21 #include "../SDL_internal.h" 40 #define SAVE_32BIT_BMP 47 #define BI_BITFIELDS 3 55 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 56 int alphaChannelOffset = 0;
58 int alphaChannelOffset = 3;
72 alpha = ((
Uint8*)surface->
pixels) + alphaChannelOffset;
155 }
else if (biSize >= 40) {
216 if (biSize > headerSize) {
222 biHeight = -biHeight;
234 switch (biBitCount) {
237 ExpandBMP = biBitCount;
245 SDL_SetError(
"%d-bpp BMP images are not supported", biBitCount);
254 switch (biCompression) {
260 switch (biBitCount) {
268 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 304 if (surface ==
NULL) {
310 palette = (surface->
format)->palette;
313 if (biClrUsed == 0) {
314 biClrUsed = 1 << biBitCount;
315 }
else if (biClrUsed > (1 << biBitCount)) {
316 SDL_SetError(
"BMP file has an invalid number of colors");
320 if ((
int) biClrUsed > palette->
ncolors) {
322 int ncolors = biClrUsed;
326 sizeof(*palette->
colors));
334 }
else if ((
int) biClrUsed < palette->ncolors) {
338 for (i = 0; i < (int) biClrUsed; ++
i) {
345 for (i = 0; i < (int) biClrUsed; ++
i) {
370 bmpPitch = (biWidth + 7) >> 3;
371 pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
374 bmpPitch = (biWidth + 1) >> 1;
375 pad = (((bmpPitch) % 4) ? (4 - ((bmpPitch) % 4)) : 0);
378 pad = ((surface->
pitch % 4) ? (4 - (surface->
pitch % 4)) : 0);
384 bits = end - surface->
pitch;
386 while (bits >= top && bits < end) {
391 int shift = (8 - ExpandBMP);
392 for (i = 0; i < surface->
w; ++
i) {
393 if (i % (8 / ExpandBMP) == 0) {
400 bits[
i] = (pixel >> shift);
401 if (bits[i] >= biClrUsed) {
402 SDL_SetError(
"A BMP image contains a pixel with a color out of the palette");
417 if (biBitCount == 8 && palette && biClrUsed < (1 << biBitCount)) {
418 for (i = 0; i < surface->
w; ++
i) {
419 if (bits[i] >= biClrUsed) {
420 SDL_SetError(
"A BMP image contains a pixel with a color out of the palette");
426 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 429 switch (biBitCount) {
433 for (i = 0; i < surface->
w; i++)
440 for (i = 0; i < surface->
w; i++)
451 for (i = 0; i < pad; ++
i) {
456 bits += surface->
pitch;
458 bits -= surface->
pitch;
472 if (freesrc && src) {
487 char magic[2] = {
'B',
'M' };
510 #ifdef SAVE_32BIT_BMP 585 biWidth = surface->
w;
586 biHeight = surface->
h;
590 biSizeImage = surface->
h * surface->
pitch;
620 for (i = 0; i < ncolors; ++
i) {
640 pad = ((bw % 4) ? (4 - (bw % 4)) : 0);
642 bits -= surface->
pitch;
648 const Uint8 padbyte = 0;
649 for (i = 0; i < pad; ++
i) {
667 if (surface != saveme) {
672 if (freedst && dst) {
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
#define SDL_UnlockSurface
GLdouble GLdouble GLdouble r
#define SDL_COPY_COLORKEY
uint32_t Uint32
An unsigned 32-bit integer type.
#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
static void CorrectAlphaChannel(SDL_Surface *surface)
GLdouble GLdouble GLdouble GLdouble top
GLfloat GLfloat GLfloat alpha
#define SDL_RWseek(ctx, offset, whence)
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
uint8_t Uint8
An unsigned 8-bit integer type.
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