コード例 #1
0
ファイル: read.c プロジェクト: ohinds/VolumeProcessingLibrary
/*
 *--------------------------------------------------------------
 *
 * GetDri --
 *
 *        Process a DRI marker
 *
 * Results:
 *        None
 *
 * Side effects:
 *        Exits on error.
 *        Bitstream is parsed.
 *
 *--------------------------------------------------------------
 */
static void GetDri (DecompressInfo *dcPtr)
{
    if (Get2bytes () != 4) 
    {
        fprintf (stderr, "Bogus length in DRI\n");
        /* exit (1); */
        dcPtr->error = -1; return;
    }

    dcPtr->restartInterval = (Ushort) Get2bytes ();
}
コード例 #2
0
ファイル: read.c プロジェクト: ohinds/VolumeProcessingLibrary
/*
 *--------------------------------------------------------------
 *
 * GetSof --
 *
 *        Process a SOFn marker
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        Bitstream is parsed
 *        Exits on error
 *        dcPtr structure is filled in
 *
 *--------------------------------------------------------------
 */
static void GetSof (DecompressInfo *dcPtr, int code)
{
    int length;
    short ci;
    int c;
    JpegComponentInfo *compptr;
    
    code = code;

    length = Get2bytes ();

    dcPtr->dataPrecision = GetJpegChar();
    dcPtr->imageHeight = Get2bytes ();
    dcPtr->imageWidth = Get2bytes ();
    dcPtr->numComponents = GetJpegChar();

    /*
     * We don't support files in which the image height is initially
     * specified as 0 and is later redefined by DNL.  As long as we
     * have to check that, might as well have a general sanity check.
     */
    if ((dcPtr->imageHeight <= 0 ) ||
        (dcPtr->imageWidth <= 0) || 
        (dcPtr->numComponents <= 0)) {
        fprintf (stderr, "Empty JPEG image (DNL not supported)\n");
        /* exit(1); */
        dcPtr->error = -1; return;
    }

    if ((dcPtr->dataPrecision<MinPrecisionBits) ||
        (dcPtr->dataPrecision>MaxPrecisionBits)) {
        fprintf (stderr, "Unsupported JPEG data precision\n");
        /* exit(1); */
        dcPtr->error = -1; return;
    }

    if (length != (dcPtr->numComponents * 3 + 8)) {
        fprintf (stderr, "Bogus SOF length\n");
        /* exit (1); */
        dcPtr->error = -1; return;
    }

    for (ci = 0; ci < dcPtr->numComponents; ci++) {
        compptr = &dcPtr->compInfo[ci];
        compptr->componentIndex = ci;
        compptr->componentId = GetJpegChar();
        c = GetJpegChar();
        compptr->hSampFactor = (c >> 4) & 15;
        compptr->vSampFactor = (c) & 15;
        (void) GetJpegChar(); /* skip Tq */
    }
}/*endof GetSof */
コード例 #3
0
ファイル: read.c プロジェクト: ohinds/VolumeProcessingLibrary
/*
 *--------------------------------------------------------------
 *
 * GetDht --
 *
 *        Process a DHT marker
 *
 * Results:
 *        None
 *
 * Side effects:
 *        A huffman table is read.
 *        Exits on error.
 *
 *--------------------------------------------------------------
 */
static void GetDht (DecompressInfo *dcPtr)
{
    int length;
    Uchar bits[17];
    Uchar huffval[256];
    int i, index, count;
    HuffmanTable **htblptr=NULL;

    length = Get2bytes () - 2;

    while (length) {
        index = GetJpegChar();

        bits[0] = 0;
        count = 0;
        for (i = 1; i <= 16; i++) {
            bits[i] = GetJpegChar();
            count += bits[i];
        }

        if (count > 256) {
            fprintf (stderr, "Bogus DHT counts\n");
            /* exit (1); */
            dcPtr->error = -1; return;
        }

        for (i = 0; i < count; i++)
            huffval[i] = GetJpegChar();

        length -= 1 + 16 + count;

        if (index & 0x10) {        /* AC table definition */
           fprintf(stderr,"Huffman table for lossless JPEG is not defined.\n");
        } 
        else {                /* DC table definition */
            htblptr = &dcPtr->dcHuffTblPtrs[index];
        }

        if (index < 0 || index >= 4) 
        {
            fprintf (stderr, "Bogus DHT index %d\n", index);
            /* exit (1); */
            dcPtr->error = -1; return;
        }

        if (*htblptr == NULL) 
        {
            *htblptr = &HuffmanTableMemory[index];
             if (*htblptr==NULL) 
                         {
                fprintf(stderr,"Can't malloc HuffmanTable\n");
                /* exit(-1); */
                dcPtr->error = -1; return;
             }
        }

        MEMCPY((*htblptr)->bits, bits, sizeof ((*htblptr)->bits));
        MEMCPY((*htblptr)->huffval, huffval, sizeof ((*htblptr)->huffval));
    }
}
コード例 #4
0
ファイル: read.c プロジェクト: ohinds/VolumeProcessingLibrary
/*
 *--------------------------------------------------------------
 *
 * GetApp0 --
 *
 *        Process an APP0 marker.
 *
 * Results:
 *        None
 *
 * Side effects:
 *        Bitstream is parsed
 *
 *--------------------------------------------------------------
 */
static void GetApp0 (DecompressInfo *dcPtr)
{
    int length;

    length = Get2bytes () - 2;
    while (length-- > 0)        /* skip any remaining data */
        (void)GetJpegChar();
}
コード例 #5
0
ファイル: read.c プロジェクト: ohinds/VolumeProcessingLibrary
/*
 *--------------------------------------------------------------
 *
 * SkipVariable --
 *
 *        Skip over an unknown or uninteresting variable-length marker
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        Bitstream is parsed over marker.
 *
 *
 *--------------------------------------------------------------
 */
static void SkipVariable (DecompressInfo *dcPtr)
{
    int length;

    length = Get2bytes () - 2;

    while (length--) {
        GetJpegChar();
    }
}
コード例 #6
0
ファイル: read.c プロジェクト: ohinds/VolumeProcessingLibrary
/*
 *--------------------------------------------------------------
 *
 * GetSos --
 *
 *        Process a SOS marker
 *
 * Results:
 *        None.
 *
 * Side effects:
 *        Bitstream is parsed.
 *        Exits on error.
 *
 *--------------------------------------------------------------
 */
static void GetSos (DecompressInfo *dcPtr)
{
    int length;
    int i, ci, n, c, cc;
    JpegComponentInfo *compptr;

    length = Get2bytes ();

    /* 
     * Get the number of image components.
     */
    n = GetJpegChar();
    dcPtr->compsInScan = n;
    length -= 3;

    if (length != (n * 2 + 3) || n < 1 || n > 4) {
        fprintf (stderr, "Bogus SOS length\n");
        /* exit (1); */
        dcPtr->error = -1; return;
    }


    for (i = 0; i < n; i++) {
        cc = GetJpegChar();
        c = GetJpegChar();
        length -= 2;

        for (ci = 0; ci < dcPtr->numComponents; ci++)
            if (cc == dcPtr->compInfo[ci].componentId) {
                break;
            }

        if (ci >= dcPtr->numComponents) {
            fprintf (stderr, "Invalid component number in SOS\n");
            /* exit (1); */
            dcPtr->error = -1; return;
        }

        compptr = &dcPtr->compInfo[ci];
        dcPtr->curCompInfo[i] = compptr;
        compptr->dcTblNo = (c >> 4) & 15;
    }

    /*
     * Get the PSV, skip Se, and get the point transform parameter.
     */
    dcPtr->Ss = GetJpegChar(); 
    (void)GetJpegChar();
    c = GetJpegChar(); 
    dcPtr->Pt = c & 0x0F;
}/*endof GetSos */
コード例 #7
0
ファイル: xskin_loadBMP.c プロジェクト: 1c0n/xbmc
BMPHeader *loadBMPHeader( struct timidity_file *fp ) {

  static BMPHeader h;
  int i;

  /* file header */

  if ( (ugetc(fp) != 'B') || (ugetc(fp) != 'M') ) return NULL;
  h.size = Get4bytes( fp );    /* size */
  if ( h.size < 0 ) return NULL;
  i = Get2bytes( fp );         /* reserved 1 */
  i = Get2bytes( fp );         /* reserved 2 */
  h.offbits = Get4bytes( fp ); /* offbits */
  if ( h.offbits < 0 ) return NULL;


  /* information header */

  h.hsize = Get4bytes( fp );   /* header size */
  if ( h.hsize < 0 ) return NULL;

  if ( h.hsize == 40 ) {
    h.w = Get4bytes( fp );     /* width */
    h.h = Get4bytes( fp );     /* height */
  } else {
    h.w = Get2bytes( fp );     /* width */
    h.h = Get2bytes( fp );     /* height */
  }
  if ( h.h < 0 ) return NULL;

  i = Get2bytes( fp );         /* planes */
  if ( i != 1 ) return NULL;

  h.bitcounts = Get2bytes(fp); /* bit-counts */
  if ( h.bitcounts != 4 && h.bitcounts != 8 && h.bitcounts != 24 ) 
    return NULL;

  if ( h.hsize==40 || h.hsize==64 ) {
    i = Get4bytes( fp );       /* compress */
    h.compress = i;
    h.ncolors = ( h.offbits - h.hsize - 14 ) / 4;
                               /* colors */
  } else {
    h.ncolors = 0;
    h.compress=0;
  }

  return &h;
}