"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/fastjpgmacro.h" (9 Jan 2007, 6161 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #ifndef FASTJPGMACRO_H
    2 #define FASTJPGMACRO_H
    3 
    4 
    5 #define QUICKTIME_FASTJPG_HANDLE_RST(rst_int, rst_cnt) \
    6 { \
    7     if(((rst_int) && (rst_cnt == 0))) \
    8     { \
    9         jpeg_info->jpg_h_bbuf = 0; \
   10         jpeg_info->jpg_h_bnum = 0; \
   11         if(jpeg_info->marker == 0) jpeg_info->marker = quicktime_fastjpg_check_for_marker(jpeg_info); \
   12         if(jpeg_info->marker) \
   13         { \
   14             if(jpeg_info->marker == M_EOI) \
   15             { \
   16                 jpeg_info->jpg_saw_EOI = 1; \
   17                 return 1; \
   18             } \
   19             else \
   20             if(jpeg_info->marker == M_SOS) quicktime_fastjpg_readSOS(jpeg_info); \
   21             else \
   22             if(!((jpeg_info->marker >= M_RST0) && (jpeg_info->marker <= M_RST7))) \
   23             { \
   24                 printf("QUICKTIME_FASTJPG_HANDLE_RST: unexp marker(%x)\n", jpeg_info->marker); \
   25                 /*return(0);*/ \
   26             } \
   27             jpeg_info->marker = 0; \
   28         } \
   29         jpeg_info->jpg_comps[0].dc = jpeg_info->jpg_comps[1].dc = jpeg_info->jpg_comps[2].dc = 0; \
   30         rst_cnt = rst_int; \
   31     } \
   32     else \
   33         rst_cnt--; \
   34 }
   35 
   36 #define QUICKTIME_FASTJPG_TEST_MARKER \
   37 while(jpeg_info->marker) \
   38 { \
   39     if(jpeg_info->marker == M_EOI) \
   40     { \
   41         jpeg_info->jpg_saw_EOI = 1; \
   42         jpeg_info->marker = 0; \
   43     } \
   44     else \
   45     if(jpeg_info->marker == M_SOS) \
   46     { \
   47         quicktime_fastjpg_readSOS(jpeg_info); \
   48         jpeg_info->marker = 0; \
   49     } \
   50     else \
   51     if((jpeg_info->marker >= M_RST0) && (jpeg_info->marker <= M_RST7)) \
   52     { \
   53         jpeg_info->jpg_comps[0].dc = jpeg_info->jpg_comps[1].dc = jpeg_info->jpg_comps[2].dc = 0; \
   54         rst_skip = rst_count; \
   55         rst_count = jpeg_info->jpg_rst_interval; \
   56         jpeg_info->marker = 0; \
   57         jpeg_info->jpg_h_bbuf = 0; \
   58         jpeg_info->jpg_h_bnum = 0; \
   59     } \
   60     else /* Unknown or unexpected Marker */ \
   61     { \
   62         printf("QUICKTIME_FASTJPG_TEST_MARKER: unexp marker(%x)\n", jpeg_info->marker); \
   63         jpeg_info->marker = quicktime_fastjpg_skip_to_next_rst(jpeg_info); /* hopefully a RST marker */ \
   64     } \
   65 }
   66 
   67 #define QUICKTIME_FASTJPG_HBBUF_FILL8_1(hbbuf, hbnum) \
   68 { \
   69     (hbbuf) <<= 8; \
   70     (hbnum) += 8; \
   71 \
   72     if(jpeg_info->marker) tmp__ = 0x00; \
   73     else \
   74     { \
   75         tmp__ = *(jpeg_info->chunk++); \
   76         jpeg_info->chunk_size--; \
   77     } \
   78 \
   79     while(tmp__ == 0xff) \
   80     { \
   81         t1_ = *(jpeg_info->chunk++); \
   82         jpeg_info->chunk_size--; \
   83         if(t1_ == 0x00) break; \
   84         else if(t1_ == 0xff) continue; \
   85         else \
   86         { \
   87             jpeg_info->marker = t1_; \
   88             tmp__ = 0x00; \
   89             break; \
   90         } \
   91     } \
   92     hbbuf |= tmp__; \
   93 }
   94 
   95 #define QUICKTIME_FASTJPG_HUFF_DECODE(huff_hdr, htbl, hbnum, hbbuf, result) \
   96 { \
   97     while(hbnum < 16) { QUICKTIME_FASTJPG_HBBUF_FILL8_1(hbbuf, hbnum); } \
   98     tmp_ = (hbbuf >> (hbnum - 8)) & 0xff; \
   99     hcode_ = (htbl)[tmp_]; \
  100     if(hcode_) \
  101     { \
  102         hbnum -= (hcode_ >> 8); \
  103         (result) = hcode_ & 0xff; \
  104     } \
  105     else \
  106     { \
  107         minbits_ = 9; \
  108         tmp_ = (hbbuf >> (hbnum - 16)) & 0xffff; /* get 16 bits */  \
  109         shift_ = 16 - minbits_; \
  110         hcode_ = tmp_ >> shift_; \
  111 \
  112         while(hcode_ > huff_hdr->maxcode[minbits_]) \
  113         { \
  114             minbits_++; \
  115             shift_--; \
  116             hcode_ = tmp_ >> shift_; \
  117         } \
  118 \
  119         if(minbits_ > 16) \
  120         { \
  121             printf("QUICKTIME_FASTJPG_HUFF_DECODE error\n"); \
  122             return 1; \
  123         } \
  124         else  \
  125         { \
  126             hbnum -= minbits_; \
  127             hcode_ -= huff_hdr->mincode[minbits_]; \
  128             result = huff_hdr->vals[(huff_hdr->valptr[minbits_] + hcode_)]; \
  129         } \
  130     } \
  131 }
  132 
  133 
  134 #define QUICKTIME_FASTJPG_HUFF_MASK(s) ((1 << (s)) - 1)
  135 
  136 #define QUICKTIME_FASTJPG_GET_BITS(n, hbnum, hbbuf, result) \
  137 { \
  138     hbnum -= n; \
  139     while(hbnum < 0) \
  140     { \
  141         QUICKTIME_FASTJPG_HBBUF_FILL8_1(hbbuf, hbnum); \
  142     } \
  143     (result) = ((hbbuf >> hbnum) & QUICKTIME_FASTJPG_HUFF_MASK(n)); \
  144 }
  145 
  146 #define QUICKTIME_FASTJPG_HUFF_EXTEND(val, sz) \
  147     ((val) < (1 << ((sz) - 1)) ? (val) + (((-1) << (sz)) + 1) : (val))
  148 
  149 #define QUICKTIME_MCU_ARGS \
  150     quicktime_jpeg_t *jpeg_info,  \
  151     unsigned char **row_pointers, \
  152     long frame_width, \
  153     long frame_height, \
  154     unsigned long mcu_row_size, \
  155     unsigned long ip_size, \
  156     quicktime_mjpa_buffs *yuvbufs, \
  157     int interlaced
  158     
  159 
  160 #define QUICKTIME_MCU_VARS \
  161     unsigned long yi; \
  162     unsigned char *yptr, *uptr, *vptr; \
  163     long *YTab = jpeg_info->yuvtabs.YUV_Y_tab; \
  164     long *UBTab = jpeg_info->yuvtabs.YUV_UB_tab; \
  165     long *VRTab = jpeg_info->yuvtabs.YUV_VR_tab; \
  166     long *UGTab = jpeg_info->yuvtabs.YUV_UG_tab; \
  167     long *VGTab = jpeg_info->yuvtabs.YUV_VG_tab; \
  168     unsigned char *ybuf = yuvbufs->ybuf; \
  169     unsigned char *ubuf = yuvbufs->ubuf; \
  170     unsigned char *vbuf = yuvbufs->vbuf;
  171 
  172 #define QUICKTIME_MCU111111_MID_VARS \
  173     unsigned char *ip; \
  174     unsigned char *yp, *up, *vp; \
  175     long xi, skip;
  176 
  177 #define QUICKTIME_MCU111111_MID_DECL \
  178     ip = *row_pointers; \
  179     yp = yptr; \
  180     up = uptr; \
  181     vp = vptr; \
  182     xi = frame_width; \
  183     skip = 0;
  184 
  185 #define QUICKTIME_MCU_INNER_VARS \
  186     unsigned long u0; \
  187     unsigned long v0; \
  188     long cr; \
  189     long cb; \
  190     long cg; \
  191     long y_long;
  192 
  193 
  194 #define QUICKTIME_MCU_INNER_INIT \
  195     u0 = (unsigned long)*up++; \
  196     v0 = (unsigned long)*vp++; \
  197     cr = VRTab[v0]; \
  198     cb = UBTab[u0]; \
  199     cg = UGTab[u0] + VGTab[v0];
  200 
  201 #define QUICKTIME_MCU4H_INNER_TAIL(inc1, inc2) \
  202     skip++; \
  203     if(skip >= 8) \
  204     { \
  205         skip = 0; \
  206         yp += inc2; \
  207         up += inc1; \
  208         vp += inc1; \
  209     } \
  210     else \
  211     if(!(skip & 1)) /* 2 4 6 */ \
  212         yp += inc1;
  213 
  214 #define QUICKTIME_MCU_LIMITRANGE(x) \
  215     (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x)));
  216 
  217 #define QUICKTIME_MCU_YUV_TO_RGB(y, cr, cg, cb, ip) \
  218     y_long = (long)y; \
  219     *ip++ = (unsigned char)QUICKTIME_MCU_LIMITRANGE((y_long + cr) >> 6); \
  220     *ip++ = (unsigned char)QUICKTIME_MCU_LIMITRANGE((y_long + cg) >> 6); \
  221     *ip++ = (unsigned char)QUICKTIME_MCU_LIMITRANGE((y_long + cb) >> 6);
  222 
  223 
  224 #define QUICKTIME_MCU221111_MID_VARS \
  225     unsigned char *ip0, *ip1; \
  226     unsigned char *yp, *up, *vp; \
  227     long xi, skip;
  228 
  229 
  230 #define QUICKTIME_MCU221111_MID_DECL \
  231     if(frame_height <= 0) return 0; \
  232     if(yi == 4) yptr += 64; \
  233     ip0 = *row_pointers; \
  234     row_pointers += interlaced ? 2 : 1; \
  235     ip1 = *row_pointers; \
  236     row_pointers += interlaced ? 2 : 1; \
  237     yp = yptr; \
  238     up = uptr; \
  239     vp = vptr; \
  240     xi = frame_width; \
  241     skip = 0;
  242 
  243 #define QUICKTIME_MCU2H_INNER_TAIL(inc1, inc2) \
  244     skip++; \
  245     if(skip == 4) yp += inc1; \
  246     else \
  247     if(skip >= 8) \
  248     { \
  249         skip = 0; \
  250         yp += inc2; \
  251         up += inc1; \
  252         vp += inc1; \
  253     }
  254 
  255 #define QUICKTIME_MCU1H_INNER_TAIL(inc) \
  256     skip++; \
  257     if(skip >= 8) \
  258     { \
  259         skip = 0; \
  260         yp += inc; \
  261         up += inc; \
  262         vp += inc; \
  263     }
  264 
  265 
  266 #endif