~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/codec/jpeg/mix.cc

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * mix.cc --
  3  *
  4  *      FIXME: This file needs a description here.
  5  *
  6  * Copyright (c) 1996-2002 The Regents of the University of California.
  7  * All rights reserved.
  8  *
  9  * Redistribution and use in source and binary forms, with or without
 10  * modification, are permitted provided that the following conditions are met:
 11  *
 12  * A. Redistributions of source code must retain the above copyright notice,
 13  *    this list of conditions and the following disclaimer.
 14  * B. Redistributions in binary form must reproduce the above copyright notice,
 15  *    this list of conditions and the following disclaimer in the documentation
 16  *    and/or other materials provided with the distribution.
 17  * C. Neither the names of the copyright holders nor the names of its
 18  *    contributors may be used to endorse or promote products derived from this
 19  *    software without specific prior written permission.
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  */
 33 
 34 /*
 35  * This routine mixes the DC & AC components of an 8x8 block of
 36  * pixels.  This routine is called for every block decoded so it
 37  * needs to be efficient.  It tries to do as many pixels in parallel
 38  * as will fit in a word.  The one complication is that it has to
 39  * deal with overflow (sum > 255) and underflow (sum < 0).  Underflow
 40  * & overflow are only possible if both terms have the same sign and
 41  * are indicated by the result having a different sign than the terms.
 42  * Note that underflow is more worrisome than overflow since it results
 43  * in bright white dots in a black field.
 44  * The DC term and sum are biased by 128 so a negative number has the
 45  * 2^7 bit = 0.  The AC term is not biased so a negative number has
 46  * the 2^7 bit = 1.  So underflow is indicated by (DC & AC & sum) != 0;
 47  */
 48 #define JPEG_MIX_LOGIC \
 49         sum = dc + ac; \
 50         uflo = (dc ^ ac) & (dc ^ sum) & omask; \
 51         if (uflo) { \
 52                 if ((ac = uflo & dc) != 0) { \
 53                         /* integer overflows */ \
 54                         ac |= ac >> 1; \
 55                         ac |= ac >> 2; \
 56                         ac |= ac >> 4; \
 57                         sum |= ac; \
 58                 } \
 59                 if ((uflo &=~ ac) != 0) { \
 60                         /* integer underflow(s) */ \
 61                         uflo |= uflo >> 1; \
 62                         uflo |= uflo >> 2; \
 63                         uflo |= uflo >> 4; \
 64                         sum &= ~uflo; \
 65                 } \
 66         }
 67 
 68 #ifdef INT_64
 69 #define JPEG_MIX8(bp, out) \
 70         ac = *(INT_64*)(bp); \
 71         JPEG_MIX_LOGIC \
 72         *(INT_64*)(out) = sum; \
 73         (bp) += 8; \
 74         (out) += stride;
 75 #else
 76 #define JPEG_MIX4(bp, out) \
 77         ac = *(u_word*)(bp); \
 78         JPEG_MIX_LOGIC \
 79         *(u_word*)(out) = sum;
 80 
 81 #define JPEG_MIX8(bp, out) \
 82         JPEG_MIX4(bp, out) \
 83         JPEG_MIX4(bp + 4, out + 4) \
 84         bp += 8; \
 85         out += stride;
 86 #endif
 87 
 88 
 89 void JpegDecoder::mix(u_int idc, const u_char* bp, u_char* out, int stride) const
 90 {
 91         register int t;
 92 
 93         idc = UCLIMIT(idc) & 0xff;
 94         idc |= idc << 8;
 95         idc |= idc << 16;
 96 #ifdef INT_64
 97         INT_64 dc = idc, ac, sum;
 98         dc |= dc << 32;
 99         INT_64 uflo, omask = 0x8080808080808080;
100 #else
101         u_word dc = idc, ac, sum;
102         u_word uflo, omask = 0x80808080;
103 #endif
104 
105         JPEG_MIX8(bp, out)
106         JPEG_MIX8(bp, out)
107         JPEG_MIX8(bp, out)
108         JPEG_MIX8(bp, out)
109         JPEG_MIX8(bp, out)
110         JPEG_MIX8(bp, out)
111         JPEG_MIX8(bp, out)
112         JPEG_MIX8(bp, out)
113 }
114 
115 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.