summaryrefslogtreecommitdiff
path: root/modules/bmp/image_loader_bmp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/bmp/image_loader_bmp.cpp')
-rw-r--r--modules/bmp/image_loader_bmp.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp
index c7fdf56af4..171895ed24 100644
--- a/modules/bmp/image_loader_bmp.cpp
+++ b/modules/bmp/image_loader_bmp.cpp
@@ -130,23 +130,19 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image,
line_ptr += 1;
} break;
case 24: {
- uint32_t color = *((uint32_t *)line_ptr);
-
- write_buffer[index + 2] = color & 0xff;
- write_buffer[index + 1] = (color >> 8) & 0xff;
- write_buffer[index + 0] = (color >> 16) & 0xff;
+ write_buffer[index + 2] = line_ptr[0];
+ write_buffer[index + 1] = line_ptr[1];
+ write_buffer[index + 0] = line_ptr[2];
write_buffer[index + 3] = 0xff;
index += 4;
line_ptr += 3;
} break;
case 32: {
- uint32_t color = *((uint32_t *)line_ptr);
-
- write_buffer[index + 2] = color & 0xff;
- write_buffer[index + 1] = (color >> 8) & 0xff;
- write_buffer[index + 0] = (color >> 16) & 0xff;
- write_buffer[index + 3] = color >> 24;
+ write_buffer[index + 2] = line_ptr[0];
+ write_buffer[index + 1] = line_ptr[1];
+ write_buffer[index + 0] = line_ptr[2];
+ write_buffer[index + 3] = line_ptr[3];
index += 4;
line_ptr += 4;
@@ -172,11 +168,9 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image,
const uint8_t *cb = p_color_buffer;
for (unsigned int i = 0; i < color_table_size; ++i) {
- uint32_t color = *((uint32_t *)cb);
-
- pal[i * 4 + 0] = (color >> 16) & 0xff;
- pal[i * 4 + 1] = (color >> 8) & 0xff;
- pal[i * 4 + 2] = (color)&0xff;
+ pal[i * 4 + 0] = cb[2];
+ pal[i * 4 + 1] = cb[1];
+ pal[i * 4 + 2] = cb[0];
pal[i * 4 + 3] = 0xff;
cb += 4;
@@ -211,7 +205,7 @@ Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f,
// A valid bmp file should always at least have a
// file header and a minimal info header
- if (f->get_len() > BITMAP_FILE_HEADER_SIZE + BITMAP_INFO_HEADER_MIN_SIZE) {
+ if (f->get_length() > BITMAP_FILE_HEADER_SIZE + BITMAP_INFO_HEADER_MIN_SIZE) {
// File Header
bmp_header.bmp_file_header.bmp_signature = f->get_16();
if (bmp_header.bmp_file_header.bmp_signature == BITMAP_SIGNATURE) {
@@ -304,7 +298,7 @@ static Ref<Image> _bmp_mem_loader_func(const uint8_t *p_bmp, int p_size) {
Error open_memfile_error = memfile.open_custom(p_bmp, p_size);
ERR_FAIL_COND_V_MSG(open_memfile_error, Ref<Image>(), "Could not create memfile for BMP image buffer.");
Ref<Image> img;
- img.instance();
+ img.instantiate();
Error load_error = ImageLoaderBMP().load_image(img, &memfile, false, 1.0f);
ERR_FAIL_COND_V_MSG(load_error, Ref<Image>(), "Failed to load BMP image.");
return img;