cute_aseprite.h: Added support for indexed and grayscale pixels#423
cute_aseprite.h: Added support for indexed and grayscale pixels#423mathewmariani wants to merge 1 commit intoRandyGaul:masterfrom
Conversation
|
Finding this? After fixing that, I'm still getting no rendered image. |
| ase_color_t result = s_blend(src_color, dst_color, opacity); | ||
| dst[dst_index] = result; | ||
| if (ase->mode == ASE_MODE_RGBA) { | ||
| ase_color_t *d = (ase_color_t *) dst; |
There was a problem hiding this comment.
Need to match formatting style for the rest of the file -- (ase_color_t*) not ase_color_t *
| d[dst_index] = result; | ||
| } else if (ase->mode == ASE_MODE_GRAYSCALE) { | ||
| ase_grayscale_t *d = (ase_grayscale_t *) dst; | ||
| d[dst_index] = ((ase_grayscale_t *) src)[cw * sy + sx]; |
There was a problem hiding this comment.
Formatting: ((ase_grayscale_t *) src) -> ((ase_grayscale_t*)src)
| return a < b ? b : a; | ||
| } | ||
|
|
||
| static ase_color_t s_color(ase_t* ase, void* src, int index) |
There was a problem hiding this comment.
We need to leave a helper function so people can add in their own new blending support. The blending loops below are optional and only added in for convenience. There are many ways to blend aseprite layers together, I just picked the most "typical" to support for now.
| int aw = ase->w; | ||
| for (int dx = dl, sx = cl; dx < dr; dx++, sx++) { | ||
| for (int dy = dt, sy = ct; dy < db; dy++, sy++) { | ||
| int dst_index = aw * dy + dx; |
There was a problem hiding this comment.
Did you accidentally delete this?
RandyGaul
left a comment
There was a problem hiding this comment.
I'd make a little more of a fleshed out abstraction for rendering different kinds of images. Kind of like how I had a helper function to fetch pixels of different types, you should probably invest some time to write something to help you write pixels of different types for different image output formats. This will make the code much more reusable for implementing different kinds of layer blending.
This pull requests adds support for color modes grayscale and indexed color modes.
struct ase_frame_tnow has a fieldvoid* pixels;instead of aase_color_t* pixelsto reflect how the specs defined a pixel. We can cast to our desired color types (struct ase_color_t,struct ase_grayscale_t, andstruct ase_index) as needed.A pixel as described in the specs:
Blending is not supported for
ASE_MODE_GRAYSCALEandASE_MODE_INDEXEDands_blendwill only be called when the color mode isASE_MODE_RGBA.