alexh110
23rd February 2013, 19:38
Hey guys.
Have just written a QBASIC program to extract the pixel data from a 24-bit bmp, convert to YUV, then convert back to RGB and write out another bmp.
The idea is to manipulate the YUV data with some code I will insert later on.
However it's not working correctly: my output file has a black bar across the top, though the remainder of the image lower down is OK.
Presumably there's an error in my assumptions about the bmp's header structure, but I'm not sure how to adjust the BMPHeaderType.
Any help would be great!
My code is shown below (NB I'm using the array l(x%, y%) for the Y component values to avoid confusion with the y-coordinate):
TYPE BMPHeaderType
* * id AS STRING * 2*
* * size AS LONG*
* * rr1 AS INTEGER*
* * rr2 AS INTEGER*
* * offset AS LONG*
* * horz AS LONG*
* * wid AS LONG*
* * hei AS LONG*
* * planes AS INTEGER*
* * bpp AS INTEGER*
* * pakbyte AS LONG*
* * imagebytes AS LONG*
* * xres AS LONG*
* * yres AS LONG*
* * colch AS LONG*
* * ic AS LONG*
* * pal AS STRING * 1024*
END TYPE
DIM BmpHeader AS BMPHeaderType
OPEN "4.bmp" FOR BINARY AS #1
GET #1, , BmpHeader
DIM Pixel AS STRING * 1
DIM l(720, 576) AS INTEGER
DIM u(720, 576) AS INTEGER
DIM v(720, 576) AS INTEGER
FOR y% = 1 TO 576
* * FOR x% = 1 TO 720
* * * * GET #1, , Pixel
* * * * B = ASC(Pixel)
* * * * GET #1, , Pixel
* * * * G = ASC(Pixel)
* * * * GET #1, , Pixel
* * * * R = ASC(Pixel)
* * * * l(x%, y%) = 0.299 * R + 0.587 * G + 0.114 * B
* * * * u(x%, y%) = (B - l(x%, y%)) * 0.565
* * * * v(x%, y%) = (R - l(x%, y%)) * 0.713
NEXT x%, y%
CLOSE #1
OPEN "4_mod.bmp" FOR BINARY AS #1
PUT #1, , BmpHeader
FOR y% = 1 TO 576
* * FOR x% = 1 TO 720
* * * * R = l(x%, y%) + 1.403 * v(x%, y%)
* * * * G = l(x%, y%) - 0.344 * u(x%, y%) - 0.714 * v(x%, y%)
* * * * B = l(x%, y%) + 1.770 * u(x%, y%)
* * * * R = INT(R)
* * * * G = INT(G)
* * * * B = INT(B)
* * * * IF R > 255 THEN R = 255
* * * * IF G > 255 THEN G = 255
* * * * IF B > 255 THEN B = 255
* * * * IF R < 0 THEN R = 0
* * * * IF G < 0 THEN G = 0
* * * * IF B < 0 THEN B = 0
* * * * Pixel = CHR$(B)
* * * * PUT #1, , Pixel
* * * * Pixel = CHR$(G)
* * * * PUT #1, , Pixel
* * * * Pixel = CHR$(R)
* * * * PUT #1, , Pixel
NEXT x%, y%
CLOSE #1
Have just written a QBASIC program to extract the pixel data from a 24-bit bmp, convert to YUV, then convert back to RGB and write out another bmp.
The idea is to manipulate the YUV data with some code I will insert later on.
However it's not working correctly: my output file has a black bar across the top, though the remainder of the image lower down is OK.
Presumably there's an error in my assumptions about the bmp's header structure, but I'm not sure how to adjust the BMPHeaderType.
Any help would be great!
My code is shown below (NB I'm using the array l(x%, y%) for the Y component values to avoid confusion with the y-coordinate):
TYPE BMPHeaderType
* * id AS STRING * 2*
* * size AS LONG*
* * rr1 AS INTEGER*
* * rr2 AS INTEGER*
* * offset AS LONG*
* * horz AS LONG*
* * wid AS LONG*
* * hei AS LONG*
* * planes AS INTEGER*
* * bpp AS INTEGER*
* * pakbyte AS LONG*
* * imagebytes AS LONG*
* * xres AS LONG*
* * yres AS LONG*
* * colch AS LONG*
* * ic AS LONG*
* * pal AS STRING * 1024*
END TYPE
DIM BmpHeader AS BMPHeaderType
OPEN "4.bmp" FOR BINARY AS #1
GET #1, , BmpHeader
DIM Pixel AS STRING * 1
DIM l(720, 576) AS INTEGER
DIM u(720, 576) AS INTEGER
DIM v(720, 576) AS INTEGER
FOR y% = 1 TO 576
* * FOR x% = 1 TO 720
* * * * GET #1, , Pixel
* * * * B = ASC(Pixel)
* * * * GET #1, , Pixel
* * * * G = ASC(Pixel)
* * * * GET #1, , Pixel
* * * * R = ASC(Pixel)
* * * * l(x%, y%) = 0.299 * R + 0.587 * G + 0.114 * B
* * * * u(x%, y%) = (B - l(x%, y%)) * 0.565
* * * * v(x%, y%) = (R - l(x%, y%)) * 0.713
NEXT x%, y%
CLOSE #1
OPEN "4_mod.bmp" FOR BINARY AS #1
PUT #1, , BmpHeader
FOR y% = 1 TO 576
* * FOR x% = 1 TO 720
* * * * R = l(x%, y%) + 1.403 * v(x%, y%)
* * * * G = l(x%, y%) - 0.344 * u(x%, y%) - 0.714 * v(x%, y%)
* * * * B = l(x%, y%) + 1.770 * u(x%, y%)
* * * * R = INT(R)
* * * * G = INT(G)
* * * * B = INT(B)
* * * * IF R > 255 THEN R = 255
* * * * IF G > 255 THEN G = 255
* * * * IF B > 255 THEN B = 255
* * * * IF R < 0 THEN R = 0
* * * * IF G < 0 THEN G = 0
* * * * IF B < 0 THEN B = 0
* * * * Pixel = CHR$(B)
* * * * PUT #1, , Pixel
* * * * Pixel = CHR$(G)
* * * * PUT #1, , Pixel
* * * * Pixel = CHR$(R)
* * * * PUT #1, , Pixel
NEXT x%, y%
CLOSE #1