Image data containers [SOLVED]

On 10/02/2017 at 02:43, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R14 
Platform:      
Language(s) :     C++  ;

---------
Hi all,

could one of the fine folk here please provide an example of how we can set bitmap image data for proper 32bit images? Something like this (but in 32bit data land!) would help:

// psuedo code
  
void MyDialog::GetImageData(int width,int height,BaseBitmap* bmp)
{
    UCHAR *img = gNew UCHAR[width*height*3];
	
    // set one pixel to grey
    img[7*14 + 36 + 0] = 128; // R
    img[7*14 + 36 + 1] = 128; // G
    img[7*14 + 36 + 2] = 128; // B
  
    for(int h = 0; h < height;)
    {
        bmp->SetPixelCnt(o,h,width,(UCHAR* )img[h * width],COLORBYTES_RGB,COLORMODE_RGB,PIXELCNT_0);
  
        h++;
    }
  
    // free container etc.
}

Also, could they clarify what data range the image data should be in? E.g. 0.0 - 1.0 or 0 - 4294967295.

Cheers,

WP.

On 13/02/2017 at 09:00, xxxxxxxx wrote:

Hello,

32-bit image data is stored as Float32 data:

  
AutoAlloc<BaseBitmap> bitmap;  
if (!bitmap)  
  return false;  
  
// define bitmap dimensions and bit depth  
const Int32 width  = 1024;  
const Int32 height = 1024;  
const Int32 pixelBytes = COLORBYTES_RGBf; // RGBf format  
const Int32 pixelBits  = pixelBytes * 8;  
  
// initialize the BaseBitmap with the given dimensions and bit depth  
const IMAGERESULT res = bitmap->Init(width, height, pixelBits);  
if (res != IMAGERESULT_OK)  
  return false;  
  
// allocate memory for one line  
const Int32 bufferSize = width * 3;  
PIX_F*      lineBuffer = NewMemClear(PIX_F, bufferSize);  
if (!lineBuffer)  
  return false;  
  
// loop through all lines  
for (Int32 y = 0; y <= height; ++y)  
{  
  // shade of red based on the position  
  const Float32 red = Float32(y) / Float32(height);  
  
  Int32 offset = 0;  
  for (Int32 x = 0; x < width; ++x)  
  {  
  // shade of green based on the position  
  const Float32 green = Float32(x) / Float32(width);  
  
  // fill buffer  
  lineBuffer[offset] = red;  
  lineBuffer[offset + 1] = green;  
  lineBuffer[offset + 2] = 0.0;  
  
  offset += 3;  
  }  
  
  // write full line into the bitmap  
  bitmap->SetPixelCnt(0, y, width, (UChar* )lineBuffer, pixelBytes, COLORMODE_RGBf, PIXELCNT_0);  
}  
  
// delete line memory  
DeleteMem(lineBuffer);  

best wishes,
Sebastian

On 14/02/2017 at 02:27, xxxxxxxx wrote:

Thanks Sebastian - that's got it working :thumbsup:

WP.