On 8/07/12 3:16 , Jorge D'Alpuim wrote:
> int height = image_rgb->s();
> int width = image_rgb->t();
> int length = image_rgb->r();
> const long size = width * height * length * 4;
> 
> unsigned char* rgb_data = image_rgb->data();
> unsigned char* rgba_data = (unsigned char*)calloc(size,sizeof(unsigned char));
> 
> for(long i = 0; i < size; i+= 4)
> {
> rgba_data[i + 0] = rgb_data[i + 0]; //red
> rgba_data[i + 1] = rgb_data[i + 1]; //green
> rgba_data[i + 2] = rgb_data[i + 2]; //blue
> rgba_data[i + 3] = 255; //alpha
> }

For one, you're skipping over every 4th byte of input data (rgb_data).
Try something like:

const int numPixels = width * height * length;
for (int i = 0; i < numPixels; ++i)
{
  rgba_data[i * 4 + 0] = rgb_data[i * 3 + 0];
  rgba_data[i * 4 + 1] = rgb_data[i * 3 + 1];
  rgba_data[i * 4 + 2] = rgb_data[i * 3 + 2];
  rgba_data[i * 4 + 3] = 0xff;
}

Cheers,
/ulrich
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to