2005.10.27 06:40 "[Tiff] How located pixels with BitsPerSample not bound to byte?", by Шебеко Евгений

2005.10.27 15:55 "Re: [Tiff] How located pixels with BitsPerSample not bound to byte?", by Bob Friesenhahn

On Thu, 27 Oct 2005, [Windows-1251] Øåáåêî Åâãåíèé wrote:

If we talking about testing exotic images.

Look at the flower-rgb-contig-12.tif from the test images. It have RGB,Uncompressed, PlanarConfig=Continue, and BitsPerSample=12

How the pixels are located inside a strip in such case? I really cann't understand :)

Is it correct?

  Bytes:       0   |    1    |    2   |   3    |   4
  Bits :   76543210|7654|3210|76543210|76543210|7654|3210
  Pixels:  rrrrrrrr|rrrr|gggg|gggggggg|bbbbbbbb|bbbb|rrrr|
  Samples:   hiR   |lowR|hiG |  lowG  |  hiB   |lowB| hiR

I think that this is correct.

There is some code from GraphicsMagick which helps read/write samples from "bit streams". The code can be obtained via the web from "http://cvs.graphicsmagick.org/cgi-bin/cvsweb.cgi/GraphicsMagick/magick/bit_stream.h".

The code is quite easy to use ('bytes' is a stream of bits such as a scanline):

   BitStreamReadHandle bit_stream;
   BitStreamInitializeRead(&bit_stream, bytes);

   Loop around code like this to collect all samples...
     unsigned int red = BitStreamMSBRead(&bit_stream, 12);
     unsigned int green = BitStreamMSBRead(&bit_stream, 12);
     unsigned int blue = BitStreamMSBRead(&bit_stream, 12);

There is similar code to support writing bit streams.

The performance may not be as good as carefully hand-crafted code for a specific depth, but it makes dealing with depths ranging from 1 to 32 bits very easy. Since the code is inlined, if you can fill an array with red, green, blue and only invoke BitStreamMSBRead() once in the sample extraction loop (tighter loop), performance is likely to be better.

Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/