loading bitmap trouble
Mummra

Good afternoon, I have the following problem when I want to load the image mk.png the program snaps, and it's not the program because you can load other images even load the same image but changing the background in this case mkasd.png. in the version 5.0.10 ther was no problem. I'm using the current version vstudio2015 allegro5_1_12 so do i need to do somting else befor loading the image?.

sorri for the bad inglesh

this is my code

#include "allegro5\allegro5.h"
#include "allegro5\allegro_image.h"
#include <iostream>

int main()
{
al_init();
al_init_image_addon();

ALLEGRO_DISPLAY *display;
display = al_create_display(640, 480);
if (display == nullptr)
{
return EXIT_FAILURE;
}
al_clear_to_color(al_map_rgb(0, 0, 0));
ALLEGRO_BITMAP *img = al_load_bitmap("mk.png");
al_draw_bitmap(img, 0.0, 0.0, 0);
al_flip_display();
al_rest(5.0);
return 0;
}

SiegeLord

I just tried your code with MSVC 2015 and the 5.1.12 32 and 64 bit binaries, and it worked ok (at least with my bitmap). Could you make sure that your bitmap is where you expect it to be (also perhaps try using an absolute path, just to be sure).

Mummra

yes the code works but when i tried this bitmap (mk.png) it breaks

Elias

This .png is missing its CRC value, so is basically invalid. We could make Allegro read it anyway (we can instruct libpng to read on instead of error out) - but the downside is, if we do that we are likely to read in actually broken png files as well.

Best way is to simply open your .png in an image editor and save it again, then it will be fine.

elias@T440s:/tmp$ pngcheck -v mk.png 
File: mk.png (8826 bytes)
  chunk IHDR at offset 0x0000c, length 13
    363 x 475 image, 8-bit palette, non-interlaced
  chunk PLTE at offset 0x00025, length 768: 256 palette entries
  chunk tRNS at offset 0x00331, length 256: 256 transparency entries
  chunk IDAT at offset 0x0043d, length 7725
    zlib: deflated, 32K window, default compression
  chunk IEND at offset 0x02276, length 0
:  EOF while reading CRC value
ERRORS DETECTED in mk.png

[edit:] Actually, you can specify special handling for CRC errors, this patch would make Allegro ignore them:

#SelectExpand
1diff --git a/addons/image/png.c b/addons/image/png.c 2index 97badd0..9f014de 100644 3--- a/addons/image/png.c 4+++ b/addons/image/png.c 5@@ -62,7 +62,7 @@ static void read_data(png_structp png_ptr, png_bytep data, png_uint_32 length) 6 { 7 ALLEGRO_FILE *f = (ALLEGRO_FILE *)png_get_io_ptr(png_ptr); 8 if ((png_uint_32) al_fread(f, data, length) != length) 9- png_error(png_ptr, "read error (loadpng calling al_fs_entry_read)"); 10+ png_warning(png_ptr, "read error (loadpng calling al_fs_entry_read)"); 11 } 12 13 14@@ -110,6 +110,8 @@ static ALLEGRO_BITMAP *really_load_png(png_structp png_ptr, png_infop info_ptr, 15 16 ALLEGRO_ASSERT(png_ptr && info_ptr); 17 18+ png_set_crc_action(png_ptr, PNG_CRC_WARN_USE, PNG_CRC_WARN_DISCARD); 19+ 20 /* The call to png_read_info() gives us all of the information from the 21 * PNG file before the first IDAT (image data chunk). 22 */

Mummra

a ok thanx

Thread #615905. Printed from Allegro.cc