diff VSs_tinyjpeg/tinyjpeg-internal.h @ 0:a8af8b3fc99d

initial commit
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Thu, 05 Jul 2012 11:35:03 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/VSs_tinyjpeg/tinyjpeg-internal.h	Thu Jul 05 11:35:03 2012 +0200
     1.3 @@ -0,0 +1,159 @@
     1.4 +/*
     1.5 + * Small jpeg decoder library (Internal header)
     1.6 + *
     1.7 + * Copyright (c) 2006, Luc Saillard <luc@saillard.org>
     1.8 + * All rights reserved.
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions are met:
    1.11 + * 
    1.12 + * - Redistributions of source code must retain the above copyright notice,
    1.13 + *  this list of conditions and the following disclaimer.
    1.14 + *
    1.15 + * - Redistributions in binary form must reproduce the above copyright notice,
    1.16 + *  this list of conditions and the following disclaimer in the documentation
    1.17 + *  and/or other materials provided with the distribution.
    1.18 + *
    1.19 + * - Neither the name of the author nor the names of its contributors may be
    1.20 + *  used to endorse or promote products derived from this software without
    1.21 + *  specific prior written permission.
    1.22 + * 
    1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.24 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.25 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.26 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    1.27 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.28 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.29 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.30 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.31 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.32 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.33 + * POSSIBILITY OF SUCH DAMAGE.
    1.34 + *
    1.35 + */
    1.36 +
    1.37 +#ifndef __TINYJPEG_INTERNAL_H_
    1.38 +#define __TINYJPEG_INTERNAL_H_
    1.39 +
    1.40 +#define SANITY_CHECK 1
    1.41 +
    1.42 +struct jdec_private;
    1.43 +
    1.44 +#define HUFFMAN_BITS_SIZE  256
    1.45 +#define HUFFMAN_HASH_NBITS 9
    1.46 +#define HUFFMAN_HASH_SIZE  (1UL<<HUFFMAN_HASH_NBITS)
    1.47 +#define HUFFMAN_HASH_MASK  (HUFFMAN_HASH_SIZE-1)
    1.48 +
    1.49 +#define HUFFMAN_TABLES	   4
    1.50 +#define COMPONENTS	   3
    1.51 +
    1.52 +#define cY  0
    1.53 +#define cCb 1
    1.54 +#define cCr 2
    1.55 +
    1.56 +#define BLACK_Y 0
    1.57 +#define BLACK_U 127
    1.58 +#define BLACK_V 127
    1.59 +
    1.60 +#if DEBUG
    1.61 +#define trace(fmt, args...) do { \
    1.62 +   fprintf(stderr, fmt, ## args); \
    1.63 +   fflush(stderr); \
    1.64 +} while(0)
    1.65 +#else
    1.66 +#define trace(fmt, args...) do { } while (0)
    1.67 +#endif
    1.68 +#define error(fmt, args...) do { \
    1.69 +   snprintf(error_string, sizeof(error_string), fmt, ## args); \
    1.70 +   return -1; \
    1.71 +} while(0)
    1.72 +
    1.73 +#define be16_to_cpu(x) (((x)[0]<<8)|(x)[1])
    1.74 +
    1.75 +enum std_markers {
    1.76 +   DQT  = 0xDB, /* Define Quantization Table */
    1.77 +   SOF  = 0xC0, /* Start of Frame (size information) */
    1.78 +   DHT  = 0xC4, /* Huffman Table */
    1.79 +   SOI  = 0xD8, /* Start of Image */
    1.80 +   SOS  = 0xDA, /* Start of Scan */
    1.81 +   RST  = 0xD0, /* Reset Marker d0 -> .. */
    1.82 +   RST7 = 0xD7, /* Reset Marker .. -> d7 */
    1.83 +   EOI  = 0xD9, /* End of Image */
    1.84 +   DRI  = 0xDD, /* Define Restart Interval */
    1.85 +   APP0 = 0xE0,
    1.86 +};
    1.87 +
    1.88 +struct huffman_table
    1.89 +{
    1.90 +  /* Fast look up table, using HUFFMAN_HASH_NBITS bits we can have directly the symbol,
    1.91 +   * if the symbol is <0, then we need to look into the tree table */
    1.92 +  short int lookup[HUFFMAN_HASH_SIZE];
    1.93 +  /* code size: give the number of bits of a symbol is encoded */
    1.94 +  unsigned char code_size[HUFFMAN_HASH_SIZE];
    1.95 +  /* some place to store value that is not encoded in the lookup table */
    1.96 +  uint16_t slowtable[16-HUFFMAN_HASH_NBITS][256];
    1.97 +};
    1.98 +
    1.99 +struct component 
   1.100 +{
   1.101 +  unsigned int Hfactor;
   1.102 +  unsigned int Vfactor;
   1.103 +  float *Q_table;		/* Pointer to the quantisation table to use */
   1.104 +  struct huffman_table *AC_table;
   1.105 +  struct huffman_table *DC_table;
   1.106 +  short int previous_DC;	/* Previous DC coefficient */
   1.107 +  short int DCT[64];		/* DCT coef */
   1.108 +#if SANITY_CHECK
   1.109 +  unsigned int cid;
   1.110 +#endif
   1.111 +};
   1.112 +
   1.113 +typedef int (*decode_MCU_fct) (struct jdec_private *priv);
   1.114 +typedef void (*convert_colorspace_fct) (struct jdec_private *priv);
   1.115 +
   1.116 +struct jdec_private
   1.117 +{
   1.118 +  /* Public variables */
   1.119 +  uint8_t *components[COMPONENTS];
   1.120 +  unsigned int width, height;	/* Size of the image */
   1.121 +  unsigned int mcus_in_width, mcus_in_height;
   1.122 +	unsigned int mcus_posx, mcus_posy;
   1.123 +  unsigned int flags;
   1.124 +
   1.125 +  /* Private variables */
   1.126 +  const unsigned char *stream_begin, *stream_end;
   1.127 +  unsigned int stream_length;
   1.128 +
   1.129 +  const unsigned char *stream;	/* Pointer to the current stream */
   1.130 +  unsigned int reservoir, nbits_in_reservoir;
   1.131 +
   1.132 +  struct component component_infos[COMPONENTS];
   1.133 +  float Q_tables[COMPONENTS][64];		/* quantization tables */
   1.134 +  struct huffman_table HTDC[HUFFMAN_TABLES];	/* DC huffman tables   */
   1.135 +  struct huffman_table HTAC[HUFFMAN_TABLES];	/* AC huffman tables   */
   1.136 +  int default_huffman_table_initialized;
   1.137 +  unsigned int restart_interval;
   1.138 +//   int restarts_to_go;			/* MCUs left in this restart interval */
   1.139 +  int last_rst_marker_seen;			/* Rst marker is incremented each time */
   1.140 +
   1.141 +  /* Temp space used after the IDCT to store each components */
   1.142 +  uint8_t Y[64*4], Cr[64], Cb[64];
   1.143 +
   1.144 +  /* Internal Pointer use for colorspace conversion, do not modify it !!! */
   1.145 +  uint8_t *plane;
   1.146 +
   1.147 +};
   1.148 +
   1.149 +#if defined(__GNUC__) && (__GNUC__ > 3) && defined(__OPTIMIZE__)
   1.150 +#define __likely(x)       __builtin_expect(!!(x), 1)
   1.151 +#define __unlikely(x)     __builtin_expect(!!(x), 0)
   1.152 +#else
   1.153 +#define __likely(x)       (x)
   1.154 +#define __unlikely(x)     (x)
   1.155 +#endif
   1.156 +
   1.157 +#define IDCT tinyjpeg_idct_float
   1.158 +void tinyjpeg_idct_float (struct component *compptr, uint8_t *output_buf, int stride);
   1.159 +int parse_JFIF(struct jdec_private *priv, const unsigned char *stream);
   1.160 +
   1.161 +#endif
   1.162 +