Lines Matching refs:priv
155 static int build_default_huffman_tables(struct jdec_private *priv)
158 if (priv->default_huffman_table_initialized)
162 priv->HTDC_valid[i] = 1;
163 memcpy(priv->HTDC[i].bits, default_huffman_table_param.huffman_table[i].num_dc_codes, 16);
164 memcpy(priv->HTDC[i].values, default_huffman_table_param.huffman_table[i].dc_values, 16);
165 priv->HTAC_valid[i] = 1;
166 memcpy(priv->HTAC[i].bits, default_huffman_table_param.huffman_table[i].num_ac_codes, 16);
167 memcpy(priv->HTAC[i].values, default_huffman_table_param.huffman_table[i].ac_values, 256);
169 priv->default_huffman_table_initialized = 1;
199 static int parse_DQT(struct jdec_private *priv, const unsigned char *stream)
217 memcpy(priv->Q_tables[qi&0x0F], stream, 64);
218 priv->Q_tables_valid[qi & 0x0f] = 1;
225 static int parse_SOF(struct jdec_private *priv, const unsigned char *stream)
237 priv->nf_components = nr_components;
255 c = &priv->component_infos[i];
266 priv->width[scan_num] = width;
267 priv->height[scan_num] = height;
274 static int parse_SOS(struct jdec_private *priv, const unsigned char *stream)
281 priv->cur_sos.nr_components= nr_components;
287 priv->cur_sos.components[i].component_id = cid;
288 priv->cur_sos.components[i].dc_selector = ((table>>4)&0x0F);
289 priv->cur_sos.components[i].ac_selector = (table&0x0F);
295 if (cid != priv->component_infos[i].cid)
297 i, cid, i, priv->component_infos[i].cid);
301 priv->stream = stream+3;
306 int tinyjpeg_parse_SOS(struct jdec_private *priv, const unsigned char *stream)
308 return parse_SOS(priv, stream);
312 static int parse_DHT(struct jdec_private *priv, const unsigned char *stream)
329 memcpy(priv->HTAC[index & 0xf].bits, stream, 16);
332 memcpy(priv->HTDC[index & 0xf].bits, stream, 16);
349 memcpy(priv->HTAC[index & 0xf].values, stream, count);
350 priv->HTAC_valid[index & 0xf] = 1;
353 memcpy(priv->HTDC[index & 0xf].values, stream, count);
354 priv->HTDC_valid[index & 0xf] = 1;
365 static int parse_DRI(struct jdec_private *priv, const unsigned char *stream)
378 priv->restart_interval = be16_to_cpu(stream+2);
381 trace("Restart interval = %d\n", priv->restart_interval);
389 static int findEOI(struct jdec_private *priv,const unsigned char *stream)
391 while (!(*stream == 0xff && *(stream+1) == 0xd9 )&& stream<=priv->stream_end) //searching for the end of image marker
396 priv->stream_scan=stream;
400 static int findSOI(struct jdec_private *priv,const unsigned char *stream)
404 if(stream<=priv->stream_end)
412 priv->stream=stream+2;
416 static int parse_JFIF(struct jdec_private *priv, const unsigned char *stream)
425 next_image_found = findSOI(priv,stream);
426 stream=priv->stream;
428 while (!sos_marker_found && stream<=priv->stream_end)
439 if (parse_SOF(priv, stream) < 0)
443 if (parse_DQT(priv, stream) < 0)
448 if (parse_SOS(priv, stream) < 0)
453 if (parse_DHT(priv, stream) < 0)
458 if (parse_DRI(priv, stream) < 0)
472 build_default_huffman_tables(priv);
479 if ( (priv->component_infos[cY].Hfactor < priv->component_infos[cCb].Hfactor)
480 || (priv->component_infos[cY].Hfactor < priv->component_infos[cCr].Hfactor))
482 if ( (priv->component_infos[cY].Vfactor < priv->component_infos[cCb].Vfactor)
483 || (priv->component_infos[cY].Vfactor < priv->component_infos[cCr].Vfactor))
485 if ( (priv->component_infos[cCb].Hfactor!=1)
486 || (priv->component_infos[cCr].Hfactor!=1)
487 || (priv->component_infos[cCb].Vfactor!=1)
488 || (priv->component_infos[cCr].Vfactor!=1))
491 findEOI(priv,stream);
513 struct jdec_private *priv;
515 priv = (struct jdec_private *)calloc(1, sizeof(struct jdec_private));
516 if (priv == NULL)
518 return priv;
526 void tinyjpeg_free(struct jdec_private *priv)
528 free(priv);
537 int tinyjpeg_parse_header(struct jdec_private *priv, const unsigned char *buf, unsigned int size)
545 priv->stream_begin = buf;
546 priv->stream_length = size;
547 priv->stream_end = priv->stream_begin + priv->stream_length;
549 priv->stream = priv->stream_begin;
550 ret = parse_JFIF(priv, priv->stream);
555 int tinyjpeg_decode(struct jdec_private *priv)
620 pic_param.picture_width = priv->width[scan_num];
621 pic_param.picture_height = priv->height[scan_num];
622 pic_param.num_components = priv->nf_components;
626 pic_param.components[i].component_id = priv->component_infos[i].cid;
627 pic_param.components[i].h_sampling_factor = priv->component_infos[i].Hfactor;
628 pic_param.components[i].v_sampling_factor = priv->component_infos[i].Vfactor;
629 pic_param.components[i].quantiser_table_selector = priv->component_infos[i].quant_table_index;
703 priv->width[scan_num],priv->height[scan_num], //alignment?
709 priv->width[scan_num], priv->height[scan_num], // alignment?
729 if (!priv->Q_tables_valid[i])
733 iq_matrix.quantiser_table[i][j] = priv->Q_tables[i][j];
747 sizeof(priv->HTDC[0].bits));
749 sizeof(priv->HTDC[0].values[0]));
751 if (!priv->HTDC_valid[i] || !priv->HTAC_valid[i])
754 memcpy(huffman_table.huffman_table[i].num_dc_codes, priv->HTDC[i].bits,
756 memcpy(huffman_table.huffman_table[i].dc_values, priv->HTDC[i].values,
758 memcpy(huffman_table.huffman_table[i].num_ac_codes, priv->HTAC[i].bits,
760 memcpy(huffman_table.huffman_table[i].ac_values, priv->HTAC[i].values,
773 max_h_factor = priv->component_infos[0].Hfactor;
774 max_v_factor = priv->component_infos[0].Vfactor;
776 slice_param.slice_data_size = (priv->stream_scan - priv->stream);
781 slice_param.num_components = priv->cur_sos.nr_components;
783 slice_param.components[i].component_selector = priv->cur_sos.components[i].component_id; /* FIXME: set to values specified in SOS */
784 slice_param.components[i].dc_table_selector = priv->cur_sos.components[i].dc_selector; /* FIXME: set to values specified in SOS */
785 slice_param.components[i].ac_table_selector = priv->cur_sos.components[i].ac_selector; /* FIXME: set to values specified in SOS */
787 slice_param.restart_interval = priv->restart_interval;
788 slice_param.num_mcus = ((priv->width[scan_num]+max_h_factor*8-1)/(max_h_factor*8))*
789 ((priv->height[scan_num]+max_v_factor*8-1)/(max_v_factor*8)); // ?? 720/16?
800 priv->stream_scan - priv->stream,
802 (void*)priv->stream, // jpeg_clip,
835 src_rect.width = priv->width[scan_num];
836 src_rect.height = priv->height[scan_num];
848 parse_JFIF(priv,priv->stream);
849 if(priv->width[scan_num] == 0 && priv->height[scan_num] == 0)
858 const char *tinyjpeg_get_errorstring(struct jdec_private *priv)
861 priv = priv;
864 void tinyjpeg_get_size(struct jdec_private *priv, unsigned int *width, unsigned int *height)
866 *width = priv->width[scan_num];
867 *height = priv->height[scan_num];