Mac uiImageAppend: handle stride correctly
This commit is contained in:
parent
e0ca00e55b
commit
c0742d3de0
|
@ -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 n, l;
|
||||
unsigned char *pix[1];
|
||||
|
||||
// OS X demands that R and B are in the opposite order from what we expect
|
||||
|
@ -43,7 +43,8 @@ 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) {
|
||||
for (l = 0; l < pixelHeight; l++){
|
||||
for (n = 0; n < pixelWidth; n++) {
|
||||
sp[0] = bp[2];
|
||||
sp[1] = bp[1];
|
||||
sp[2] = bp[0];
|
||||
|
@ -51,6 +52,9 @@ void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, in
|
|||
sp += 4;
|
||||
bp += 4;
|
||||
}
|
||||
// jump over unused bytes at end of line
|
||||
bp += byteStride - pixelWidth * 4;
|
||||
}
|
||||
|
||||
pix[0] = (unsigned char *) swizzled;
|
||||
repCalibrated = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:pix
|
||||
|
|
|
@ -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