I am using a frame grabber to capture images on a film scanner. The raw image is captured by the frame grabber and put in a memory block. I then pass this to the Einhugur RawBitmap class, which converts it to a picture for display in my app.
Everything works fine if the frame grabber is set to 8 bit monochrome capture. But if I set it to 16bit monochrome, the resulting image is …not right.
With the camera set to mono8 acquisition, confirmed in the manufacturer’s software and their debug logging tool, using the following code in Xojo:
var grabbed as boolean = false
//get the frame buffer into the captureBuffer memory block
//This function looks at the camera's current mode and determines whether to
//expect an 8 or 16 bit image in the frame buffer.
grabbed = FrameGrabber.CXPGetFrameBuffer
if grabbed = true then
var rowbytes as integer
var bpp as integer
if FrameGrabber.frameBPP = 2 then //16bit color
bpp = 16
elseif FrameGrabber.frameBPP = 1 then //8bit mono
bpp = 8
end if
//Calculate bytes per row in the image
rowbytes = (bpp * FrameGrabber.frameColumns) / 8
//Use Einhugur plugin to convert raw image data to a picture
var frame as new RawBitmap(FrameGrabber.captureBuffer, FrameGrabber.frameColumns, FrameGrabber.frameRows, rowbytes, RawBitmap.RawBitmapFormat.gg)
Var convertedFrame as Picture = RawBitmapConverter.ToPicture(frame,false)
var displayedFrame as new picture(MainWindow.FrameDisplay.Width, MainWindow.FrameDisplay.Height)
displayedFrame.Graphics.DrawPicture(convertedFrame, 0, 0, displayedFrame.Graphics.Width, displayedFrame.Graphics.Height, 0, 0, convertedFrame.Width, convertedFrame.Height)
MainWindow.FrameDisplay.Backdrop = displayedFrame
end if
Resulting image - weird image but this is how it should look:
Now, if I set the camera to Mono16 and grab a frame in the manufacturer’s software, it looks exactly like the image above, only it’s from the 16bit frame buffer. but if I change how RawBitmap is interpreting the data, using “gg” as the RawBitmapFormat when setting up the RawBitmap object, the result is this:
You can see there’s some image there. Obviously this is an issue with how the 16bit data is being interpreted - but by Xojo? RawBitmap? I’m not sure. For the purpose of the app itself, display of the image at 8 bit is just fine as long as I’m able to process the image behind the scenes at 16. What am I missing here?