ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

tif_next.c
Go to the documentation of this file.
00001 /* $Id: tif_next.c,v 1.8.2.1 2010-06-08 18:50:42 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 NEXT_SUPPORT
00029 /*
00030  * TIFF Library.
00031  *
00032  * NeXT 2-bit Grey Scale Compression Algorithm Support
00033  */
00034 
00035 #define SETPIXEL(op, v) {           \
00036     switch (npixels++ & 3) {        \
00037     case 0: op[0]  = (unsigned char) ((v) << 6); break; \
00038     case 1: op[0] |= (v) << 4; break;   \
00039     case 2: op[0] |= (v) << 2; break;   \
00040     case 3: *op++ |= (v);      break;   \
00041     }                   \
00042 }
00043 
00044 #define LITERALROW  0x00
00045 #define LITERALSPAN 0x40
00046 #define WHITE       ((1<<2)-1)
00047 
00048 static int
00049 NeXTDecode(TIFF* tif, tidata_t buf, tsize_t occ, tsample_t s)
00050 {
00051     unsigned char *bp, *op;
00052     tsize_t cc;
00053     tidata_t row;
00054     tsize_t scanline, n;
00055 
00056     (void) s;
00057     /*
00058      * Each scanline is assumed to start off as all
00059      * white (we assume a PhotometricInterpretation
00060      * of ``min-is-black'').
00061      */
00062     for (op = buf, cc = occ; cc-- > 0;)
00063         *op++ = 0xff;
00064 
00065     bp = (unsigned char *)tif->tif_rawcp;
00066     cc = tif->tif_rawcc;
00067     scanline = tif->tif_scanlinesize;
00068     for (row = buf; occ > 0; occ -= scanline, row += scanline) {
00069         n = *bp++, cc--;
00070         switch (n) {
00071         case LITERALROW:
00072             /*
00073              * The entire scanline is given as literal values.
00074              */
00075             if (cc < scanline)
00076                 goto bad;
00077             _TIFFmemcpy(row, bp, scanline);
00078             bp += scanline;
00079             cc -= scanline;
00080             break;
00081         case LITERALSPAN: {
00082             tsize_t off;
00083             /*
00084              * The scanline has a literal span that begins at some
00085              * offset.
00086              */
00087             off = (bp[0] * 256) + bp[1];
00088             n = (bp[2] * 256) + bp[3];
00089             if (cc < 4+n || off+n > scanline)
00090                 goto bad;
00091             _TIFFmemcpy(row+off, bp+4, n);
00092             bp += 4+n;
00093             cc -= 4+n;
00094             break;
00095         }
00096         default: {
00097             uint32 npixels = 0, grey;
00098             uint32 imagewidth = tif->tif_dir.td_imagewidth;
00099 
00100             /*
00101              * The scanline is composed of a sequence of constant
00102              * color ``runs''.  We shift into ``run mode'' and
00103              * interpret bytes as codes of the form
00104              * <color><npixels> until we've filled the scanline.
00105              */
00106             op = row;
00107             for (;;) {
00108                 grey = (n>>6) & 0x3;
00109                 n &= 0x3f;
00110                 /*
00111                  * Ensure the run does not exceed the scanline
00112                  * bounds, potentially resulting in a security
00113                  * issue.
00114                  */
00115                 while (n-- > 0 && npixels < imagewidth)
00116                     SETPIXEL(op, grey);
00117                 if (npixels >= imagewidth)
00118                     break;
00119                 if (cc == 0)
00120                     goto bad;
00121                 n = *bp++, cc--;
00122             }
00123             break;
00124         }
00125         }
00126     }
00127     tif->tif_rawcp = (tidata_t) bp;
00128     tif->tif_rawcc = cc;
00129     return (1);
00130 bad:
00131     TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "NeXTDecode: Not enough data for scanline %ld",
00132         (long) tif->tif_row);
00133     return (0);
00134 }
00135 
00136 int
00137 TIFFInitNeXT(TIFF* tif, int scheme)
00138 {
00139     (void) scheme;
00140     tif->tif_decoderow = NeXTDecode;
00141     tif->tif_decodestrip = NeXTDecode;
00142     tif->tif_decodetile = NeXTDecode;
00143     return (1);
00144 }
00145 #endif /* NEXT_SUPPORT */
00146 
00147 /* vim: set ts=8 sts=8 sw=8 noet: */
00148 /*
00149  * Local Variables:
00150  * mode: c
00151  * c-basic-offset: 8
00152  * fill-column: 78
00153  * End:
00154  */

Generated on Wed May 23 2012 04:17:42 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.