42 typedef struct BMPHEADER {
51 #define BMP_FILEHEADER_SIZE 14
53 #define CHECK_HEADER_FIELD(_mem, _field) ((_mem[0] == _field[0]) && (_mem[1] == _field[1]))
54 #define CHECK_HEADER_FIELD_BMP(_mem) \
55 (CHECK_HEADER_FIELD(_mem, "BM") || CHECK_HEADER_FIELD(_mem, "BA") || \
56 CHECK_HEADER_FIELD(_mem, "CI") || CHECK_HEADER_FIELD(_mem, "CP") || \
57 CHECK_HEADER_FIELD(_mem, "IC") || CHECK_HEADER_FIELD(_mem, "PT"))
77 memcpy(&bmi, mem,
sizeof(bmi));
84 if (u > 0 && u <= 32) {
102 return (((
x * depth) + 31) & ~31) >> 3;
113 bool top_to_bottom =
false;
134 top_to_bottom =
true;
138 if (
x < 1 || !(
ELEM(depth, 1, 4, 8, 16, 24, 32))) {
142 const size_t pixel_data_offset = (size_t)
LITTLE_LONG(*(
int *)(mem + 10));
144 const size_t num_actual_data_bytes =
size - pixel_data_offset;
146 const size_t num_expected_data_bytes = row_size_in_bytes *
y;
147 if (num_actual_data_bytes < num_expected_data_bytes || num_actual_data_bytes >
size ||
148 pixel_data_offset < header_bytes || pixel_data_offset > (
size - num_expected_data_bytes) ||
149 palette_offset < header_bytes || palette_offset > pixel_data_offset) {
160 bmp = mem + pixel_data_offset;
163 printf(
"palette_offset: %d, x: %d y: %d, depth: %d\n", palette_offset,
x,
y, depth);
178 const char(*palette)[4] = (
const char(*)[4])(mem + palette_offset);
179 const int startmask = ((1 << depth) - 1) << 8;
180 for (
size_t i =
y; i > 0; i--) {
183 int bitmask = startmask;
189 for (
size_t j =
x; j > 0; j--) {
192 index = (bmp[0] & bitmask) >> bitoffs;
193 pcol = palette[index];
210 bmp += (row_size_in_bytes - nbytes);
213 else if (depth == 16) {
214 for (
size_t i =
y; i > 0; i--) {
218 for (
size_t j =
x; j > 0; j--) {
219 col = bmp[0] + (bmp[1] << 8);
220 rect[0] = ((
col >> 10) & 0x1f) << 3;
221 rect[1] = ((
col >> 5) & 0x1f) << 3;
222 rect[2] = ((
col >> 0) & 0x1f) << 3;
230 else if (depth == 24) {
231 const int x_pad =
x % 4;
232 for (
size_t i =
y; i > 0; i--) {
236 for (
size_t j =
x; j > 0; j--) {
249 else if (depth == 32) {
250 for (
size_t i =
y; i > 0; i--) {
254 for (
size_t j =
x; j > 0; j--) {
275 #undef CHECK_HEADER_FIELD_BMP
276 #undef CHECK_HEADER_FIELD
281 putc((ui >> 0) & 0xFF, ofile);
282 putc((ui >> 8) & 0xFF, ofile);
283 putc((ui >> 16) & 0xFF, ofile);
284 return putc((ui >> 24) & 0xFF, ofile);
289 putc((us >> 0) & 0xFF, ofile);
290 return putc((us >> 8) & 0xFF, ofile);
297 const size_t bytes_per_pixel = (ibuf->
planes + 7) >> 3;
300 const size_t pad_bytes_per_scanline = (4 - ibuf->
x * bytes_per_pixel % 4) % 4;
301 const size_t bytesize = (ibuf->
x * bytes_per_pixel + pad_bytes_per_scanline) * ibuf->
y;
309 const bool is_grayscale = bytes_per_pixel == 1;
310 const size_t palette_size = is_grayscale ? 255 * 4 : 0;
314 putIntLSB(bytesize + pixel_array_start, ofile);
333 for (
char i = 0; i < 255; i++) {
342 for (
size_t y = 0;
y < ibuf->
y;
y++) {
343 for (
size_t x = 0;
x < ibuf->
x;
x++) {
344 const size_t ptr = (
x +
y * ibuf->
x) * 4;
345 if (putc(
data[
ptr], ofile) == EOF) {
350 for (
size_t t = 0;
t < pad_bytes_per_scanline;
t++) {
351 if (putc(0, ofile) == EOF) {
359 for (
size_t y = 0;
y < ibuf->
y;
y++) {
360 for (
size_t x = 0;
x < ibuf->
x;
x++) {
361 const size_t ptr = (
x +
y * ibuf->
x) * 4;
362 if (putc(
data[
ptr + 2], ofile) == EOF) {
365 if (putc(
data[
ptr + 1], ofile) == EOF) {
368 if (putc(
data[
ptr], ofile) == EOF) {
373 for (
size_t t = 0;
t < pad_bytes_per_scanline;
t++) {
374 if (putc(0, ofile) == EOF) {
File and directory operations.
FILE * BLI_fopen(const char *filepath, const char *mode) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
@ COLOR_ROLE_DEFAULT_BYTE
struct ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
Contains defines and structs used throughout the imbuf module.
#define CHECK_HEADER_FIELD_BMP(_mem)
bool imb_savebmp(ImBuf *ibuf, const char *filepath, int UNUSED(flags))
struct BMPINFOHEADER BMPINFOHEADER
ImBuf * imb_bmp_decode(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
static bool checkbmp(const uchar *mem, const size_t size)
bool imb_is_a_bmp(const uchar *buf, size_t size)
#define BMP_FILEHEADER_SIZE
static int putIntLSB(uint ui, FILE *ofile)
static size_t imb_bmp_calc_row_size_in_bytes(size_t x, size_t depth)
static int putShortLSB(ushort us, FILE *ofile)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void colorspace_set_default_role(char *colorspace, int size, int role)