SetPixel() for 32 bit float images
-
In the class c4d.bitmaps.BaseBitmap you can call BaseBitmap.SetPixel() to set the color value of an individual pixel. It seems like it only takes in values between 0 and 255 for RGB. I'm working with MultipassBitmap to create a 32 bit float image and want to be able to modify the individual pixels. Is there a similar way to change the pixel values so I could feed it a value between 0 and 1?
-
Hello,
you can write 32bit data into a BaseBitmap using
SetPixelCnt()
. This function allows to write a block of data into the bitmap.You find example code showing how to use SetPixelCnt() in the documentation, on GitHub or here:
bitmap = c4d.bitmaps.BaseBitmap() if bitmap is None: return # define bitmap dimensions and bit depth width = 100 height = 100 pixelBytes = c4d.COLORBYTES_RGBf # RGBf format pixelBits = pixelBytes * 8 # initialize the BaseBitmap with the given dimensions and bit depth res = bitmap.Init(width, height, pixelBits) if res != c4d.IMAGERESULT_OK: return # allocate memory for one line bufferSize = pixelBytes * width lineBuffer = storage.ByteSeq(None, bufferSize) # loop through all lines for y in xrange(height): # shade of red based on the position red = float(y) / float(height) offset = 0 for x in xrange(width): # shade of green based on the position green = float(x) / float(width) # fill buffer lineBuffer[offset + 0:offset + 4] = struct.pack("f",red) lineBuffer[offset + 4:offset + 8] = struct.pack("f", green) lineBuffer[offset + 8:offset + 12] = struct.pack("f", 0.0) offset = offset + pixelBytes # write full line into the bitmap bitmap.SetPixelCnt(0, y, width, lineBuffer.GetOffset(0), pixelBytes, c4d.COLORMODE_RGBf, c4d.PIXELCNT_0) c4d.bitmaps.ShowBitmap(bitmap)
As always, please add tags to your post.
best wishes,
Sebastian -
Thanks so much this is exactly what I was looking for.