Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Intelligent bitmap depth conversion 1,4,8,16,24 bits

Intelligent bitmap depth conversion 1,4,8,16,24 bits

Scheduled Pinned Locked Moved C / C++ / MFC
comgraphicstutorialquestion
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sumit Kapoor
    wrote on last edited by
    #1

    Hi All, I want to do Intelligent bitmap depth conversion. Convert XXX to XXX (without color lose): 24 bits --> 16 bits (If few color used that can fit in 16 bits) 24 bits --> 8 bits (If few color used that can fit in 8 bits) 24 bits --> 4 bits (If few color used that can fit in 4 bits) 24 bits --> 1 bits (If few color used that can fit in 1 bit) Do u know, How I can find this bitmap has exact color(with no color lose) to fit in lower depth? For example : If I have a 24bits baitmap, but that is using only two colors. These two colors can be shown by 4 bits bitmap without any lose of color, then I should use 4 bits bitmap WHY 24 bits. Thanks:) Sumit K.:) ---Sumit Kapoor--- sumit_kapoor1980@hotmail.com

    J N 2 Replies Last reply
    0
    • S Sumit Kapoor

      Hi All, I want to do Intelligent bitmap depth conversion. Convert XXX to XXX (without color lose): 24 bits --> 16 bits (If few color used that can fit in 16 bits) 24 bits --> 8 bits (If few color used that can fit in 8 bits) 24 bits --> 4 bits (If few color used that can fit in 4 bits) 24 bits --> 1 bits (If few color used that can fit in 1 bit) Do u know, How I can find this bitmap has exact color(with no color lose) to fit in lower depth? For example : If I have a 24bits baitmap, but that is using only two colors. These two colors can be shown by 4 bits bitmap without any lose of color, then I should use 4 bits bitmap WHY 24 bits. Thanks:) Sumit K.:) ---Sumit Kapoor--- sumit_kapoor1980@hotmail.com

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      There are a few articles on working with bitmaps at CP. I do not remember if CxImage supports bitmap color depth conversion, but it supports multiple image formats. The CDibData class does support such conversion, but I never did get around to updating it (a bug-dealing with compression). The only reason for converting your two color bitmap, from a 24-bit format, is to reduce the storage requirements. Think about that; a 24-bit image stores each pixel value in 3-bytes, a 4-bit image stores two pixels values per byte. A 4-bit bitmap image does require that a palette be provide, but that palette will, in this case, have only two entries. INTP Every thing is relative...

      1 Reply Last reply
      0
      • S Sumit Kapoor

        Hi All, I want to do Intelligent bitmap depth conversion. Convert XXX to XXX (without color lose): 24 bits --> 16 bits (If few color used that can fit in 16 bits) 24 bits --> 8 bits (If few color used that can fit in 8 bits) 24 bits --> 4 bits (If few color used that can fit in 4 bits) 24 bits --> 1 bits (If few color used that can fit in 1 bit) Do u know, How I can find this bitmap has exact color(with no color lose) to fit in lower depth? For example : If I have a 24bits baitmap, but that is using only two colors. These two colors can be shown by 4 bits bitmap without any lose of color, then I should use 4 bits bitmap WHY 24 bits. Thanks:) Sumit K.:) ---Sumit Kapoor--- sumit_kapoor1980@hotmail.com

        N Offline
        N Offline
        normanS
        wrote on last edited by
        #3

        16-bit colour simply allocates fewer bits per colour than 24-bit. A common 16-bit format which is easy to describe uses 5 pixels each for Red, Green, Blue, with one unused, i.e. it is 15-bit. True 16-bit allocates 6 bits for green, I think. To check whether an image is entirely suitable for 15-bit, you could use brute-force, and step through every pixel, checking that the 3 least-significant bits for each colour are all zero. Theoretically, you loose information if you discard non-zero bits. Alternatively, you could just force 24-bit images to 16-bit, but this can give visible changes in the image. To convert to 8-bit per pixel or lower, I don't think there is an easy way. I would allocate a 256-member array for 24-bit colour values, then step through the pixels, one by one. For each pixel, check if the value is in the array. If the colour value is in the array, go on to the next pixel. If it is not, add its colour value to the array. If the pixel's colour value is not in the array, but the array already has 256 colour values, then sorry - your image can not be converted to an 8-bit image without loss of quality! ((I seem to remember something about 16 "system reserved" colours in an 8-bit image, so you may only be able to use 240 colours.))

        S 1 Reply Last reply
        0
        • N normanS

          16-bit colour simply allocates fewer bits per colour than 24-bit. A common 16-bit format which is easy to describe uses 5 pixels each for Red, Green, Blue, with one unused, i.e. it is 15-bit. True 16-bit allocates 6 bits for green, I think. To check whether an image is entirely suitable for 15-bit, you could use brute-force, and step through every pixel, checking that the 3 least-significant bits for each colour are all zero. Theoretically, you loose information if you discard non-zero bits. Alternatively, you could just force 24-bit images to 16-bit, but this can give visible changes in the image. To convert to 8-bit per pixel or lower, I don't think there is an easy way. I would allocate a 256-member array for 24-bit colour values, then step through the pixels, one by one. For each pixel, check if the value is in the array. If the colour value is in the array, go on to the next pixel. If it is not, add its colour value to the array. If the pixel's colour value is not in the array, but the array already has 256 colour values, then sorry - your image can not be converted to an 8-bit image without loss of quality! ((I seem to remember something about 16 "system reserved" colours in an 8-bit image, so you may only be able to use 240 colours.))

          S Offline
          S Offline
          Sumit Kapoor
          wrote on last edited by
          #4

          for 24 to 16 no idea come to mind... For 24 to 8 bit.. ya..you are right I have to iterate and find out about color usage, that's already going in my mind, For 256 colors we can make 216 colors by combinations of(0,51,102,153,204, 255)and other 40 colors I have not found yet..how to find these.. But I don't think, it's a good idea. I m working in this direction..but mind is still trying to avoide this method. Regards, Sumit K sumit_kapoor1980@hotmail.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups