xforms-development
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XForms] displaying images


From: alessandro basili
Subject: Re: [XForms] displaying images
Date: Sun, 22 Jan 2012 21:28:20 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1

First mistake I found in my code:

On 1/21/2012 10:33 AM, alessandro basili wrote:
> Hi everyone,
> 
> I need to show images from an array and I am trying the following:
> 
> <begin pseudo-code>
> FL_IMAGE *image;
> 
> create_form_with_image() {
> 
>   int w, h, i, j;
> 
>   begin_form(); // fl_bgn_form is used...
> 
>   if (!(image = flimage_alloc())) {
>     PANIC("Cannot allocate image"); //exit (1) is used...
>   }
>   image->type = FL_IMAGE_GRAY16;
>   image->w    = w = 128;
>   image->h    = h = 128;
>   if (!(image->gray = fl_get_matrix (w, h, sizeof (uint16)))) {
>     PANIC("Cannot allocate matrix"); //exit (1) is used...
>   }
> 
>   for(i=0; i<128; i++) {
>     for(j=0; j<128; j++) {
>       image->gray[i][j] = 128*i+j; // some value...
>     }
>   }
> 
>   if ((flimage_display (image, form->window)) {
>     INFO("displaying image"); //printf is used...
>   }
> 

the form is not yet created, so image cannot be drawn yet. Moreover, the
flimage_display returns 0 if everything is ok, otherwise it reports the
error, therefore the above if() should reflect this behavior.

>   end_form(); // fl_end_form is used...
> }
> 
> //~----
> 
> int main () {
> 
>   fl_initialize();
>   create_form_with_image();
> 
>   while(1) fl_do_forms();
> }
> 
> <end pseudo-code>
> 
> Unfortunately, even though apparently I am able to allocate the image
> and the matrix, it looks like I'm not able to display the image.
> I have the form created, but I have only a gray square of the size I
> expect but nothing else.
> 
> Am I missing something basic? I guess so...

I think I missed a very stupid mistake in my code that prevented correct
allocation in the very first place. I use to have a local pointer
variable that points to the global pointer variable to simplify writing:

int *this_is_a_global_pointer;

int foo (void) {

  int *t = this_is_a_global_pointer;
  *t = 0;
}

Unfortunately this will work if and only if *this_is_a_global_pointer is
allocated before referring to it and this was the stupid part a messed
up with.

Well, now I see beautiful images, the way I wanted!

Al



reply via email to

[Prev in Thread] Current Thread [Next in Thread]