象它的名称表述的那样,这是条纹图像的特例。在这种情况中,所有位图都存储在一个大的块中。 我在 Windows 机器上体验过单条图像的可靠性问题。通常建议一个未压缩的条不要占据 8 K 字节以上, 黑白图像限制为单条中最多为 65536 个像素。条纹(或多条)图像
图像的水平块存储在一起。多个条垂直地连接以形成完整的位图。 演示了这个概念。图 2. 悉尼港大桥的条纹图像平铺图像
象盥洗室墙壁那样,它是由瓷砖组成的。 演示了这种表示法, 它可用于非常大的图像。当您想在任何时候只操纵图像的一小部分时,平铺特别有用。图 3. 悉尼港大桥的平铺图像平铺图像不太常见,所以在本文中我将集中讨论条纹图像。请记住,单条图像只是多条图像的子集。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <stdio.h> #include <tiffio.h> int main(int argc, char *argv[]){ TIFF *image; uint16 photo, bps, spp, fillorder; uint32 width; tsize_t stripSize; unsigned long imageOffset, result; int stripMax, stripCount; char *buffer, tempbyte; unsigned long bufferSize, count; // Open the TIFF image if((image = TIFFOpen(argv[1], "r")) == NULL){ fprintf(stderr, "Could not open incoming image\n"); exit(42); } // Check that it is of a type that we support if((TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps) == 0) || (bps != 1)){ fprintf(stderr, "Either undefined or unsupported number of bits per sample\n"); exit(42); } if((TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp) == 0) || (spp != 1)){ fprintf(stderr, "Either undefined or unsupported number of samples per pixel\n"); exit(42); } // Read in the possibly multiple strips stripSize = TIFFStripSize (image); stripMax = TIFFNumberOfStrips (image); imageOffset = 0; bufferSize = TIFFNumberOfStrips (image) * stripSize; if((buffer = (char *) malloc(bufferSize)) == NULL){ fprintf(stderr, "Could not allocate enough memory for the uncompressed image\n"); exit(42); } for (stripCount = 0; stripCount < stripMax; stripCount++){ if((result = TIFFReadEncodedStrip (image, stripCount, buffer + imageOffset, stripSize)) == -1){ fprintf(stderr, "Read error on input strip number %d\n", stripCount); exit(42); } imageOffset += result; } // Deal with photometric interpretations if(TIFFGetField(image, TIFFTAG_PHOTOMETRIC, &photo) == 0){ fprintf(stderr, "Image has an undefined photometric interpretation\n"); exit(42); } if(photo != PHOTOMETRIC_MINISWHITE){ // Flip bits printf("Fixing the photometric interpretation\n"); for(count = 0; count < bufferSize; count++) buffer[count] = ~buffer[count]; } // Deal with fillorder if(TIFFGetField(image, TIFFTAG_FILLORDER, &fillorder) == 0){ fprintf(stderr, "Image has an undefined fillorder\n"); exit(42); } if(fillorder != FILLORDER_MSB2LSB){ // We need to swap bits -- ABCDEFGH becomes HGFEDCBA printf("Fixing the fillorder\n"); for(count = 0; count < bufferSize; count++){ tempbyte = 0; if(buffer[count] & 128) tempbyte += 1; if(buffer[count] & 64) tempbyte += 2; if(buffer[count] & 32) tempbyte += 4; if(buffer[count] & 16) tempbyte += 8; if(buffer[count] & 8) tempbyte += 16; if(buffer[count] & 4) tempbyte += 32; if(buffer[count] & 2) tempbyte += 64; if(buffer[count] & 1) tempbyte += 128; buffer[count] = tempbyte; } } // Do whatever it is we do with the buffer -- we dump it in hex if(TIFFGetField(image, TIFFTAG_IMAGEWIDTH, &width) == 0){ fprintf(stderr, "Image does not define its width\n"); exit(42); } for(count = 0; count < bufferSize; count++){ printf("%02x", (unsigned char) buffer[count]); if((count + 1) % (width / 8) == 0) printf("\n"); else printf(" "); } TIFFClose(image); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |