21 #include "../SDL_internal.h" 41 #define SAVE_32BIT_BMP 48 #define BI_BITFIELDS 3 52 #ifndef LCS_WINDOWS_COLOR_SPACE 54 #define LCS_WINDOWS_COLOR_SPACE 0x57696E20 61 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 62 int alphaChannelOffset = 0;
64 int alphaChannelOffset = 3;
78 alpha = ((
Uint8*)surface->
pixels) + alphaChannelOffset;
161 }
else if (biSize >= 40) {
222 if (biSize > headerSize) {
226 if (biWidth <= 0 || biHeight == 0) {
227 SDL_SetError(
"BMP file with bad dimensions (%dx%d)", biWidth, biHeight);
233 biHeight = -biHeight;
245 switch (biBitCount) {
248 ExpandBMP = biBitCount;
256 SDL_SetError(
"%d-bpp BMP images are not supported", biBitCount);
265 switch (biCompression) {
271 switch (biBitCount) {
279 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 315 if (surface ==
NULL) {
321 palette = (surface->
format)->palette;
324 if (biClrUsed == 0) {
325 biClrUsed = 1 << biBitCount;
326 }
else if (biClrUsed > (1 << biBitCount)) {
327 SDL_SetError(
"BMP file has an invalid number of colors");
331 if ((
int) biClrUsed > palette->
ncolors) {
333 int ncolors = biClrUsed;
337 sizeof(*palette->
colors));
345 }
else if ((
int) biClrUsed < palette->ncolors) {
349 for (i = 0; i < (int) biClrUsed; ++
i) {
356 for (i = 0; i < (int) biClrUsed; ++
i) {
381 bmpPitch = (biWidth + 7) >> 3;
382 pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
385 bmpPitch = (biWidth + 1) >> 1;
386 pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
389 pad = ((surface->
pitch % 4) ? (4 - (surface->
pitch % 4)) : 0);
395 bits = end - surface->
pitch;
397 while (bits >= top && bits < end) {
402 int shift = (8 - ExpandBMP);
403 for (i = 0; i < surface->
w; ++
i) {
404 if (i % (8 / ExpandBMP) == 0) {
411 bits[
i] = (pixel >> shift);
412 if (bits[i] >= biClrUsed) {
413 SDL_SetError(
"A BMP image contains a pixel with a color out of the palette");
428 if (biBitCount == 8 && palette && biClrUsed < (1 << biBitCount)) {
429 for (i = 0; i < surface->
w; ++
i) {
430 if (bits[i] >= biClrUsed) {
431 SDL_SetError(
"A BMP image contains a pixel with a color out of the palette");
437 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 440 switch (biBitCount) {
444 for (i = 0; i < surface->
w; i++)
451 for (i = 0; i < surface->
w; i++)
462 for (i = 0; i < pad; ++
i) {
467 bits += surface->
pitch;
469 bits -= surface->
pitch;
483 if (freesrc && src) {
500 char magic[2] = {
'B',
'M' };
525 Sint32 bV4Endpoints[3 * 3] = {0};
533 #ifdef SAVE_32BIT_BMP 606 biWidth = surface->
w;
607 biHeight = surface->
h;
611 biSizeImage = surface->
h * surface->
pitch;
622 if (save32bit && !saveLegacyBMP) {
626 bV4RedMask = 0x00ff0000;
627 bV4GreenMask = 0x0000ff00;
628 bV4BlueMask = 0x000000ff;
629 bV4AlphaMask = 0xff000000;
650 if (save32bit && !saveLegacyBMP) {
656 for (i = 0; i < 3 * 3; i++) {
671 for (i = 0; i < ncolors; ++
i) {
691 pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
693 bits -= surface->
pitch;
699 const Uint8 padbyte = 0;
700 for (i = 0; i < pad; ++
i) {
718 if (surface != saveme) {
723 if (freedst && dst) {
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
#define SDL_UnlockSurface
GLdouble GLdouble GLdouble r
#define SDL_COPY_COLORKEY
#define LCS_WINDOWS_COLOR_SPACE
#define SDL_RWwrite(ctx, ptr, size, n)
#define SDL_ConvertSurface
A collection of pixels used in software blitting.
#define SDL_RWread(ctx, ptr, size, n)
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const void * bits
uint32_t Uint32
An unsigned 32-bit integer type.
static void CorrectAlphaChannel(SDL_Surface *surface)
GLdouble GLdouble GLdouble GLdouble top
GLfloat GLfloat GLfloat alpha
#define SDL_GetHintBoolean
#define SDL_RWseek(ctx, offset, whence)
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
uint8_t Uint8
An unsigned 8-bit integer type.
#define SDL_HINT_BMP_SAVE_LEGACY_FORMAT
Prevent SDL from using version 4 of the bitmap header when saving BMPs.
SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x)
int SDL_InitFormat(SDL_PixelFormat *format, Uint32 pixel_format)
int SDL_SaveBMP_RW(SDL_Surface *saveme, SDL_RWops *dst, int freedst)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
#define SDL_OutOfMemory()
SDL_Surface * SDL_LoadBMP_RW(SDL_RWops *src, int freesrc)
#define SDL_CreateRGBSurface
uint16_t Uint16
An unsigned 16-bit integer type.
int64_t Sint64
A signed 64-bit integer type.
GLboolean GLboolean GLboolean GLboolean a
GLboolean GLboolean GLboolean b