From cadf185cee754f2841431acb6b15f93459a1fa93 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 28 Jun 2024 08:12:46 +1000 Subject: [PATCH] Broken 16 bits per pixel bitmaps --- src/Bitmap.c | 12 ++++---- src/Bitmap.h | 68 ++++++++++++++++++++++++++++++----------- src/Drawer2D.c | 2 +- src/Drawer2D.h | 2 +- src/Graphics_D3D11.c | 2 +- src/Graphics_D3D9.c | 2 +- src/Graphics_SoftGPU.c | 2 +- src/Window_3DS.c | 2 +- src/Window_Android.c | 2 +- src/Window_Dreamcast.c | 2 +- src/Window_GCWii.c | 2 +- src/Window_MacClassic.c | 2 +- src/Window_N64.c | 2 +- src/Window_NDS.c | 2 +- src/Window_PS1.c | 2 +- src/Window_PS2.c | 2 +- src/Window_PSP.c | 2 +- src/Window_PSVita.c | 2 +- src/Window_Switch.c | 2 +- src/Window_Terminal.c | 2 +- src/Window_WiiU.cpp | 2 +- src/Window_X11.c | 4 +-- src/Window_Xbox.c | 2 +- src/Window_Xbox360.c | 2 +- src/Window_cocoa.m | 2 +- src/_GLShared.h | 4 +-- src/interop_ios.m | 2 +- 27 files changed, 84 insertions(+), 50 deletions(-) diff --git a/src/Bitmap.c b/src/Bitmap.c index af8c0d911..4a10f1630 100644 --- a/src/Bitmap.c +++ b/src/Bitmap.c @@ -35,12 +35,12 @@ void Bitmap_UNSAFE_CopyBlock(int srcX, int srcY, int dstX, int dstY, void Bitmap_Allocate(struct Bitmap* bmp, int width, int height) { bmp->width = width; bmp->height = height; - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "bitmap data"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "bitmap data"); } void Bitmap_TryAllocate(struct Bitmap* bmp, int width, int height) { bmp->width = width; bmp->height = height; - bmp->scan0 = (BitmapCol*)Mem_TryAlloc(width * height, 4); + bmp->scan0 = (BitmapCol*)Mem_TryAlloc(width * height, BITMAPCOLOR_SIZE); } void Bitmap_Scale(struct Bitmap* dst, struct Bitmap* src, @@ -409,9 +409,9 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) { for (i = 0; i < dataSize; i += 3) { palette[i / 3] &= BITMAPCOLOR_A_MASK; /* set RGB to 0 */ - palette[i / 3] |= buffer[i ] << BITMAPCOLOR_R_SHIFT; - palette[i / 3] |= buffer[i + 1] << BITMAPCOLOR_G_SHIFT; - palette[i / 3] |= buffer[i + 2] << BITMAPCOLOR_B_SHIFT; + palette[i / 3] |= BitmapColor_R_Bits(buffer[i ]); + palette[i / 3] |= BitmapColor_G_Bits(buffer[i + 1]); + palette[i / 3] |= BitmapColor_B_Bits(buffer[i + 2]); } } break; @@ -434,7 +434,7 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) { /* set alpha component of palette */ for (i = 0; i < dataSize; i++) { palette[i] &= BITMAPCOLOR_RGB_MASK; /* set A to 0 */ - palette[i] |= buffer[i] << BITMAPCOLOR_A_SHIFT; + palette[i] |= BitmapColor_A_Bits(buffer[i]); } } else if (colorspace == PNG_COLOR_RGB) { if (dataSize != 6) return PNG_ERR_TRANS_COUNT; diff --git a/src/Bitmap.h b/src/Bitmap.h index c8688cc09..1a236bff9 100644 --- a/src/Bitmap.h +++ b/src/Bitmap.h @@ -6,8 +6,15 @@ */ struct Stream; -/* Represents a packed 32 bit RGBA colour, suitable for native graphics API texture pixels. */ -typedef cc_uint32 BitmapCol; +/* Represents a packed RGBA colour, suitable for 3D graphics API textures and 2D window framebuffers. */ +#ifndef BITMAP_16BPP + typedef cc_uint32 BitmapCol; + #define BITMAPCOLOR_SIZE 4 +#else + typedef cc_uint16 BitmapCol; + #define BITMAPCOLOR_SIZE 2 +#endif + #if defined CC_BUILD_WEB || defined CC_BUILD_ANDROID || defined CC_BUILD_PSP || defined CC_BUILD_PSVITA || defined CC_BUILD_PS2 #define BITMAPCOLOR_R_SHIFT 0 #define BITMAPCOLOR_G_SHIFT 8 @@ -18,6 +25,11 @@ typedef cc_uint32 BitmapCol; #define BITMAPCOLOR_G_SHIFT 16 #define BITMAPCOLOR_B_SHIFT 8 #define BITMAPCOLOR_A_SHIFT 0 +#elif defined BITMAP_16BPP + #define BITMAPCOLOR_B_SHIFT 0 + #define BITMAPCOLOR_G_SHIFT 5 + #define BITMAPCOLOR_R_SHIFT 10 + #define BITMAPCOLOR_A_SHIFT 15 #else #define BITMAPCOLOR_B_SHIFT 0 #define BITMAPCOLOR_G_SHIFT 8 @@ -25,21 +37,43 @@ typedef cc_uint32 BitmapCol; #define BITMAPCOLOR_A_SHIFT 24 #endif -#define BITMAPCOLOR_R_MASK (0xFFU << BITMAPCOLOR_R_SHIFT) -#define BITMAPCOLOR_G_MASK (0xFFU << BITMAPCOLOR_G_SHIFT) -#define BITMAPCOLOR_B_MASK (0xFFU << BITMAPCOLOR_B_SHIFT) -#define BITMAPCOLOR_A_MASK (0xFFU << BITMAPCOLOR_A_SHIFT) - -/* Extracts just the R/G/B/A component from a bitmap color */ -#define BitmapCol_R(color) ((cc_uint8)(color >> BITMAPCOLOR_R_SHIFT)) -#define BitmapCol_G(color) ((cc_uint8)(color >> BITMAPCOLOR_G_SHIFT)) -#define BitmapCol_B(color) ((cc_uint8)(color >> BITMAPCOLOR_B_SHIFT)) -#define BitmapCol_A(color) ((cc_uint8)(color >> BITMAPCOLOR_A_SHIFT)) - -#define BitmapColor_R_Bits(color) ((cc_uint8)(color) << BITMAPCOLOR_R_SHIFT) -#define BitmapColor_G_Bits(color) ((cc_uint8)(color) << BITMAPCOLOR_G_SHIFT) -#define BitmapColor_B_Bits(color) ((cc_uint8)(color) << BITMAPCOLOR_B_SHIFT) -#define BitmapColor_A_Bits(color) ((cc_uint8)(color) << BITMAPCOLOR_A_SHIFT) +#ifndef BITMAP_16BPP + /* Masks a packed color to the selected component */ + #define BITMAPCOLOR_R_MASK (0xFFU << BITMAPCOLOR_R_SHIFT) + #define BITMAPCOLOR_G_MASK (0xFFU << BITMAPCOLOR_G_SHIFT) + #define BITMAPCOLOR_B_MASK (0xFFU << BITMAPCOLOR_B_SHIFT) + #define BITMAPCOLOR_A_MASK (0xFFU << BITMAPCOLOR_A_SHIFT) + + /* Extracts just the R/G/B/A component from a bitmap color */ + #define BitmapCol_R(color) ((cc_uint8)(color >> BITMAPCOLOR_R_SHIFT)) + #define BitmapCol_G(color) ((cc_uint8)(color >> BITMAPCOLOR_G_SHIFT)) + #define BitmapCol_B(color) ((cc_uint8)(color >> BITMAPCOLOR_B_SHIFT)) + #define BitmapCol_A(color) ((cc_uint8)(color >> BITMAPCOLOR_A_SHIFT)) + + /* Converts input value into a packed color component */ + #define BitmapColor_R_Bits(value) ((cc_uint8)(value) << BITMAPCOLOR_R_SHIFT) + #define BitmapColor_G_Bits(value) ((cc_uint8)(value) << BITMAPCOLOR_G_SHIFT) + #define BitmapColor_B_Bits(value) ((cc_uint8)(value) << BITMAPCOLOR_B_SHIFT) + #define BitmapColor_A_Bits(value) ((cc_uint8)(value) << BITMAPCOLOR_A_SHIFT) +#else + /* Masks a packed color to the selected component */ + #define BITMAPCOLOR_R_MASK (0x3FU << BITMAPCOLOR_R_SHIFT) + #define BITMAPCOLOR_G_MASK (0x3FU << BITMAPCOLOR_G_SHIFT) + #define BITMAPCOLOR_B_MASK (0x3FU << BITMAPCOLOR_B_SHIFT) + #define BITMAPCOLOR_A_MASK (0x01U << BITMAPCOLOR_A_SHIFT) + + /* Extracts just the R/G/B/A component from a bitmap color */ + #define BitmapCol_R(color) (((cc_uint8)(color >> BITMAPCOLOR_R_SHIFT) & 0x3F) << 3) + #define BitmapCol_G(color) (((cc_uint8)(color >> BITMAPCOLOR_G_SHIFT) & 0x3F) << 3) + #define BitmapCol_B(color) (((cc_uint8)(color >> BITMAPCOLOR_B_SHIFT) & 0x3F) << 3) + #define BitmapCol_A(color) (((cc_uint8)(color >> BITMAPCOLOR_A_SHIFT) & 0x01) << 7) + + /* Converts input value into a packed color component */ + #define BitmapColor_R_Bits(value) (((cc_uint8)(value) >> 3) << BITMAPCOLOR_R_SHIFT) + #define BitmapColor_G_Bits(value) (((cc_uint8)(value) >> 3) << BITMAPCOLOR_G_SHIFT) + #define BitmapColor_B_Bits(value) (((cc_uint8)(value) >> 3) << BITMAPCOLOR_B_SHIFT) + #define BitmapColor_A_Bits(value) (((cc_uint8)(value) >> 7) << BITMAPCOLOR_A_SHIFT) +#endif #define BitmapCol_Make(r, g, b, a) (BitmapColor_R_Bits(r) | BitmapColor_G_Bits(g) | BitmapColor_B_Bits(b) | BitmapColor_A_Bits(a)) #define BitmapColor_RGB(r, g, b) (BitmapColor_R_Bits(r) | BitmapColor_G_Bits(g) | BitmapColor_B_Bits(b) | BITMAPCOLOR_A_MASK) diff --git a/src/Drawer2D.c b/src/Drawer2D.c index 589ca0b24..ee809ec4e 100644 --- a/src/Drawer2D.c +++ b/src/Drawer2D.c @@ -163,7 +163,7 @@ void Context2D_Alloc(struct Context2D* ctx, int width, int height) { ctx->bmp.width = width; ctx->bmp.height = height; - ctx->bmp.scan0 = (BitmapCol*)Mem_AllocCleared(width * height, 4, "bitmap data"); + ctx->bmp.scan0 = (BitmapCol*)Mem_AllocCleared(width * height, BITMAPCOLOR_SIZE, "bitmap data"); } void Context2D_Wrap(struct Context2D* ctx, struct Bitmap* bmp) { diff --git a/src/Drawer2D.h b/src/Drawer2D.h index 3e4b8b8c0..792902141 100644 --- a/src/Drawer2D.h +++ b/src/Drawer2D.h @@ -93,7 +93,7 @@ cc_bool Drawer2D_IsWhiteColor(char c); cc_bool Drawer2D_UNSAFE_NextPart(cc_string* left, cc_string* part, char* colorCode); /* Divides R/G/B by 4 */ -#define SHADOW_MASK ((0x3F << BITMAPCOLOR_R_SHIFT) | (0x3F << BITMAPCOLOR_G_SHIFT) | (0x3F << BITMAPCOLOR_B_SHIFT)) +#define SHADOW_MASK (BitmapColor_R_Bits(0x3F) | BitmapColor_G_Bits(0x3F) | BitmapColor_B_Bits(0x3F)) static CC_INLINE BitmapCol GetShadowColor(BitmapCol c) { if (Drawer2D.BlackTextShadows) return BITMAPCOLOR_BLACK; diff --git a/src/Graphics_D3D11.c b/src/Graphics_D3D11.c index bcef6b119..8eccfa6cf 100644 --- a/src/Graphics_D3D11.c +++ b/src/Graphics_D3D11.c @@ -178,7 +178,7 @@ static void D3D11_DoMipmaps(ID3D11Resource* texture, int x, int y, struct Bitmap if (width > 1) width /= 2; if (height > 1) height /= 2; - cur = (BitmapCol*)Mem_Alloc(width * height, 4, "mipmaps"); + cur = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "mipmaps"); GenMipmaps(width, height, cur, prev, rowWidth); D3D11_BOX box; diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index aad3801ac..ce2d8ed05 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -287,7 +287,7 @@ static void D3D9_DoMipmaps(IDirect3DTexture9* texture, int x, int y, struct Bitm if (width > 1) width /= 2; if (height > 1) height /= 2; - cur = (BitmapCol*)Mem_Alloc(width * height, 4, "mipmaps"); + cur = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "mipmaps"); GenMipmaps(width, height, cur, prev, rowWidth); Bitmap_Init(mipmap, width, height, cur); diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index d65ef459c..9da6d28f5 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -98,7 +98,7 @@ static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) { CCTexture* tex = (CCTexture*)texId; - cc_uint32* dst = (tex->pixels + x) + y * tex->width; + BitmapCol* dst = (tex->pixels + x) + y * tex->width; CopyTextureData(dst, tex->width * 4, part, rowWidth << 2); } diff --git a/src/Window_3DS.c b/src/Window_3DS.c index 5f45a2045..6bf4988d4 100644 --- a/src/Window_3DS.c +++ b/src/Window_3DS.c @@ -189,7 +189,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_Android.c b/src/Window_Android.c index 8f9a2d1b5..ef94b173d 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -481,7 +481,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* save_args) { } void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_Dreamcast.c b/src/Window_Dreamcast.c index 9bc927184..3d9651f37 100644 --- a/src/Window_Dreamcast.c +++ b/src/Window_Dreamcast.c @@ -287,7 +287,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_GCWii.c b/src/Window_GCWii.c index 542c7d4b0..7a1b7017a 100644 --- a/src/Window_GCWii.c +++ b/src/Window_GCWii.c @@ -452,7 +452,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_MacClassic.c b/src/Window_MacClassic.c index 8fdea6020..d3c237120 100644 --- a/src/Window_MacClassic.c +++ b/src/Window_MacClassic.c @@ -439,7 +439,7 @@ static PixMapHandle fb_pixmap; void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { if (!useGWorld) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; return; diff --git a/src/Window_N64.c b/src/Window_N64.c index 91cefef26..b2778dd08 100644 --- a/src/Window_N64.c +++ b/src/Window_N64.c @@ -152,7 +152,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_NDS.c b/src/Window_NDS.c index d08a2140e..cf1566785 100644 --- a/src/Window_NDS.c +++ b/src/Window_NDS.c @@ -257,7 +257,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_PS1.c b/src/Window_PS1.c index ada8731fa..4fd796ff4 100644 --- a/src/Window_PS1.c +++ b/src/Window_PS1.c @@ -163,7 +163,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { PutDispEnv(&disp); SetDispMask(1); - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; diff --git a/src/Window_PS2.c b/src/Window_PS2.c index 6f24f1934..5cf667ccc 100644 --- a/src/Window_PS2.c +++ b/src/Window_PS2.c @@ -260,7 +260,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; diff --git a/src/Window_PSP.c b/src/Window_PSP.c index e49b47738..f0dc9c244 100644 --- a/src/Window_PSP.c +++ b/src/Window_PSP.c @@ -136,7 +136,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_PSVita.c b/src/Window_PSVita.c index 15a2e0161..55514df9a 100644 --- a/src/Window_PSVita.c +++ b/src/Window_PSVita.c @@ -194,7 +194,7 @@ void Gamepads_Process(float delta) { *#########################################################################################################################*/ static struct Bitmap fb_bmp; void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; fb_bmp = *bmp; diff --git a/src/Window_Switch.c b/src/Window_Switch.c index c4a6112ad..3d2db02ca 100644 --- a/src/Window_Switch.c +++ b/src/Window_Switch.c @@ -198,7 +198,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { framebufferCreate(&fb, nwindowGetDefault(), DisplayInfo.Width, DisplayInfo.Height, PIXEL_FORMAT_BGRA_8888, 2); framebufferMakeLinear(&fb); - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_Terminal.c b/src/Window_Terminal.c index 423d95066..32c06ebd2 100644 --- a/src/Window_Terminal.c +++ b/src/Window_Terminal.c @@ -529,7 +529,7 @@ cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_WiiU.cpp b/src/Window_WiiU.cpp index f81009d08..1285570b1 100644 --- a/src/Window_WiiU.cpp +++ b/src/Window_WiiU.cpp @@ -374,7 +374,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { GX2InitTextureRegs(&fb); fb.surface.image = MEMAllocFromDefaultHeapEx(fb.surface.imageSize, fb.surface.alignment); - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_X11.c b/src/Window_X11.c index 1b88fa83f..e003d4d40 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -1133,7 +1133,7 @@ static int fb_fast; void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { if (!fb_gc) fb_gc = XCreateGC(win_display, win_handle, 0, NULL); - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; @@ -1141,7 +1141,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { /* Easy for 24/32 bit case, but much trickier with other depths */ /* (have to do a manual and slow second blit for other depths) */ fb_fast = win_visual.depth == 24 || win_visual.depth == 32; - fb_data = fb_fast ? bmp->scan0 : Mem_Alloc(width * height, 4, "window blit"); + fb_data = fb_fast ? bmp->scan0 : Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window blit"); fb_image = XCreateImage(win_display, win_visual.visual, win_visual.depth, ZPixmap, 0, fb_data, diff --git a/src/Window_Xbox.c b/src/Window_Xbox.c index 4d0041dcf..625e26b03 100644 --- a/src/Window_Xbox.c +++ b/src/Window_Xbox.c @@ -193,7 +193,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_Xbox360.c b/src/Window_Xbox360.c index 64f946a41..97fd79d3b 100644 --- a/src/Window_Xbox360.c +++ b/src/Window_Xbox360.c @@ -147,7 +147,7 @@ void Gamepads_Process(float delta) { *------------------------------------------------------Framebuffer--------------------------------------------------------* *#########################################################################################################################*/ void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; } diff --git a/src/Window_cocoa.m b/src/Window_cocoa.m index bee984003..c6bbff711 100644 --- a/src/Window_cocoa.m +++ b/src/Window_cocoa.m @@ -702,7 +702,7 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { *#########################################################################################################################*/ static struct Bitmap fb_bmp; void Window_AllocFramebuffer(struct Bitmap* bmp, int width, int height) { - bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, 4, "window pixels"); + bmp->scan0 = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "window pixels"); bmp->width = width; bmp->height = height; fb_bmp = *bmp; diff --git a/src/_GLShared.h b/src/_GLShared.h index 5921e5d70..b568289a5 100644 --- a/src/_GLShared.h +++ b/src/_GLShared.h @@ -79,7 +79,7 @@ static void Gfx_DoMipmaps(int x, int y, struct Bitmap* bmp, int rowWidth, cc_boo if (width > 1) width /= 2; if (height > 1) height /= 2; - cur = (BitmapCol*)Mem_Alloc(width * height, 4, "mipmaps"); + cur = (BitmapCol*)Mem_Alloc(width * height, BITMAPCOLOR_SIZE, "mipmaps"); GenMipmaps(width, height, cur, prev, rowWidth); if (partial) { @@ -244,7 +244,7 @@ cc_result Gfx_TakeScreenshot(struct Stream* output) { bmp.width = vp[2]; bmp.height = vp[3]; - bmp.scan0 = (BitmapCol*)Mem_TryAlloc(bmp.width * bmp.height, 4); + bmp.scan0 = (BitmapCol*)Mem_TryAlloc(bmp.width * bmp.height, BITMAPCOLOR_SIZE); if (!bmp.scan0) return ERR_OUT_OF_MEMORY; glReadPixels(0, 0, bmp.width, bmp.height, PIXEL_FORMAT, TRANSFER_FORMAT, bmp.scan0); diff --git a/src/interop_ios.m b/src/interop_ios.m index 5b2f12d58..da777fa94 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -1401,7 +1401,7 @@ void LBackend_Redraw(void) { struct Bitmap bmp; bmp.width = max(Window_Main.Width, 1); bmp.height = max(Window_Main.Height, 1); - bmp.scan0 = (BitmapCol*)Mem_Alloc(bmp.width * bmp.height, 4, "window pixels"); + bmp.scan0 = (BitmapCol*)Mem_Alloc(bmp.width * bmp.height, BITMAPCOLOR_SIZE, "window pixels"); Context2D_Wrap(&ctx, &bmp); win_ctx = CGBitmapContextCreate(bmp.scan0, bmp.width, bmp.height, 8, bmp.width * 4,