Skip to content

Comments

cute_aseprite.h: Added support for indexed and grayscale pixels#423

Open
mathewmariani wants to merge 1 commit intoRandyGaul:masterfrom
mathewmariani:added-support-indexed-grayscale-pixelmodes
Open

cute_aseprite.h: Added support for indexed and grayscale pixels#423
mathewmariani wants to merge 1 commit intoRandyGaul:masterfrom
mathewmariani:added-support-indexed-grayscale-pixelmodes

Conversation

@mathewmariani
Copy link
Contributor

This pull requests adds support for color modes grayscale and indexed color modes.

struct ase_frame_t now has a field void* pixels; instead of a ase_color_t* pixels to reflect how the specs defined a pixel. We can cast to our desired color types (struct ase_color_t, struct ase_grayscale_t, and struct ase_index) as needed.

A pixel as described in the specs:

* `PIXEL`: One pixel, depending on the image pixel format:
  - **RGBA**: `BYTE[4]`, each pixel have 4 bytes in this order Red, Green, Blue, Alpha.
  - **Grayscale**: `BYTE[2]`, each pixel have 2 bytes in the order Value, Alpha.
  - **Indexed**: `BYTE`, each pixel uses 1 byte (the index).

Blending is not supported for ASE_MODE_GRAYSCALE and ASE_MODE_INDEXED and s_blend will only be called when the color mode is ASE_MODE_RGBA.

@RobLoach
Copy link
Contributor

RobLoach commented Feb 4, 2026

Finding this?

cute_aseprite.h:1279:75: error: ‘dst_index’ undeclared (first use in this function); did you mean ‘tag_index’?
 1279 |                                       ase_color_t dst_color = d[dst_index];
      |                                                                 ^~~~~~~~~
      |                                                                 tag_index
cute_aseprite.h:1279:75: note: each undeclared identifier is reported only once for each function it appears in

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you accidentally delete this?

Copy link
Owner

@RandyGaul RandyGaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants