Basic help with displaying images

Hi,

I’m fairly new to OpenVG and am trying to learn some of the basics. Right now, I am attempting to display a 160x160 image in a 612x792 window using the OpenVG sample code that’s available from the Khronos site.

So far, I’ve had no luck in getting the image to be displayed. Could anyone give some pointers to what I could be doing wrong, or if I’m missing something?

Below is the code that is attempting to display the image:

vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
vgClear(0, 0, 612, 792);

// Acquire the source image
ptr_source_image = (unsigned short*)&WHITE[0];

// Create the VG image
vg_img = vgCreateImage(VG_sARGB_1555, 160, 160, VG_IMAGE_QUALITY_BETTER);
vgImageSubData(vg_img, ptr_source_image, 0, VG_sARGB_1555, 0, 0, 160, 160);

// Draw the image
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
vgLoadIdentity();
vgTranslate(306.0f - (float)(160 / 2), 396.0f - (float)(160 / 2));
vgDrawImage(vg_img);
eglSwapBuffers(egldisplay, eglsurface); //vgFlush( ) is called in here

Note: The image source, WHITE[ ], is an array containing 16-bit color, in the format of 1 Alpha Bit/5 Red bits/5 Green bits/5 Blue bits.

Thanks!

Several ideas…
Well, for starters, the stride on your vgImageSubData() call is 0. I think it’s probably 320 (or possibly greater?). This is causing you to load only the first line over and over again into your image.
Next, are you sure your image format is ARGB1555? If the alpha bit is set, then image is fully transparent (and hence not show up). Check to make sure it’s not RGBA5551 or something.
Finally, as a general tip, I’d also try to not do the vgTranslate() until you get everything working quite right. You might even try to using vgSetPixels() which might work better [be faster] for you if you’re not scaling.

Hope one of those helps.

Thanks for the clarification on the stride parameter. I was mistaking that value to represent the number of data bytes in an image buffer that separated the end of one scanline to the beginning of the next scanline.

The buffer that I am using that contains the image uses the value 0x7FFF to represent a white pixel, where the alpha bit is equal to zero. Hopefully I interpreted that correctly as ARGB1555!

I will give vgSetPixels( ) a try, ultimately I intend to do some form of scaling, but my more immediate goal is to get the image displayed.

Thanks for the feedback!

Just a quick update…

I simplified things to the following, using the stride and vgSetPixels that were suggested:

vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
vgClear(0, 0, 612, 792);

// Acquire the source image
ptr_source_image = (unsigned short*)&WHITE[0];

// Create the VG image
vg_img = vgCreateImage(VG_sARGB_1555, 160, 160, VG_IMAGE_QUALITY_BETTER);
vgImageSubData(vg_img, ptr_source_image, 320, VG_sARGB_1555, 0, 0, 160, 160);

// Draw the image
vgSetPixels(0, 0, vg_img, 0, 0, 160, 160);

I was able to get a white 160x160 image to display. To test out whether ARGB1555 was correct, I tried another 160x160 image that was not a solid color, and that displayed properly using vgSetPixels, so that was a good result.

Now, when I replace the vgSetPixels( ) function call with vgDrawImage(vg_img), instead of seeing the intended image, the 160x160 area of the window shows up as solid black. Any suggestions as to what could cause that? Are there any paint options that I should be setting?

Thanks again!

Hard to say.
Try setting the background color to something other than black before the vgDrawImage() call (like blue). That way:

If the screen is black, something is drawing, and it’s probably something to do with render state. I would try a different internal storage type for the vgImage (try up-converting it to one of the RGB888 [just change the type in the vgCreateImage call to something else] - maybe there is no texture sampler for RGB5551 in your driver implementation). You did try calling vgGetError() before and after the vgDrawImage() call, right? Other than that, ensure that alpha masking, scissoring, color transformations, and every other such setting is the default [off], that blending is set to SRC_OVR, and that when you call vgDrawImage, you are actually using VG_DRAW_IMAGE_NORMAL instead of one of the other funky modes [or an invalid one].

Otherwise if it remains blue, it’s probably a transform issue and the image is drawing somewhere you don’t expect (just leave all the matrices at the identity). Do baby steps on the transform until you figure out what’s happening and why.


Addendum:
I think you might actually have your alpha mixed up and it’s treating your image as transparent. Try inverting your alpha bit or using RGBx555x/xBGRx555 modes. Give that a try too.

Thanks Ivo, your last comment regarding the alpha was the cause!