Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[textures] Implement some image manipulation functions #47

Closed
raysan5 opened this issue Sep 11, 2015 · 2 comments
Closed

[textures] Implement some image manipulation functions #47

raysan5 opened this issue Sep 11, 2015 · 2 comments
Assignees
Labels
enhancement This is an improvement of some feature
Milestone

Comments

@raysan5
Copy link
Owner

raysan5 commented Sep 11, 2015

While creating examples and demos I missed some image manipulation functions. The following proposed functions could be useful.

Desired functions [textures.c]:

void ImageCrop(Image *image, Rectangle crop);
void ImageResize(Image *image, int newWidth, int newHeight); // Use stb_image_resize.h
void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec);
void ImageDrawText(Image *dst, const char *text, Vector2 position, int size, Color color);
void ImageDrawTextEx(Image *dst, SpriteFont font, const char *text, Vector2 position, int size, Color color);

Compressed image formats won't be supported and returned image should keep the same format as original one. To simplify image operation in some cases, it could be converted to R8G8B8A8 (32bit) format to operate with it and reconverted to original format at the end.

Some notes on every function implementation:

  • ImageCrop() is quite easy, just take care of out-of-image limits.
  • ImageResize() is not that easy but 'stb_image_resize.h` can be used to simply the process, function would be just a wrapper.
  • ImageDraw() is just an image blitting process, it could use ImageResize() if destination rectangle size is different than source rectangle size.
  • ImageDrawText() is quite complex. It should use default raylib font but font image must be retrieved from SpriteFont texture id. Then, depending on every letter to draw into the resulting image, every letter source rectangle should be taken from font image and ImageDraw() could be used. Depending on desired font size, ImageResize() should also be used.
  • ImageDrawTextEx() is similar to ImageDrawText() but using a custom font.
@raysan5 raysan5 added the enhancement This is an improvement of some feature label Sep 11, 2015
@raysan5 raysan5 added this to the raylib v1.4 milestone Sep 11, 2015
@raysan5 raysan5 assigned raysan5 and unassigned raysan5 Sep 13, 2015
@raysan5
Copy link
Owner Author

raysan5 commented Sep 17, 2015

Probably those functions were not a priority but I needed them for a small project and I started implementing them. So far I got:

void ImageCrop(Image *image, Rectangle crop);
void ImageResize(Image *image, int newWidth, int newHeight); // Use stb_image_resize.h
void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec);

Functions left (and some new ones I need):

void ImageDrawText(Image *dst, const char *text, Vector2 position, int size, Color color);
void ImageDrawTextEx(Image *dst, SpriteFont font, const char *text, Vector2 position, int size, Color color);
void ImageFlipVertical(Image *image);
void ImageFlipHorizontal(Image *image);
void ImageColorInvert(Image *image);
void ImageColorGrayscale(Image *image);
void ImageColorContrast(Image *image, float contrast);
void ImageColorBrightness(Image *image, int brightness);

Maybe I should split textures module into: textures.c and image.c?

@raysan5
Copy link
Owner Author

raysan5 commented Oct 24, 2015

After some development, the following functions:

void ImageDrawText(Image *dst, const char *text, Vector2 position, int size, Color color);
void ImageDrawTextEx(Image *dst, SpriteFont font, const char *text, Vector2 position, int size, Color color);

have been replaced by simpler (and more generic) versions:

Image ImageText(const char *text, int fontSize, Color color);
Image ImageTextEx(SpriteFont font, const char *text, int fontSize, int spacing, Color tint);

All defined functions have been created and tested and also a new one:

void ImageColorTint(Image *image, Color color);

Feature completed on commit afdf357

@raysan5 raysan5 closed this as completed Oct 24, 2015
michaelfiber pushed a commit to michaelfiber/raylib that referenced this issue Sep 21, 2023
Restyle, added functionality, code rework, +1 more change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an improvement of some feature
Projects
None yet
Development

No branches or pull requests

1 participant