开发者

48 bits TIFF format [closed]

Closed. Th开发者_运维技巧is question does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 4 years ago.

Improve this question

I have an image saved in tiff format which is 24 bits per pixel. May I know if there's a program written in C language or java that can convert the 24 bits per pixel to 48 bits per pixel?


If I was writing such a program in C, I'd start by looking at libtiff. It's pretty straightforward to read and write tiff image data.

The more interesting question is how you convert 24-bit image data to 48-bit. The output is wider than the input, so you have to come up with the missing bits from somewhere. You might naively start by setting the lowest eight bits to zero in each of the three channels, but some sort of interpolation would likely give better results.

There might be some useful tips waiting to be mined from the source to gimp and graphicsmagick. (Indeed, they can probably already do such conversions before breakfast without blinking.)


I had a similar problem with 24bits RGB. I manually inserted an empty byte every 3bytes before copying the image to the GPU for processing, and then have that empty byte removed after the processing. This DRAMATICALLY improved the performance of the GPU processing, so definitely you have to do it.

The following two functions do the work (they are successfully tested).


/* .........................................................
*/
void copyInsertingPading3to4 (const unsigned char * source, 
                             unsigned char * destination,
                             unsigned int sourceSizeInBytes) 
{
  unsigned int j=0;
  for (unsigned int i=0; i<=sourceSizeInBytes-1; i++) 
    {
      destination[j] = source[i];
      if (i%3 == 2) {
        j++;
        destination[j] = 0;
      }
          j++;
    }
} // ()

/* ......................................................... */ void copyRemovingPading4to3 (const unsigned char * source, unsigned char * destination, unsigned int sourceSizeInbytes) { unsigned int j=0; for (unsigned int i=0; i<=sourceSizeInBytes-1; i++) { if ( (i%4) < 3 ) { destination[j] = source[i]; j++; } } } // ()

Note that when removing the padding the size of the source in bytes is greater than the original :-)


I'm not quite sure if it is able to handle 48bit tiffs, but you might want to have a look at imagemagick


Convert from a 24-bit image to a 48-bit one is rather straightforward. Because each channel in the 24-bit image is the MSB of the 48-bit image's corresponding channel, you only need to pad one zero byte between each other.

RGB → R0G0B0 for big endian and RGB → 0R0G0B for little endian

uint8_t  img24[PIXELCOUNT*3];
uint16_t img48[PIXELCOUNT*3];
unsigned int i;

for (i = 0; i < PIXELCOUNT*3; i++)
    img48[i] = img24[i];

or

uint8_t img24[PIXELCOUNT*3], img48[PIXELCOUNT*6];
unsigned int i;

for (i = 0; i < PIXELCOUNT*3; i++)
{
    img48[i*2] = 0;
    img48[i*2 + 1] = img24[i]; // reverse for big endian
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜