equal
deleted
inserted
replaced
3 #include "stdafx.h" |
3 #include "stdafx.h" |
4 #include "openttd.h" |
4 #include "openttd.h" |
5 #include "gfx.h" |
5 #include "gfx.h" |
6 #include "bmp.h" |
6 #include "bmp.h" |
7 #include "macros.h" |
7 #include "macros.h" |
|
8 #include "helpers.hpp" |
8 |
9 |
9 void BmpInitializeBuffer(BmpBuffer *buffer, FILE *file) { |
10 void BmpInitializeBuffer(BmpBuffer *buffer, FILE *file) { |
10 buffer->pos = -1; |
11 buffer->pos = -1; |
11 buffer->file = file; |
12 buffer->file = file; |
12 buffer->read = 0; |
13 buffer->read = 0; |
326 info->palette_size = ReadDword(buffer); // number of colors in palette |
327 info->palette_size = ReadDword(buffer); // number of colors in palette |
327 SkipBytes(buffer, header_size - 16); // skip the end of info header |
328 SkipBytes(buffer, header_size - 16); // skip the end of info header |
328 } |
329 } |
329 if (info->palette_size == 0) info->palette_size = 1 << info->bpp; |
330 if (info->palette_size == 0) info->palette_size = 1 << info->bpp; |
330 |
331 |
331 data->palette = calloc(info->palette_size, sizeof(*(data->palette))); |
332 CallocT(&data->palette, info->palette_size); |
332 if (data->palette == NULL) return false; |
333 if (data->palette == NULL) return false; |
333 |
334 |
334 for (i = 0; i < info->palette_size; i++) { |
335 for (i = 0; i < info->palette_size; i++) { |
335 data->palette[i].b = ReadByte(buffer); |
336 data->palette[i].b = ReadByte(buffer); |
336 data->palette[i].g = ReadByte(buffer); |
337 data->palette[i].g = ReadByte(buffer); |
348 */ |
349 */ |
349 bool BmpReadBitmap(BmpBuffer *buffer, BmpInfo *info, BmpData *data) |
350 bool BmpReadBitmap(BmpBuffer *buffer, BmpInfo *info, BmpData *data) |
350 { |
351 { |
351 assert(info != NULL && data != NULL); |
352 assert(info != NULL && data != NULL); |
352 |
353 |
353 data->bitmap = calloc(info->width * info->height, ((info->bpp == 24) ? 3 : 1) * sizeof(byte)); |
354 data->bitmap = (byte*)calloc(info->width * info->height, ((info->bpp == 24) ? 3 : 1) * sizeof(byte)); |
354 if (data->bitmap == NULL) return false; |
355 if (data->bitmap == NULL) return false; |
355 |
356 |
356 /* Load image */ |
357 /* Load image */ |
357 SetStreamOffset(buffer, info->offset); |
358 SetStreamOffset(buffer, info->offset); |
358 switch (info->compression) { |
359 switch (info->compression) { |