Browse Source

ADDED: `GenImageText()`

Probably useless but interesting for education. It generated a grayscale image directly from text data.
pull/2760/head
Ray 2 years ago
parent
commit
e61639f6fc
2 changed files with 20 additions and 0 deletions
  1. +1
    -0
      src/raylib.h
  2. +19
    -0
      src/rtextures.c

+ 1
- 0
src/raylib.h View File

@ -1244,6 +1244,7 @@ RLAPI Image GenImageChecked(int width, int height, int checksX, int checksY, Col
RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise RLAPI Image GenImageWhiteNoise(int width, int height, float factor); // Generate image: white noise
RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise RLAPI Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float scale); // Generate image: perlin noise
RLAPI Image GenImageCellular(int width, int height, int tileSize); // Generate image: cellular algorithm, bigger tileSize means bigger cells RLAPI Image GenImageCellular(int width, int height, int tileSize); // Generate image: cellular algorithm, bigger tileSize means bigger cells
RLAPI Image GenImageText(int width, int height, const char *text); // Generate image: grayscale image from text data
// Image manipulation functions // Image manipulation functions
RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)

+ 19
- 0
src/rtextures.c View File

@ -893,6 +893,25 @@ Image GenImageCellular(int width, int height, int tileSize)
return image; return image;
} }
// Generate image: grayscale image from text data
Image GenImageText(int width, int height, const char *text)
{
Image image = { 0 };
int textLength = TextLength(text);
int imageViewSize = width*height;
image.width = width;
image.height = height;
image.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE;
image.data = RL_CALLOC(imageViewSize, 1);
image.mipmaps = 1;
memcpy(image.data, text, (textLength > imageViewSize)? imageViewSize : textLength);
return image;
}
#endif // SUPPORT_IMAGE_GENERATION #endif // SUPPORT_IMAGE_GENERATION
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------

Loading…
Cancel
Save