22 views
in System Integration by

Hello,

in my demo project i want to load an extern bitmap which i saved as an binary file. When implementing the following code i recognized some difference in Bitmap creation. When calling EwCreateBitmap in Windows the Bitmap is aligned to 4 Byte (empty pixels added) and with OpenGL the is no alignment.

I do not want to make a conversion while loading the Bitmap. Is it possible to influence the pixel alignment?

Another problem i've got is that under Linux the error 137 ("Failed to lock the surface for direct memory access.") occurs. With Windows i do not have any problem. Maybe it has to do something with the difference in Bitmap creation?!

 

XHandle DeviceDriver::create_xbitmap(myBITMAP Bitmap)
{
  XBitmap     *xBitmap;
  XBitmapLock *xBitmapLock;
  XPoint      xSize;  

  xSize.X = Bitmap.width;  
  xSize.Y = Bitmap.height;  

  /* create EW Bitmap */
  xBitmap = EwCreateBitmap(EW_PIXEL_FORMAT_NATIVE, xSize, 0, 1);
  if (!xBitmap)
  {
    printf("Could not create EW Bitmap \n");
    return 0;
  }
    
  /* Lock the entire bitmap for the write only operation */
  xBitmapLock = EwLockBitmap(xBitmap, 0, EwNewRect(0, 0, xSize.X, xSize.Y), 0, 1);
  uint32_t offset = (xBitmapLock->Pitch1Y >> 2) - xSize.X;    // different with Win32, OpenGL

  /* Get the pointer to the bitmap pixel memory */
  memcpy(xBitmapLock->Pixel1, Bitmap.image, Bitmap.size);

  /* finally, unlock the bitmap */
  EwUnlockBitmap(xBitmapLock);

  return (XHandle)xBitmap;
}

 

1 Answer

+1 vote
by
 
Best answer

Hello JK,

the alignment does strictly reflect the peculiarities (or even restrictions) of the particular target system. Specifying any other alignment is thus not possible. In turn, you should evaluate the Pitch variables when copying pixel data to the locked bitmap memory. The correct approach would be: implement a loop and iterate over the pixel rows. At the end of each row skip to the next row by additionally the value Pitch1Y to the original start position of the actual row. Be careful when adding the Pitch value to a pointer other than char*. The Pitch values are expressed in bytes. Eventually typecast the pointer to char* before performing the addition and then cast it back to the correct type (e.g. unsigned int*). See also following sections:

Type XBitmapLock

Extern Bitmap interface

Concerning your second question, probably you are trying to lock the bitmap for READ and WRITE operation. In case of OpenGL there is no interface to obtain read access to an OpenGL texture (to a bitmap memory). OpenGL permits only the write operation to its textures and manages (hides) the memory internally. Ensure the parameter aRead is 0 when calling the function EwLockBitmap().

I hope it helps you further.

Best regards

Paul Banach

by
Thanks for your reply Paul.

I removed the Read command of the Bitmap. That helped thanks. It would be great if you can add such info to the function description.
by

Great that it works now. Concerning the documentation, the description of the function EwLockBitmap() addresses the OpenGL limitations explicitly:

 

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...