Page 1 of 1

10-Bit Color Packing

Posted: Mon Aug 21, 2023 12:52 pm
by chris319
Hello -

I am starting to work with 10-bit color (10 bits each red, green, blue, no alpha. I have written two procedures to encode r, g and b values into packed and unpacked 64-bit quads.

Could somebody please check my code? Does anyone have a faster, more efficient way of doing this?

Here are the pixel formats:

https://www.1stvision.com/cameras/IDS/I ... rmats.html

Thank you.

Code: Select all

;RGB10, BGR10, RGB12, BGR12, RGBa10, BGRa10, RGBa12, BGRa12
;Color pixel formats With a bit depth of 10 Or 12 bit need two bytes For each color value ("R", "G", "B", "a"), leaving 6 Or 4 bits of every second byte unused. With RGB10, BGR10, RGB12 Or BGR12 a pixel needs 6 byte = 48 bit in total. Adding an alpha channel, the size of RGBa10, BGRa10, RGBa12 And BGRa12 the pixel's size increases to 8 byte = 64 bit.
;The second pixel row starts With byte 6n Or 8n respectively.

;RGB10p32, BGR10p32
;With the packed 10 bit formats RGB10p32 And BGR10p32, the unused bits are reduced To only 2 out of 32 total bits. This means the Data is much denser packed but the alignment gets lost. RGB10p32 And BGR10p32 need 4 byte = 32 bits For each pixel.
;The second pixel row starts With byte 4n.

;https://www.1stvision.com/cameras/IDS/IDS-manuals/en/basics-color-pixel-formats.html

red1.q = 1023
green1.q = 1023
blue1.q = 1023

red2.q = 1023
green2.q = 1023
blue2.q =1023

;RGB10p32
Procedure RGB10p32 (red1, green1, blue1, red2, green2, blue2)

sampleP.q = 0 ;64 bits RGB10p32 - INITIALIZE TO ZERO

blue1 << 52
green1 << 42
red1 << 32

blue2 << 20
green2 << 10

sampleP | red2 | green2 | blue2 | red1 | green1 | blue1

ProcedureReturn sampleP

EndProcedure

Procedure rgb10 ()
sample.q = 0
  
red1 << 48
blue2 << 32
green2 << 16

sample | red2 | green2 | blue2 | red1 | green1 | blue1

ProcedureReturn sample

EndProcedure

Re: 10-Bit Color Packing

Posted: Mon Aug 21, 2023 7:37 pm
by STARGÅTE
I'm more than confused to your code.

What is the aim of RGB10p32() and rgb10() ?
Why RGB10p32 gives the color in a quad with the high value is an unpacked color and the lower value is packed?
Why rgb10() has no arguments? The colors are not defined as global, so they are zero inside the procedure.

Here is my code:

Code: Select all

Procedure.l RGB10(Red.w, Green.w, Blue.w)
	ProcedureReturn (Red & $3FF) | ((Green & $3FF) << 10) | ((Blue & $3FF) << 20)
EndProcedure


Procedure.w Red10(RGB10.l)
	ProcedureReturn RGB10 & $3FF
EndProcedure

Procedure.w Green10(RGB10.l)
	ProcedureReturn (RGB10 >> 10) & $3FF
EndProcedure

Procedure.w Blue10(RGB10.l)
	ProcedureReturn (RGB10 >> 20) & $3FF
EndProcedure

Define Color.l = RGB10(900, 400, 100)

Debug Hex(Color)
Debug Red10(Color)
Debug Green10(Color)
Debug Blue10(Color)

Re: 10-Bit Color Packing

Posted: Mon Aug 21, 2023 9:24 pm
by chris319
What is the aim of RGB10p32() and rgb10() ?
Did you read the web page I linked to? It gives two formats: packed and non-packed. The pixels MUST conform to either of those formats. Note that there are unused bits.

Re: 10-Bit Color Packing

Posted: Tue Aug 22, 2023 1:53 am
by idle
I think Stargate means how do you intend to process it.

Code: Select all

;RGB10p32
Procedure.q RGB10p32(r.w,g.w,b.w,r1.w,g1.w,b1.w)
  Protected col.q  
  
  col | r   
  col | (g << 10) 
  col | (b << 20)  
  col | (r1 << 32) 
  col | (g1 << 42) 
  col | (b1 << 52) 
  
  ProcedureReturn col 
  
EndProcedure

Procedure.q RGBa10(r.w,g.w,b.w)
  Protected col.q    
  col | r 
  col | (g << 16)  
  col | (b << 32)
  
  ProcedureReturn col  
  
EndProcedure 

;1100110011 = 819   
;1001001001 = 585 
 
col.q = RGB10p32(585,819,585,819,585,819) 
;1100110011-1001001001-1100110011-00-1001001001-1100110011-1001001001
Debug Bin(col) 

col.q = RGBa10(585,819,585) 
Debug LSet(Bin(col),64,"0")   
;1001001001-000000-1100110011-000000-1001001001-0000000000000000000000

Re: 10-Bit Color Packing

Posted: Tue Aug 22, 2023 10:33 am
by STARGÅTE
chris319 wrote: Mon Aug 21, 2023 9:24 pm
What is the aim of RGB10p32() and rgb10() ?
Did you read the web page I linked to? It gives two formats: packed and non-packed. The pixels MUST conform to either of those formats. Note that there are unused bits.
I read the page. My question refer to your implementation of those functions.
Your code for rgb10() gives alway 0
and your code for RGB10p32() calculates a quad value (64 bit) of two packed colors, but returns an integer (only 32 bit on x86).
Why do you calculate two colors at once?

Re: 10-Bit Color Packing

Posted: Tue Aug 22, 2023 11:45 pm
by chris319
How is this?

I was reluctant previously to left-shift a 16-bit varaible.

Code: Select all

Global red1.u = 1023
Global green1.u = 1023
Global blue1.u = 1023

Global red2.u = 1023
Global green2.u = 1023
Global blue2.u =1023

;RGB10p32
Procedure.q RGB10pa32 (red1, green1, blue1, red2, green2, blue2)

sampleP.q = 0 ;64 bits RGB10p32 - INITIALIZE TO ZERO

sampleP = red2 | green2 << 10 | blue2 << 20 | red1 << 32 | green1 << 42| blue1 << 52

ProcedureReturn sampleP

EndProcedure

Procedure.q rgb10 (red1, green1, blue1, red2, green2, blue2)
sample.q = 0
  
red1 << 48
blue2 << 32
green2 << 16

sample = red2 | green2 << 16| blue2 << 32| red1 << 48

ProcedureReturn sample

EndProcedure

Re: 10-Bit Color Packing

Posted: Wed Aug 23, 2023 7:34 am
by STARGÅTE
What are you doing?
In rgb10() you do a shift red1, blue1 and green 2, twice!
Additional, you have arguments green1 and blue1 but never use them in the procedure.
Please, can you explain what you want to do?

Re: 10-Bit Color Packing

Posted: Wed Aug 23, 2023 2:30 pm
by chris319
Better?

https://www.1stvision.com/cameras/IDS/I ... rmats.html

Code: Select all

Global red1.u = 1023
Global green1.u = 1023
Global blue1.u = 1023

Global red2.u = 1023
Global green2.u = 1023
Global blue2.u =1023

;RGB10p32
Procedure.q RGB10pa32 (red1, green1, blue1, red2, green2, blue2)

sampleP.q = 0 ;64 bits RGB10p32 - INITIALIZE TO ZERO

sampleP = red2 | green2 << 10 | blue2 << 20 | red1 << 32 | green1 << 42| blue1 << 52

ProcedureReturn sampleP

EndProcedure

Procedure.q rgb10 (red1, red2, green2, blue2)
sample.q = 0
  
sample = red2 | green2 << 16| blue2 << 32| red1 << 48

ProcedureReturn sample

EndProcedure