Find the answer to your Linux question:
Results 1 to 3 of 3
Hai friends, i wrote a usb camera driver program,using this program i transfer data from camera to my pc.But the camera output is rgb565 format data. How can i open ...
  1. #1
    Just Joined!
    Join Date
    Apr 2007
    Posts
    16

    How to create .bmp file from a rgb565 file

    Hai friends,
    i wrote a usb camera driver program,using this program i transfer data from camera to my pc.But the camera output is rgb565 format data. How can i open this file in linux or how can i create a .bmp file from rgb. Anyone have idea about this or any good links ,pls help me asap......

    regards shabeer

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Posts
    45
    Preliminary explanation:
    «rgb565» is the name of a BMP colour-bitmask¹ and simply states, that the colour bits of each pixel are consequetively saved in 5, 6 and 5 bits. Thus an «rgb565»-“file” actually already is a bitmap file. If the file additionally contains a DIB/BMP header, then it already is a BMP-file.

    Answer:
    Due to your inability to open the file[s] in question, it seems it/they do[es] not possess that/these header[s]. The solution is simple:
    1. Use a program that can already do it, like i.e. ffmpeg².
    2. Add a BMP header for 16-bit BMP files.
    3. Convert it to another raw bitmap format (like rgb888, which means: 8 bits for each red, blue and green) and then add a valid BMP header. This approach was taken here. While I cannot vow for whether the code actually compiles (or for that matter: can be interpreted) or not, the algorithm is the core of the «rgb565 raw bitmap file» → «24 bit BMP file» conversion process (in this piece of code the BMP file header creation and the DIB scanline padding is abstracted in the “image” class instance). Adding a valid 24 bit BMP header is trivial, as it has only 2 variables, the x- und y-resolution:
      Code:
      int scan_line_bytes = (4 - ((x_res * 3) % 4)) % 4;
      int payload_size = x_res * y_res * 3 + y_res * scan_line_bytes;
      bitmap_header_type bmp_header = {
      	.bfType = 19778,
      	.bfSize = payload_size + 54,
      	.bfReserved1 = 0,
      	.bfReserved2 = 0,
      	.bfOffBits = 54,
      	.biSize = 40,
      	.biWidth = x_res,
      	.biHeight = y_res,
      	.biPlanes = 1,
      	.biBitCount = 24,
      	.biCompression = BI_RGB,
      	.biSizeImage = payload_size,
      	.biXPelsPerMeter = 0,
      	.biYPelsPerMeter = 0,
      	.biClrUsed = 0,
      	.biClrImportant = 0
      };
      I donʼt know if ImageMagick can do this automatically for you. I tried (as stated in ³)
      Code:
      $> ls
      RAWBMP_104x208.rawrgb
      $> convert -size 104x208 rgb:RAWBMP_104x208.rawrgb real.bmp;
      but this always aborted with the error message
      Code:
      $> convert -size 104x208 rgb:RAWBMP_104x208.rawrgb real.bmp;
      convert: Unexpected end-of-file `RAWBMP_104x208.rawrgb': No such file or directory.
      Although this process always created the file “real.bmp”, the result never matched the input except for the filesʼ resolution (hints as to what I missed or what mistake I made are welcome).


    Footnotes:
    1. Microsoft Windows Bitmap: Summary from the Encyclopedia of Graphics File Formats – BMP Version 3 (Microsoft Windows NT)
    2. RGB565 To PNG/JPEG | Software View
    3. Hints and tips specific to Imagemagick:
      „[…] Convert RAW back to some other
      Code:
      formatconvert -size widthxheight rgb:new.raw new.png
      […]“

  3. #3
    Just Joined!
    Join Date
    Apr 2007
    Posts
    16
    thankU for ur replay......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...