Merge pull request #402 from mischnic/table-image-fix
"Fix uiImage on mac" uiImageAppend()'s swizzling only works if the pixel stride is a multiple of four. Don't swizzle the pixel stride pixels. Also a minor documentation fix.
This commit is contained in:
commit
976279ef33
|
@ -34,7 +34,7 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in
|
|||
{
|
||||
NSBitmapImageRep *repCalibrated, *repsRGB;
|
||||
uint8_t *swizzled, *bp, *sp;
|
||||
int n;
|
||||
int x, y;
|
||||
unsigned char *pix[1];
|
||||
|
||||
// OS X demands that R and B are in the opposite order from what we expect
|
||||
|
@ -43,13 +43,17 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in
|
|||
swizzled = (uint8_t *) uiprivAlloc((byteStride * pixelHeight) * sizeof (uint8_t), "uint8_t[]");
|
||||
bp = (uint8_t *) pixels;
|
||||
sp = swizzled;
|
||||
for (n = 0; n < byteStride * pixelHeight; n += 4) {
|
||||
sp[0] = bp[2];
|
||||
sp[1] = bp[1];
|
||||
sp[2] = bp[0];
|
||||
sp[3] = bp[3];
|
||||
sp += 4;
|
||||
bp += 4;
|
||||
for (y = 0; y < pixelHeight; y++){
|
||||
for (x = 0; x < pixelWidth; x++) {
|
||||
sp[0] = bp[2];
|
||||
sp[1] = bp[1];
|
||||
sp[2] = bp[0];
|
||||
sp[3] = bp[3];
|
||||
sp += 4;
|
||||
bp += 4;
|
||||
}
|
||||
// jump over unused bytes at end of line
|
||||
bp += byteStride - pixelWidth * 4;
|
||||
}
|
||||
|
||||
pix[0] = (unsigned char *) swizzled;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
// desktop systems at the time of writing (mid-2018)
|
||||
//
|
||||
// uiImage is very simple: it only supports non-premultiplied 32-bit
|
||||
// ARGB images, and libui does not provide any image file loading
|
||||
// RGBA images, and libui does not provide any image file loading
|
||||
// or image format conversion utilities on top of that.
|
||||
typedef struct uiImage uiImage;
|
||||
|
||||
|
@ -36,8 +36,8 @@ _UI_EXTERN void uiFreeImage(uiImage *i);
|
|||
|
||||
// uiImageAppend adds a representation to the uiImage.
|
||||
// pixels should point to a byte array of non-premultiplied pixels
|
||||
// stored in [R G B A] order (so ((uint8_t *) pixels)[0] is the A of the
|
||||
// first pixel and [3] is the B of the first pixel). pixelWidth and
|
||||
// stored in [R G B A] order (so ((uint8_t *) pixels)[0] is the R of the
|
||||
// first pixel and [3] is the A of the first pixel). pixelWidth and
|
||||
// pixelHeight is the size *in pixels* of the image, and pixelStride is
|
||||
// the number *of bytes* per row of the pixels array. Therefore,
|
||||
// pixels itself must be at least byteStride * pixelHeight bytes long.
|
||||
|
|
Loading…
Reference in New Issue