A3DGraphPictureData Struct Reference
A description of a two-dimensional picture. More...
Data Fields | |
A3DEPictureDataFormat | m_eFormat |
Image format specifier. | |
A3DUns8 * | m_pucBinaryData |
Image binary data. | |
A3DUns32 | m_uiPixelHeight |
Image height in pixels. If picture dimension is part of m_pucBinaryData , this field is 0. | |
A3DUns32 | m_uiPixelWidth |
Image width in pixels. If picture dimension is part of m_pucBinaryData , this field is 0. | |
A3DUns32 | m_uiSize |
The size of m_pucBinaryData in bytes. | |
Detailed Description
A description of a two-dimensional picture.
- Version
- 2.0
A picture is a set of color information organised according to a specific memory layout known as format. HOOPS supports various layouts such as RGB or grayscale.
Pictures are mainly used within textures descriptions. To known how to read or define texture information within Exchange, see A3DGraphTextureDefinitionData
.
- Encoding
- Raw picture data are written into
m_pucBinaryData
. Description for the actual content depends on the picture format selected intom_eFormat
. When dimensions of the picture is not encoded within the data, image width and height are written intom_uiPixelWidth
andm_uiPixelHeight
respectively, in pixels.
- Raw color data
m_pucBinaryData
can hold a raw pixel array where each byte describes a component for one pixel. According to the value form_eFormat
:kA3DPictureBitmapGreyByte
: Each pixel is encoded within one byte with a value of the range [0 ; 255]. This format is generally used for grayscale images.kA3DPictureBitmapGreyaByte
: Same askA3DPictureBitmapGreyByte
but each value is followed by a second pixel information, generally used for alpha (transparency) channel.kA3DPictureBitmapRgbByte
: Each pixel is encoded within a triplet of bytes which descriped the red, green and blue components of the pixel in memory order.kA3DPictureBitmapRgbaByte
: Same askA3DPictureBitmapRgbByte
but a fourth byte is added at the end of each triplet, generally for alpha (transparency) information.
The pixel array is describes row-major, where the origin is at the topleft corner of the image.
The following code describes an RGB 255x100 image with a color fading from red to green:
A3DGraphPictureData picture;
A3D_INITIALIZE_DATA(A3DGraphPictureData, picture);
picture.m_eFormat = kA3DPictureBitmapRgbByte;
picture.m_uiPixelWidth = 255;
picture.m_uiPixelHeight = 100;
picture.m_pucBinaryData = malloc(picture.m_uiSize);
A3DUns32 red_i = (picture.m_uiPixelWidth * row + column) * 3;
A3DUns32 green_i = red_i + 1;
A3DUns32 blue_i = green_i + 1;
picture.m_pucBinaryData[red_i] = 255 - row;
picture.m_pucBinaryData[green_i] = row;
picture.m_pucBinaryData[blue] = 0;
}
}
The following function is an example on how to use [OpenGL 4 glTexImage2D
] with HOOPS picture data:
{
assert(picture);
GLenum target = GL_TEXTURE_2D;
GLenum level = 0;
GLsizei width = picture->m_uiPixelWidth;
GLsizei height = picture->m_uiPixelHeight;
GLint border = 0;
GLenum type = GL_UNSIGNED_BYTE;
GLint internalformat;
GLenum format;
switch(picture->m_eFormat) {
}
glTexImage2D(target, level, internalformat,
width, height, border,
format, type, picture->m_pucBinaryData
);
return A3D_SUCCESS;
}
- Complex format
m_pucBinaryData
can contains encoded BMP, PNG or JPEG data accoring to the value ofm_eFormat
. In those cases, the dimension of the picture is part of the data. Thusm_uiPixelWidth
andm_uiPixelHeight
are set to 0.
- Memory management
- The content of
m_pucBinaryData
is allocated from the heap. When creating a picture instance, you are responsible for the management of its memory. When inserting a newA3DGraphPictureData
instance into the global state using#A3DGlobalInsertGraphPicture
, the content ofm_pucBinaryData
is cloned for internal use.