@ Jonnin
Actually that might be tricky because when I am using a monochrome camera
the color bitmap does not exist.
I have an industrial machine vision application. This has been running for
several years using a color camera(s) only. The machine is examining Product
A, at a rate of 12 frames per second. It then performs image analysis and
from that determines where the product is to be placed along the length of
the machine.
Now I want to use that process to do the same thing with product B. However,
without getting into details, Product B requires a monochrome camera.
Now I don't want to have two different apps. I could use compiler directives to
compile one way or the other. However I prefer not to do that. I have made the
program automatically detect which camera is plugged in and change the
parameters accordingly.
The cameras use USB3 interface and with their driver, images are captured
following either a hardware or software trigger. The camera driver then places
the image in the PC memory and supplies a pointer to that image in a callback
routine. The type of image pointed to is a function of the camera. The color
camera places a color bitmap in memory, while the mono camera places a
grayscale bitmap in memory.
So when using the mono camera, the color bitmap that you suggest I poke
with grayscale values, does not actually exist.
I could create a couple of RGBTriple bitmaps purely for that purpose, but again
it all gets messy.
Also I not only read information from the bitmaps but I am also writing pixel
data back to the bitmap. If I do as you suggest, I could read the grayscale
data from the color bitmap (that has been pre-loaded with grayscale info), but
I would still need a single byte pointer to write pixel data back to the grayscale
image.
My purpose in starting this thread was that I thought there may be a simple
way to overload a pointer so that it could point to different data types of
differing length.
Using a void pointer does that but then pointer arithmetic is not available,
which is essential when seeking various areas of interest in the image bitmaps.
Now because no one has come up with the simple answer, I assume that there
is no such simple answer.
Consider this....
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void Process Image (*pImage)
{
void ptr_anything;
If (ImageIsMono) ptr_anything = (uint8_t *) pImage;
else ptr_anything = (RGBTriple *) pImage;
// processing image.....
ptr_anything++; // does not compile
// more processing....
}
|
With the above, I can see that at compile time, the compiler does not know
SizeOf the pointer so cannot increment it at line 11. However at run time, the
SizeOf the data pointed to would be known because I set it prior to the
increment. But I guess the compiler manufacturer has to make this illegal as
they cannot depend on the coder always ensuring the pointer has been
assigned.
Now Consider this....
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
void Process Image (*pImage, int i)
{
uint8_t * ptr_monoBitmap;
RGBTriplet * ptr_colorBitmap;
If (ImageIsMono)
{
ptr_monoBitmap = (uint8_t *) pImage;
// processing image.....
ptr_monoBitmap = ptr_monoBitmap + i; // does compile
// more processing....
}
else
{
ptr_colorBitmap = (RGBTriple *) pImage;
// processing image.....
ptr_colorBitmap = ptr_colorBitmap + i; // does compile
// more processing....
}
}
|
With the above the pointer arithmetic does compile even though 'i' is unknown
at compile time.
This works I guess because the compiler knows the SizeOf the data pointed
at by the pointers, and of course, the SizeOf int is also known.