Beispiel #1
0
static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr,
                           const UINT8 *bits, const UINT8 *val)
/* Define a Huffman table */
{
    int nsymbols, len;

    if (*htblptr == NULL)
        *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo);

    /* Copy the number-of-symbols-of-each-code-length counts. */
    memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));

    /*
     * Validate the counts.  We do this here mainly so we can copy the right
     * number of symbols from the val[] array, without risking marching off
     * the end of memory.  jchuff.c will do a more thorough test later.
     */
    nsymbols = 0;

    for (len = 1; len <= 16; len++)
        nsymbols += bits[len];

    if (nsymbols < 1 || nsymbols > 256)
        MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small");

    memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));
}
ImageExtractorMJPG::ImageExtractorMJPG(const unsigned int sSize[2])
	:jpegErrorManager(0),jpegStruct(0),
	 imageRows(0)
	{
	/* Copy the frame size: */
	for(int i=0;i<2;++i)
		size[i]=sSize[i];
	
	/* Initialize the JPEG decompression objects: */
	jpegErrorManager=new jpeg_error_mgr;
	jpegStruct=new jpeg_decompress_struct;
	jpeg_create_decompress(jpegStruct);
	jpegStruct->err=jpeg_std_error(jpegErrorManager);
	
	/* Create the standard Motion JPEG Huffman tables: */
	for(int tableIndex=0;tableIndex<4;++tableIndex)
		{
		/* Allocate the table: */
		JHUFF_TBL* huffmanTable=jpeg_alloc_huff_table(reinterpret_cast<jpeg_common_struct*>(jpegStruct));
		if(tableIndex<2)
			jpegStruct->dc_huff_tbl_ptrs[tableIndex]=huffmanTable;
		else
			jpegStruct->ac_huff_tbl_ptrs[tableIndex-2]=huffmanTable;
		
		/* Copy Huffman bits and values: */
		int numValues=0;
		for(int i=1;i<=16;++i)
			numValues+=huffmanTable->bits[i]=huffmanBits[tableIndex][i];
		for(int i=0;i<numValues;++i)
			huffmanTable->huffval[i]=huffmanValues[tableIndex][i];
		}
	
	/* Allocate the image row array: */
	imageRows=new unsigned char*[size[1]];
	}
Beispiel #3
0
add_huff_table (j_compress_ptr cinfo,
		JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
/* Define a Huffman table */
{
  int nsymbols, len;

  if (*htblptr == NULL)
    *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);

  /* Copy the number-of-symbols-of-each-code-length counts */
  MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));

  /* Validate the counts.  We do this here mainly so we can copy the right
   * number of symbols from the val[] array, without risking marching off
   * the end of memory.  jchuff.c will do a more thorough test later.
   */
  nsymbols = 0;
  for (len = 1; len <= 16; len++)
    nsymbols += bits[len];
  if (nsymbols < 1 || nsymbols > 256)
    ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);

  MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));

  /* Initialize sent_table FALSE so table will be written to JPEG file. */
  (*htblptr)->sent_table = FALSE;
}
Beispiel #4
0
LOCAL void

add_huff_table (j_compress_ptr cinfo,

		JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)

/* Define a Huffman table */

{

  if (*htblptr == NULL)

    *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);

  

  MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));

  MEMCOPY((*htblptr)->huffval, val, SIZEOF((*htblptr)->huffval));



  /* Initialize sent_table FALSE so table will be written to JPEG file. */

  (*htblptr)->sent_table = FALSE;

}
Beispiel #5
0
static void add_huff_table (j_decompress_ptr dinfo,
                            JHUFF_TBL **htblptr,
                            const UINT8 *bits, const UINT8 *val)
/* Define a Huffman table */
{
    int nsymbols, len;

    if (*htblptr == NULL)
        *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo);

    /* Copy the number-of-symbols-of-each-code-length counts */
    memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));

    /* Validate the counts.  We do this here mainly so we can copy the right
     * number of symbols from the val[] array, without risking marching off
     * the end of memory.  jchuff.c will do a more thorough test later.
     */
    nsymbols = 0;
    for (len = 1; len <= 16; len++)
        nsymbols += bits[len];
    if (nsymbols < 1 || nsymbols > 256)
        //    mjpeg_error_exit1("jpegutils.c:  add_huff_table failed badly. ");
        //lqt_log(NULL, LQT_LOG_ERROR, LOG_DOMAIN, "add_huff_table failed badly.\n");
        if (DEBUG)fprintf(stderr,"add_huff_table failed badly.\n");
    memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));
}
Beispiel #6
0
static void add_huff_table(j_decompress_ptr dinfo,
			   JHUFF_TBL ** htblptr,
			   const UINT8 * bits, const UINT8 * val)
/* Define a Huffman table */
{
    int nsymbols, len;

    if (*htblptr == NULL)
	*htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo);

    /* Copy the number-of-symbols-of-each-code-length counts */
    memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));

    /* Validate the counts.  We do this here mainly so we can copy the right
     * number of symbols from the val[] array, without risking marching off
     * the end of memory.  jchuff.c will do a more thorough test later.
     */
    nsymbols = 0;
    for (len = 1; len <= 16; len++)
	nsymbols += bits[len];
    if (nsymbols < 1 || nsymbols > 256)
    {
      veejay_msg(0, "(jpegutils) HUFFMAN table failed badly");
      return;
    }

    memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));
}
/*
 * Parse the DHT table.
 * This code comes from jpeg6b (jdmarker.c).
 */
static
int my_jpeg_load_dht (struct jpeg_decompress_struct *info, unsigned char *dht,
              JHUFF_TBL *ac_tables[], JHUFF_TBL *dc_tables[])
{
    unsigned int length = (dht[2] << 8) + dht[3] - 2;
    unsigned int pos = 4;
    unsigned int count, i;
    int index;

    JHUFF_TBL **hufftbl;
    unsigned char bits[17];
    unsigned char huffval[256];

    while (length > 16)
    {
       bits[0] = 0;
       index = dht[pos++];
       count = 0;
       for (i = 1; i <= 16; ++i)
       {
           bits[i] = dht[pos++];
           count += bits[i];
       }
       length -= 17;

       if (count > 256 || count > length)
           return -1;

       for (i = 0; i < count; ++i)
           huffval[i] = dht[pos++];
       length -= count;

       if (index & 0x10)
       {
           index -= 0x10;
           hufftbl = &ac_tables[index];
       }
       else
           hufftbl = &dc_tables[index];

       if (index < 0 || index >= NUM_HUFF_TBLS)
           return -1;

       if (*hufftbl == NULL)
           *hufftbl = jpeg_alloc_huff_table ((j_common_ptr)info);
       if (*hufftbl == NULL)
           return -1;

       memcpy ((*hufftbl)->bits, bits, sizeof (*hufftbl)->bits);
       memcpy ((*hufftbl)->huffval, huffval, sizeof (*hufftbl)->huffval);
    }

    if (length != 0)
       return -1;

    return 0;
}
Beispiel #8
0
JHUFF_TBL *
gs_jpeg_alloc_huff_table(stream_DCT_state * st)
{
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) {
        gs_jpeg_log_error(st);
        return NULL;
    }
    return jpeg_alloc_huff_table((j_common_ptr)
                                 & st->data.compress->cinfo);
}
Beispiel #9
0
static void add_huff_table (j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) {
	if (*htblptr == NULL)
		*htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo);

	memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));
	memcpy((*htblptr)->huffval, val, sizeof((*htblptr)->huffval));

	/* Initialize sent_table FALSE so table will be written to JPEG file. */
	(*htblptr)->sent_table = FALSE;
}
Beispiel #10
0
static void
add_huff_table(j_decompress_ptr cinfo,
	       JHUFF_TBL ** htblptr, const UINT8 * bits, const UINT8 * val)
{
    int nsymbols, len;

    if (*htblptr == NULL)
	*htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);

    memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits));

    nsymbols = 0;
    for (len = 1; len <= 16; len++)
	nsymbols += bits[len];
    memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8));

    (*htblptr)->sent_table = FALSE;
}
Beispiel #11
0
add_huff_table (j_compress_ptr cinfo,
		JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
{
  int nsymbols, len;

  if (*htblptr == NULL)
    *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);

  
  MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));

  nsymbols = 0;
  for (len = 1; len <= 16; len++)
    nsymbols += bits[len];
  if (nsymbols < 1 || nsymbols > 256)
    ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);

  MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));

  /* Initialize sent_table FALSE so table will be written to JPEG file. */
  (*htblptr)->sent_table = FALSE;
}
Beispiel #12
0
add_huff_table (j_compress_ptr cinfo,
		JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
/* Define a Huffman table */
{
  if (*(JHUFF_TBL **)(__boundcheck_ptr_reference(151,8,"add_huff_table",(void *)(htblptr),(void *)(htblptr))) == NULL)
    *(JHUFF_TBL **)(__boundcheck_ptr_reference(152,6,"add_huff_table",(void *)(htblptr),(void *)(htblptr))) = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  
  MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  MEMCOPY((*htblptr)->huffval, val, SIZEOF((*htblptr)->huffval));

  /* Initialize sent_table FALSE so table will be written to JPEG file. */
  (*(JHUFF_TBL **)(__boundcheck_ptr_reference(158,5,"add_huff_table",(void *)(htblptr),(void *)(htblptr))))->sent_table = FALSE;
}