Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentif_thunder.c
Go to the documentation of this file.
00001 /* $Id: tif_thunder.c,v 1.5.2.1 2010-06-08 18:50:43 bfriesen Exp $ */ 00002 00003 /* 00004 * Copyright (c) 1988-1997 Sam Leffler 00005 * Copyright (c) 1991-1997 Silicon Graphics, Inc. 00006 * 00007 * Permission to use, copy, modify, distribute, and sell this software and 00008 * its documentation for any purpose is hereby granted without fee, provided 00009 * that (i) the above copyright notices and this permission notice appear in 00010 * all copies of the software and related documentation, and (ii) the names of 00011 * Sam Leffler and Silicon Graphics may not be used in any advertising or 00012 * publicity relating to the software without the specific, prior written 00013 * permission of Sam Leffler and Silicon Graphics. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 00016 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 00017 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 00018 * 00019 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR 00020 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 00021 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 00022 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 00023 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 00024 * OF THIS SOFTWARE. 00025 */ 00026 00027 #include "tiffiop.h" 00028 #ifdef THUNDER_SUPPORT 00029 /* 00030 * TIFF Library. 00031 * 00032 * ThunderScan 4-bit Compression Algorithm Support 00033 */ 00034 00035 /* 00036 * ThunderScan uses an encoding scheme designed for 00037 * 4-bit pixel values. Data is encoded in bytes, with 00038 * each byte split into a 2-bit code word and a 6-bit 00039 * data value. The encoding gives raw data, runs of 00040 * pixels, or pixel values encoded as a delta from the 00041 * previous pixel value. For the latter, either 2-bit 00042 * or 3-bit delta values are used, with the deltas packed 00043 * into a single byte. 00044 */ 00045 #define THUNDER_DATA 0x3f /* mask for 6-bit data */ 00046 #define THUNDER_CODE 0xc0 /* mask for 2-bit code word */ 00047 /* code values */ 00048 #define THUNDER_RUN 0x00 /* run of pixels w/ encoded count */ 00049 #define THUNDER_2BITDELTAS 0x40 /* 3 pixels w/ encoded 2-bit deltas */ 00050 #define DELTA2_SKIP 2 /* skip code for 2-bit deltas */ 00051 #define THUNDER_3BITDELTAS 0x80 /* 2 pixels w/ encoded 3-bit deltas */ 00052 #define DELTA3_SKIP 4 /* skip code for 3-bit deltas */ 00053 #define THUNDER_RAW 0xc0 /* raw data encoded */ 00054 00055 static const int twobitdeltas[4] = { 0, 1, 0, -1 }; 00056 static const int threebitdeltas[8] = { 0, 1, 2, 3, 0, -3, -2, -1 }; 00057 00058 #define SETPIXEL(op, v) { \ 00059 lastpixel = (v) & 0xf; \ 00060 if (npixels++ & 1) \ 00061 *op++ |= lastpixel; \ 00062 else \ 00063 op[0] = (tidataval_t) (lastpixel << 4); \ 00064 } 00065 00066 static int 00067 ThunderDecode(TIFF* tif, tidata_t op, tsize_t maxpixels) 00068 { 00069 register unsigned char *bp; 00070 register tsize_t cc; 00071 unsigned int lastpixel; 00072 tsize_t npixels; 00073 00074 bp = (unsigned char *)tif->tif_rawcp; 00075 cc = tif->tif_rawcc; 00076 lastpixel = 0; 00077 npixels = 0; 00078 while (cc > 0 && npixels < maxpixels) { 00079 int n, delta; 00080 00081 n = *bp++, cc--; 00082 switch (n & THUNDER_CODE) { 00083 case THUNDER_RUN: /* pixel run */ 00084 /* 00085 * Replicate the last pixel n times, 00086 * where n is the lower-order 6 bits. 00087 */ 00088 if (npixels & 1) { 00089 op[0] |= lastpixel; 00090 lastpixel = *op++; npixels++; n--; 00091 } else 00092 lastpixel |= lastpixel << 4; 00093 npixels += n; 00094 if (npixels < maxpixels) { 00095 for (; n > 0; n -= 2) 00096 *op++ = (tidataval_t) lastpixel; 00097 } 00098 if (n == -1) 00099 *--op &= 0xf0; 00100 lastpixel &= 0xf; 00101 break; 00102 case THUNDER_2BITDELTAS: /* 2-bit deltas */ 00103 if ((delta = ((n >> 4) & 3)) != DELTA2_SKIP) 00104 SETPIXEL(op, lastpixel + twobitdeltas[delta]); 00105 if ((delta = ((n >> 2) & 3)) != DELTA2_SKIP) 00106 SETPIXEL(op, lastpixel + twobitdeltas[delta]); 00107 if ((delta = (n & 3)) != DELTA2_SKIP) 00108 SETPIXEL(op, lastpixel + twobitdeltas[delta]); 00109 break; 00110 case THUNDER_3BITDELTAS: /* 3-bit deltas */ 00111 if ((delta = ((n >> 3) & 7)) != DELTA3_SKIP) 00112 SETPIXEL(op, lastpixel + threebitdeltas[delta]); 00113 if ((delta = (n & 7)) != DELTA3_SKIP) 00114 SETPIXEL(op, lastpixel + threebitdeltas[delta]); 00115 break; 00116 case THUNDER_RAW: /* raw data */ 00117 SETPIXEL(op, n); 00118 break; 00119 } 00120 } 00121 tif->tif_rawcp = (tidata_t) bp; 00122 tif->tif_rawcc = cc; 00123 if (npixels != maxpixels) { 00124 TIFFErrorExt(tif->tif_clientdata, tif->tif_name, 00125 "ThunderDecode: %s data at scanline %ld (%lu != %lu)", 00126 npixels < maxpixels ? "Not enough" : "Too much", 00127 (long) tif->tif_row, (long) npixels, (long) maxpixels); 00128 return (0); 00129 } 00130 return (1); 00131 } 00132 00133 static int 00134 ThunderDecodeRow(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s) 00135 { 00136 tidata_t row = buf; 00137 00138 (void) s; 00139 while ((long)occ > 0) { 00140 if (!ThunderDecode(tif, row, tif->tif_dir.td_imagewidth)) 00141 return (0); 00142 occ -= tif->tif_scanlinesize; 00143 row += tif->tif_scanlinesize; 00144 } 00145 return (1); 00146 } 00147 00148 int 00149 TIFFInitThunderScan(TIFF* tif, int scheme) 00150 { 00151 (void) scheme; 00152 tif->tif_decoderow = ThunderDecodeRow; 00153 tif->tif_decodestrip = ThunderDecodeRow; 00154 return (1); 00155 } 00156 #endif /* THUNDER_SUPPORT */ 00157 00158 /* vim: set ts=8 sts=8 sw=8 noet: */ 00159 /* 00160 * Local Variables: 00161 * mode: c 00162 * c-basic-offset: 8 00163 * fill-column: 78 00164 * End: 00165 */ Generated on Mon May 28 2012 04:19:24 for ReactOS by
1.7.6.1
|