⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcmarker.c

📁 基于Linux的ffmepg decoder
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * jcmarker.c * * Copyright (C) 1991-1998, Thomas G. Lane. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * * This file contains routines to write JPEG datastream markers. */#define JPEG_INTERNALS#include "jinclude.h"#include "jpeglib.h"typedef enum {			/* JPEG marker codes */  M_SOF0  = 0xc0,  M_SOF1  = 0xc1,  M_SOF2  = 0xc2,  M_SOF3  = 0xc3,    M_SOF5  = 0xc5,  M_SOF6  = 0xc6,  M_SOF7  = 0xc7,    M_JPG   = 0xc8,  M_SOF9  = 0xc9,  M_SOF10 = 0xca,  M_SOF11 = 0xcb,    M_SOF13 = 0xcd,  M_SOF14 = 0xce,  M_SOF15 = 0xcf,    M_DHT   = 0xc4,    M_DAC   = 0xcc,    M_RST0  = 0xd0,  M_RST1  = 0xd1,  M_RST2  = 0xd2,  M_RST3  = 0xd3,  M_RST4  = 0xd4,  M_RST5  = 0xd5,  M_RST6  = 0xd6,  M_RST7  = 0xd7,    M_SOI   = 0xd8,  M_EOI   = 0xd9,  M_SOS   = 0xda,  M_DQT   = 0xdb,  M_DNL   = 0xdc,  M_DRI   = 0xdd,  M_DHP   = 0xde,  M_EXP   = 0xdf,    M_APP0  = 0xe0,  M_APP1  = 0xe1,  M_APP2  = 0xe2,  M_APP3  = 0xe3,  M_APP4  = 0xe4,  M_APP5  = 0xe5,  M_APP6  = 0xe6,  M_APP7  = 0xe7,  M_APP8  = 0xe8,  M_APP9  = 0xe9,  M_APP10 = 0xea,  M_APP11 = 0xeb,  M_APP12 = 0xec,  M_APP13 = 0xed,  M_APP14 = 0xee,  M_APP15 = 0xef,    M_JPG0  = 0xf0,  M_JPG13 = 0xfd,  M_COM   = 0xfe,    M_TEM   = 0x01,    M_ERROR = 0x100} JPEG_MARKER;/* Private state */typedef struct {  struct jpeg_marker_writer pub; /* public fields */  unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */} my_marker_writer;typedef my_marker_writer * my_marker_ptr;LOCAL(void)emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)/* Emit a marker code */{	//BitstreamPutBits(0xFF,8);	BitstreamPutBits((0xFF00 | (int) mark),16);  //emit_word(cinfo, 0xFF, 8);		//pwhsu++  //emit_word(cinfo, (int) mark, 8);  //emit_byte(cinfo, 0xFF);  //emit_byte(cinfo, (int) mark);}/* * Routines to write specific marker types. */LOCAL(int)emit_dqt (j_compress_ptr cinfo, int index)/* Emit a DQT marker *//* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */{  JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];  int prec;  int i;  if (qtbl == NULL)    ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);  prec = 0;  //for (i = 0; i < DCTSIZE2; i++) {  //  if (qtbl->quantval[i] > 255)  //    prec = 1;  //}  if (! qtbl->sent_table) {	emit_marker(cinfo, M_DQT);			//DQT	//BitstreamPutBits(M_DQT,8);    //emit_word(cinfo, M_DQT, 8);			//DQT  //pwhsu++:20040113		BitstreamPutBits(prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2,16);			//Lq    //emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);    	BitstreamPutBits(index + (prec<<4),8);    //emit_word(cinfo, index + (prec<<4), 8);		//Pq Tq //pwhsu++:20040113	//emit_byte(cinfo, index + (prec<<4));		//Pq Tq/*    for (i = 0; i < DCTSIZE2; i++) {	  unsigned int qval = rinfo.Inter_quant[index][jpeg_natural_order[i]];   //pwhsu++:20031031	  BitstreamPutBits((int) (qval & 0xFF),8);    }*/	for (i = 0; i < 8; i++) {	  int j = i*8;	  int qval0 = (rinfo.Inter_quant[index][jpeg_natural_order[j]]) & 0xFF;	  int qval1 = (rinfo.Inter_quant[index][jpeg_natural_order[j+1]]) & 0xFF;	  BitstreamPutBits( ((qval0<<8)|qval1), 16 );	  qval0 = (rinfo.Inter_quant[index][jpeg_natural_order[j+2]]) & 0xFF;	  qval1 = (rinfo.Inter_quant[index][jpeg_natural_order[j+3]]) & 0xFF;	  BitstreamPutBits( ((qval0<<8)|qval1), 16 );	  qval0 = (rinfo.Inter_quant[index][jpeg_natural_order[j+4]]) & 0xFF;	  qval1 = (rinfo.Inter_quant[index][jpeg_natural_order[j+5]]) & 0xFF;	  BitstreamPutBits( ((qval0<<8)|qval1), 16 );	  qval0 = (rinfo.Inter_quant[index][jpeg_natural_order[j+6]]) & 0xFF;	  qval1 = (rinfo.Inter_quant[index][jpeg_natural_order[j+7]]) & 0xFF;	  BitstreamPutBits( ((qval0<<8)|qval1), 16 );    }    qtbl->sent_table = TRUE;  }  return prec;}LOCAL(void)emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)/* Emit a DHT marker */{  JHUFF_TBL * htbl;  int length, i;    if (is_ac) {    htbl = cinfo->ac_huff_tbl_ptrs[index];    index += 0x10;		/* output index has AC bit set */  } else {    htbl = cinfo->dc_huff_tbl_ptrs[index];  }  if (htbl == NULL)    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);    if (! htbl->sent_table) {    emit_marker(cinfo, M_DHT);			//DHT        length = 0;    for (i = 1; i <= 16; i++)      length += htbl->bits[i];              	BitstreamPutBits(length + 2 + 1 + 16,16);	//Lh  (huffman table definition length)    	BitstreamPutBits(index,8);					    for (i = 1; i <= 16; i++)	  BitstreamPutBits(htbl->bits[i],8);          for (i = 0; i < length; i++)	  BitstreamPutBits(htbl->huffval[i],8);	          htbl->sent_table = TRUE;  }}LOCAL(void)emit_dri (j_compress_ptr cinfo)/* Emit a DRI marker */{  emit_marker(cinfo, M_DRI);    BitstreamPutBits(4, 16);	/* fixed length */  //emit_2bytes(cinfo, 4);	/* fixed length */  BitstreamPutBits((int) cinfo->restart_interval, 16);  //emit_2bytes(cinfo, (int) cinfo->restart_interval);}LOCAL(void)emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)/* Emit a SOF marker */{  int ci;  jpeg_component_info *compptr;    emit_marker(cinfo, code);		//SOFn    BitstreamPutBits(3 * cinfo->num_components + 2 + 5 + 1, 16);  /* length */ //Lf  /* Make sure image isn't bigger than SOF field can handle */  if ((long) cinfo->image_height > 65535L ||      (long) cinfo->image_width > 65535L)    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);  BitstreamPutBits(cinfo->data_precision, 8);  BitstreamPutBits((int) cinfo->image_height, 16);  BitstreamPutBits((int) cinfo->image_width, 16);   BitstreamPutBits(cinfo->num_components, 8);  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;       ci++, compptr++) {		   BitstreamPutBits(compptr->component_id, 8);		   BitstreamPutBits((compptr->h_samp_factor << 4) + compptr->v_samp_factor, 8);		   BitstreamPutBits(compptr->quant_tbl_no, 8);  }}LOCAL(void)emit_sos (j_compress_ptr cinfo)/* Emit a SOS marker */{  int i, td, ta;  jpeg_component_info *compptr;    emit_marker(cinfo, M_SOS);	//SOS    BitstreamPutBits(2 * cinfo->comps_in_scan + 2 + 1 + 3, 16);  //Ls    BitstreamPutBits(cinfo->comps_in_scan, 8);	//Ns    for (i = 0; i < cinfo->comps_in_scan; i++) {    compptr = cinfo->cur_comp_info[i];		BitstreamPutBits(compptr->component_id, 8);     td = compptr->dc_tbl_no;    ta = compptr->ac_tbl_no;    if (cinfo->progressive_mode) {      /* Progressive mode: only DC or only AC tables are used in one scan;       * furthermore, Huffman coding of DC refinement uses no table at all.       * We emit 0 for unused field(s); this is recommended by the P&M text       * but does not seem to be specified in the standard.       */      if (cinfo->Ss == 0) {	ta = 0;			/* DC scan */	if (cinfo->Ah != 0 && !cinfo->arith_code)	  td = 0;		/* no DC table either */      } else {	td = 0;			/* AC scan */      }    }	BitstreamPutBits((td << 4) + ta, 8);	  }  //BitstreamPutBits(cinfo->Ss, 8);  //Ss  //BitstreamPutBits(cinfo->Se, 8);  //Se  BitstreamPutBits((cinfo->Ss<<8)|cinfo->Se, 16);  BitstreamPutBits(0, 8);		//In baseline  //Ah Al    //emit_word(cinfo, cinfo->Ss, 8);		//Ss	//pwhsu++:20040113  //emit_word(cinfo, cinfo->Se, 8);		//Se  //emit_word(cinfo, (cinfo->Ah << 4) + cinfo->Al, 8);	//Ah Al  //emit_byte(cinfo, cinfo->Ss);		//Ss  //emit_byte(cinfo, cinfo->Se);		//Se  //emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);	//Ah Al}LOCAL(void)emit_jfif_app0 (j_compress_ptr cinfo)/* Emit a JFIF-compliant APP0 marker */{  /*   * Length of APP0 block	(2 bytes)   * Block ID			(4 bytes - ASCII "JFIF")   * Zero byte			(1 byte to terminate the ID string)   * Version Major, Minor	(2 bytes - major first)   * Units			(1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)   * Xdpu			(2 bytes - dots per unit horizontal)   * Ydpu			(2 bytes - dots per unit vertical)   * Thumbnail X size		(1 byte)   * Thumbnail Y size		(1 byte)   */    emit_marker(cinfo, M_APP0);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -