Skip to content

Commit

Permalink
Try fix bigendian
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Sep 16, 2024
1 parent 1d5b330 commit a988750
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/_webp.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,14 @@ HandleMuxError(WebPMuxError err, char *chunk) {

static int
import_frame_libwebp(WebPPicture *frame, Imaging im) {
UINT32 mask = 0;
int drop_alpha = strcmp(im->mode, "RGBA");

if (strcmp(im->mode, "RGBA") && strcmp(im->mode, "RGB") &&
strcmp(im->mode, "RGBX")) {
PyErr_SetString(PyExc_ValueError, "unsupported image mode");
return -1;

Check warning on line 97 in src/_webp.c

View check run for this annotation

Codecov / codecov/patch

src/_webp.c#L95-L97

Added lines #L95 - L97 were not covered by tests
}

if (strcmp(im->mode, "RGBA")) {
mask = MASK_UINT32_CHANNEL_3;
}

frame->width = im->xsize;
frame->height = im->ysize;
frame->use_argb = 1; // Don't convert RGB pixels to YUV
Expand All @@ -113,10 +109,18 @@ import_frame_libwebp(WebPPicture *frame, Imaging im) {
for (int y = 0; y < im->ysize; ++y) {
UINT8 *src = (UINT8 *)im->image32[y];
UINT32 *dst = frame->argb + frame->argb_stride * y;
for (int x = 0; x < im->xsize; ++x) {
UINT32 pix =
MAKE_UINT32(src[x * 4 + 2], src[x * 4 + 1], src[x * 4], src[x * 4 + 3]);
dst[x] = pix | mask;
if (drop_alpha) {
for (int x = 0; x < im->xsize; ++x) {
dst[x] =
((UINT32)(src[x * 4 + 2]) | ((UINT32)(src[x * 4 + 1]) << 8) |
((UINT32)(src[x * 4]) << 16) | (0xff << 24));
}
} else {
for (int x = 0; x < im->xsize; ++x) {
dst[x] =
((UINT32)(src[x * 4 + 2]) | ((UINT32)(src[x * 4 + 1]) << 8) |
((UINT32)(src[x * 4]) << 16) | ((UINT32)(src[x * 4 + 3]) << 24));
}
}
}

Expand Down

0 comments on commit a988750

Please sign in to comment.