Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » ALLEGRO 5 - Bitmap Corruption after writing to source image

This thread is locked; no one can reply to it. rss feed Print
ALLEGRO 5 - Bitmap Corruption after writing to source image
Kev Callahan
Member #6,022
July 2005
avatar

I'm currently messing around with ALLEGRO 5 on an ARM chip (iMX6).
I pretty much seem to have it running but a weird issue has now arisen.

I found this initially whilst using al_convert_mask_to_alpha() converting magic pink to transparency.

The issue is that if I have an ALLEGRO_BITMAP and drawing it straight to the display everything's fine.

However if I write to this BITMAP using al_convert_mask_to_alpha() or even if I draw another smaller BITMAP onto it, then it appears to corrupt the original image.

Setting a single pixel on the image doesn't appear to have any corruption effect..

Any ideas on how I best investigate this to track down the error?
I'm suspicious that maybe it's a colour depth issue (could it change?) but am struggling where to go from here..!

EDIT:
Okay more information.

bmp1 is 200x200
bmp2 is 200x200
bmp3 is 20x20

Load bmp1 and leave as is - drawn okay on display.
Load bmp2 and leave as is - drawn okay on display
Load bmp2 and draw bmp3 on it - bmp3 'part' looks fine, rest of bmp2 is corrupt.
Now..
If I load bmp2, draw bmp3, then draw bmp1 onto it, it looks fine.
If I load bmp2, draw bmp3, then draw bmp1 onto it, then draw bmp3 onto it, it looks fine.
Aarrgh... Bitmap colour depth issue??

EDIT2:
It appears the smaller bitmap is 24 bit depth, the larger images are 32..
Shouldn't this sort itself out..?

Elias
Member #358
May 2000

Could also be a bug in OpenGL drivers - but more likely in Allegro. Can you post a minimal program reproducing it?

--
"Either help out or stop whining" - Evert

Kev Callahan
Member #6,022
July 2005
avatar

As requested (pardon the hastily stripped down source), also attached the two source images, screenshot showing corruption and allegro.log

tried with 24bit and 32 bit source images - same issue.
Could be OPENGL drivers as I'm using an embedded card using the Vivante GC2000 drivers..

Thanks.

#SelectExpand
1#include <stdio.h> 2#include <stdlib.h> 3#include <math.h> 4#include <signal.h> 5#include <ctype.h> 6 7#include <allegro5/allegro.h> 8#include <allegro5/allegro_image.h> 9#include <allegro5/allegro_font.h> 10#include <allegro5/allegro_ttf.h> 11#include <allegro5/allegro_primitives.h> 12#include <allegro5/allegro_opengl.h> 13#include <allegro5/allegro_image.h> 14 15#include "header.h" 16#include "font.h" 17#include "button.h" 18 19int winsize_x = 640; 20int winsize_y = 480; 21 22ALLEGRO_DISPLAY *display = NULL; 23 24#define HZTIMER 30 25 26ALLEGRO_BITMAP *bmp1, *bmp2, *bmp3; 27 28// ** 29int main(int argc, char **argv) 30{ 31 int drawpage=0, mouse_x=0, mouse_y=0; 32 char inifile[32] = {0}; 33 34 ALLEGRO_TIMER *timer = NULL; 35 ALLEGRO_EVENT_QUEUE *eventq = NULL; 36 ALLEGRO_KEYBOARD_STATE *kbdstate = NULL; 37 ALLEGRO_MOUSE_STATE *mousestate = NULL; 38 39 // ** allegro initialisation 40 { 41 if (! al_init()) { fprintf(stderr, "Failed to initialise ALLEGRO\n"); return -1; } 42 43 // input 44 if (! al_install_keyboard()) { WHERE(); } 45 if (! al_install_mouse ()) { WHERE(); } 46 47 // addons 48 al_init_image_addon(); 49 al_init_font_addon(); 50 al_init_ttf_addon(); 51 al_init_primitives_addon(); 52 } 53 54 // ** create default path for resources 55 { 56 ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH); 57 al_append_path_component(path, "resources"); 58 al_change_directory(al_path_cstr(path, '/')); 59 fprintf(stderr, "PATH: %s\n", al_path_cstr(path, '/')); 60 al_destroy_path(path); 61 } 62 63 // ** setup display 64 { 65 al_set_new_display_flags (ALLEGRO_OPENGL); 66 al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 67 al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST); 68 69 display = al_create_display(winsize_x, winsize_y); 70 71 printf("OPENGL VERSION %x\n", al_get_opengl_version()); 72 printf("OPENGL VARIANT %x\n", al_get_opengl_variant()); 73 74 if (! display) { fprintf(stderr, "failed to create display %dx%d\n", winsize_x, winsize_y); return -1; } 75 76 fprintf(stderr, "Created Display %dx%d\n", winsize_x, winsize_y); 77 78 al_set_window_title(display, "SIMPLE"); 79 } 80 81 // clear display 82 { 83 al_set_target_backbuffer(display); 84 al_clear_to_color(al_map_rgb(12,13,18)); 85 } 86 87 bmp1 = al_load_bitmap("200x200.png"); 88 bmp2 = al_load_bitmap("200x200.png"); 89 bmp3 = al_load_bitmap("20x20.png"); 90 91 //al_convert_mask_to_alpha(bmp2, al_map_rgb(255,0,255)); // magic pink is transparent 92 93 // cause bug - draw bmp3 onto bmp2 94 { 95 al_set_target_bitmap(bmp2); 96 al_draw_bitmap(bmp3, 50, 50, 0); 97 } 98 99 al_set_target_backbuffer(display); 100 101 102 eventq = al_create_event_queue(); 103 104 // ** loop 105 while (1) 106 { 107 // ** draw on display 108 { 109 al_set_target_backbuffer(display); 110 al_draw_bitmap(bmp1, 0, 0, 0); 111 al_draw_bitmap(bmp2, 320, 0, 0); 112 } 113 114 al_flip_display(); 115 116 } 117 118 // ** shutdown 119 { 120 al_destroy_display(display); 121 } 122 123 return 0; 124}

EDIT:

Much more investigation today - I'm now thinking there are driver issues (maybe I need to do something like Trent did for the Raspberry Pi to get Allegro working on this card, but quite frankly that's beyond me).

To summarise, it appears that loading a bitmap and displaying on the screen appears to work, but as soon as I read or write access that bitmap (eg with al_get_pixel()), the image reverts to an 'old' version that's cached somewhere... (in the GPU?) from previously (demonstrated by changing the images used).
Is there any way I can 'invalidate' the bitmap[ stored in the GPU?
Must admit this isn't an area I wanted to investigate and my knowledge of this is pretty much zero.

Go to: