12bpp -> tPixMap

BlitzMax Forums/BlitzMax Programming/12bpp -> tPixMap

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Thanks Angel

The conversion is for a frame from a webcam.

Played around with it a bit an found that the format is 12bit YUV. I can get a image but the coluring is incorrect. I am attempting to convert the 4 bit YUV values to 8 Bit RGB values (RGB888)

Any ideas?

Code Below:-



TempMap= CreatePixmap (width, Height,PF_RGB888)
Local bnkPixels=CreateStaticBank(VideoMemoryAdress,width*Height*1.5)
' Local bnkTemp=CreateBank(width*Height*3)



'Assumes the pixmap is RGB format
Local sourcep:Byte Ptr=VideoMemoryAdress 'the address of the 12bpp YUV data
Local Dest:Byte Ptr= PixmapPixelPtr(tempmap,0,0) 'your pixmap object
Local Byte1:Byte
Local y1,u1,v1:Int
Local r,g,b :Int

Local YUV:Byte[width*3,Height]

'Transfer into Array(W*H) (YUV in matrices of 3 widths for Y,U and V) - i.e
For Local N:Int = 0 To Height -1
For Local n1:Int = 0 To (width*1.5)-1
Byte1=sourcep[(N*width)+n1]
yuv[(n1*2),N]=(Byte1 &$0F) Shr 4
yuv[(n1*2)+1,n]=(Byte1 & $F0)
Next
Next


Local Off1:Int=width 'start point for second set of values on row
Local Off2:Int=width*2 'start point for thrid set of values on row

For Local x:Int=0 To Height-1
For Local y:Int =0 To width-1
y1=yuv[y,x]
u1=yuv[OFF1+y,x]
u1=yuv[OFF2+y,x]

y1:-16
u1:-128
v1:-128



R = ( 298 * y1 + 409 * v1 + 128)& $ff
G = ( 298 * y1 - 100 * u1 - 208 * v1 + 128) & $ff
B = ( 298 * y1 + 516 * u1 + 128) & $ff


Dest[(((x*width)+y)*3)]=r
Dest[(((x*width)+y)*3)+1]=G
Dest[(((x*width)+y)*3)+2]=b


Next

Next