Gray pictures - 8 bit

Hello,
For graphics processing I met in Java “ByteProcessor”.
Tell me where I’m wrong.
If I understood correctly this converts a color image to a grayscale image.
I can transform a pixel to gray, so the 3 components R, G, B have the same value.
Can a 24 bit image be transformed into 8 bit in RB? And so will I get a gray image?
Alternatively can I create an array of bytes (0…255) with the value of R, G or B?

Of course, you can convert an image to greyscale in Xojo. Even a quick goggle showed me multiple methods to do greyscale.

Not in ‘one line of code’
You can do it in a loop, setting pixels (slow)
If you have plugins, there are ‘one command’ techniques that do it much faster, such as GrayscaleMBS

1 Like

I can turn a color image to gray (24 bits) but I can’t find a way to set the image to 8 bits in RB.

How can you create a non 32 bits Picture Class ?

i think intern the picture class use always 32 bit for RGBA

MemoryBlock
https://documentation.xojo.com/api/language/memoryblock.html#memoryblock

for access pixel data from picture see .RGBSurface

Xojo hasn’t supported 8 bit images for many many years.
Annoyingly… For example, I often need monochrome bitmaps and frankly feel like I’m wasting 23 out of every 24 bits!

1 Like

I never got into the subject more than that but what I thought I knew was that a color needs 6 hexadecimal numbers (ex. &cFFFFFF) so 24 bits should be enough right?
My version of RB is 2010 and there was no Alpha channel.
When I create an image I use NewPicture (Width, Height, 32 ) but with 24 I don’t see any difference.
If I use 8, the image is transformed into black and white.
So I was thinking of creating an 8-bit image and replacing the color of each pixel with the color of the original pixels calculated in grayscale.
I don’t know if this is clear or correct but here is where I am.

i not get what you will achieve.
do you will write an image converter (load/save)?

will you load an image into gray for display in window?

for gray use
gray=(r+g+b)/3.0
red=gray
green=gray
blue=gray

or do you try to save memory?

outside of xojo there are image formats which use a color palette
so each pixel reference an index to this palette.

The extra 8 would be the alpha channel… the RGB are still 0…255 values

I was thinking of creating an 8-bit image

Just give up and create a 32 bit one.
Set the RGB values to equal amounts for greyscale.

I use Gray = 0.299R + 0.587G + 0.114*B (CIE formula).
I was wondering just because I found it in another language and it would make sense to have gray colors in one channel as all three (RGB) have the same value.

1 Like

Yes it would, but you cannot do it in (any recent version of…) Xojo.
Instead, decide on your grey value and apply it to all 3 of red, green, and blue.

From documentation around 2004:

More Picture Properties
The following property determines the color depth (in bits):
Picture.Depth as Integer
Legal values are 0,1,2,4,8,16, and 32. A value of 0 indicates that this Picture is a vector rather than a raster image.

So maybe 2010 still supported a depth of 8.
Nothing new does, (and I have long been annoyed at the loss of this feature)

I will try with an array of bytes and see if it’s faster.
Yes, Jeff I can convert a picture in 8 bits with RB 2010 but you get a picture in black and white.
But I’m sure, Beatrix without Google can enlighten us.