19f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 29f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * jcmarker.c 39f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 49f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Copyright (C) 1991-1998, Thomas G. Lane. 59f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This file is part of the Independent JPEG Group's software. 69f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * For conditions of distribution and use, see the accompanying README file. 79f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 89f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This file contains routines to write JPEG datastream markers. 99f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#define JPEG_INTERNALS 129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#include "jinclude.h" 139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#include "jpeglib.h" 149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projecttypedef enum { /* JPEG marker codes */ 179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF0 = 0xc0, 189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF1 = 0xc1, 199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF2 = 0xc2, 209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF3 = 0xc3, 219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF5 = 0xc5, 239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF6 = 0xc6, 249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF7 = 0xc7, 259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_JPG = 0xc8, 279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF9 = 0xc9, 289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF10 = 0xca, 299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF11 = 0xcb, 309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF13 = 0xcd, 329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF14 = 0xce, 339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOF15 = 0xcf, 349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_DHT = 0xc4, 369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_DAC = 0xcc, 389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST0 = 0xd0, 409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST1 = 0xd1, 419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST2 = 0xd2, 429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST3 = 0xd3, 439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST4 = 0xd4, 449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST5 = 0xd5, 459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST6 = 0xd6, 469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_RST7 = 0xd7, 479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOI = 0xd8, 499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_EOI = 0xd9, 509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_SOS = 0xda, 519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_DQT = 0xdb, 529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_DNL = 0xdc, 539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_DRI = 0xdd, 549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_DHP = 0xde, 559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_EXP = 0xdf, 569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP0 = 0xe0, 589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP1 = 0xe1, 599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP2 = 0xe2, 609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP3 = 0xe3, 619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP4 = 0xe4, 629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP5 = 0xe5, 639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP6 = 0xe6, 649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP7 = 0xe7, 659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP8 = 0xe8, 669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP9 = 0xe9, 679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP10 = 0xea, 689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP11 = 0xeb, 699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP12 = 0xec, 709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP13 = 0xed, 719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP14 = 0xee, 729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_APP15 = 0xef, 739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_JPG0 = 0xf0, 759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_JPG13 = 0xfd, 769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_COM = 0xfe, 779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_TEM = 0x01, 799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project M_ERROR = 0x100 819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} JPEG_MARKER; 829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Private state */ 859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projecttypedef struct { 879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project struct jpeg_marker_writer pub; /* public fields */ 889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */ 909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} my_marker_writer; 919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projecttypedef my_marker_writer * my_marker_ptr; 939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Basic output routines. 979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Note that we do not support suspension while writing a marker. 999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Therefore, an application using suspension must ensure that there is 1009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * enough buffer space for the initial markers (typ. 600-700 bytes) before 1019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * calling jpeg_start_compress, and enough space to write the trailing EOI 1029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * (a few bytes) before calling jpeg_finish_compress. Multipass compression 1039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * modes are not supported at all with suspension, so those two are the only 1049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * points where markers will be written. 1059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 1069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 1089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_byte (j_compress_ptr cinfo, int val) 1099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a byte */ 1109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 1119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project struct jpeg_destination_mgr * dest = cinfo->dest; 1129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project *(dest->next_output_byte)++ = (JOCTET) val; 1149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (--dest->free_in_buffer == 0) { 1159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (! (*dest->empty_output_buffer) (cinfo)) 1169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ERREXIT(cinfo, JERR_CANT_SUSPEND); 1179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 1189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 1199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 1229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_marker (j_compress_ptr cinfo, JPEG_MARKER mark) 1239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a marker code */ 1249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 1259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0xFF); 1269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, (int) mark); 1279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 1289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 1319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_2bytes (j_compress_ptr cinfo, int value) 1329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a 2-byte integer; these are always MSB first in JPEG files */ 1339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 1349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, (value >> 8) & 0xFF); 1359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, value & 0xFF); 1369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 1379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 1409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Routines to write specific marker types. 1419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 1429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(int) 1449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_dqt (j_compress_ptr cinfo, int index) 1459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a DQT marker */ 1469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */ 1479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 1489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index]; 1499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int prec; 1509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int i; 1519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (qtbl == NULL) 1539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index); 1549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project prec = 0; 1569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < DCTSIZE2; i++) { 1579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (qtbl->quantval[i] > 255) 1589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project prec = 1; 1599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 1609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (! qtbl->sent_table) { 1629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_DQT); 1639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2); 1659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, index + (prec<<4)); 1679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < DCTSIZE2; i++) { 1699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* The table entries must be emitted in zigzag order. */ 1709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project unsigned int qval = qtbl->quantval[jpeg_natural_order[i]]; 1719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (prec) 1729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, (int) (qval >> 8)); 1739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, (int) (qval & 0xFF)); 1749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 1759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project qtbl->sent_table = TRUE; 1779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 1789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project return prec; 1809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 1819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 1849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_dht (j_compress_ptr cinfo, int index, boolean is_ac) 1859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a DHT marker */ 1869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 1879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project JHUFF_TBL * htbl; 1889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int length, i; 1899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (is_ac) { 1919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project htbl = cinfo->ac_huff_tbl_ptrs[index]; 1929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project index += 0x10; /* output index has AC bit set */ 1939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } else { 1949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project htbl = cinfo->dc_huff_tbl_ptrs[index]; 1959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 1969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 1979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (htbl == NULL) 1989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index); 1999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (! htbl->sent_table) { 2019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_DHT); 2029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project length = 0; 2049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 1; i <= 16; i++) 2059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project length += htbl->bits[i]; 2069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, length + 2 + 1 + 16); 2089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, index); 2099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 1; i <= 16; i++) 2119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, htbl->bits[i]); 2129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < length; i++) 2149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, htbl->huffval[i]); 2159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project htbl->sent_table = TRUE; 2179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 2189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 2199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 2229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_dac (j_compress_ptr cinfo) 2239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a DAC marker */ 2249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Since the useful info is so small, we want to emit all the tables in */ 2259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* one DAC marker. Therefore this routine does its own scan of the table. */ 2269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 2279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#ifdef C_ARITH_CODING_SUPPORTED 2289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project char dc_in_use[NUM_ARITH_TBLS]; 2299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project char ac_in_use[NUM_ARITH_TBLS]; 2309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int length, i; 2319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jpeg_component_info *compptr; 2329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < NUM_ARITH_TBLS; i++) 2349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project dc_in_use[i] = ac_in_use[i] = 0; 2359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < cinfo->comps_in_scan; i++) { 2379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project compptr = cinfo->cur_comp_info[i]; 2389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project dc_in_use[compptr->dc_tbl_no] = 1; 2399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ac_in_use[compptr->ac_tbl_no] = 1; 2409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 2419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project length = 0; 2439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < NUM_ARITH_TBLS; i++) 2449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project length += dc_in_use[i] + ac_in_use[i]; 2459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_DAC); 2479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, length*2 + 2); 2499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < NUM_ARITH_TBLS; i++) { 2519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (dc_in_use[i]) { 2529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, i); 2539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4)); 2549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 2559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (ac_in_use[i]) { 2569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, i + 0x10); 2579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->arith_ac_K[i]); 2589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 2599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 2609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project#endif /* C_ARITH_CODING_SUPPORTED */ 2619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 2629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 2659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_dri (j_compress_ptr cinfo) 2669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a DRI marker */ 2679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 2689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_DRI); 2699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 4); /* fixed length */ 2719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, (int) cinfo->restart_interval); 2739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 2749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 2779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_sof (j_compress_ptr cinfo, JPEG_MARKER code) 2789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a SOF marker */ 2799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 2809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int ci; 2819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jpeg_component_info *compptr; 2829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, code); 2849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */ 2869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Make sure image isn't bigger than SOF field can handle */ 2889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if ((long) cinfo->image_height > 65535L || 2899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project (long) cinfo->image_width > 65535L) 2909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535); 2919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->data_precision); 2939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, (int) cinfo->image_height); 2949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, (int) cinfo->image_width); 2959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->num_components); 2979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 2989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 2999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ci++, compptr++) { 3009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, compptr->component_id); 3019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor); 3029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, compptr->quant_tbl_no); 3039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 3049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 3059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 3089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_sos (j_compress_ptr cinfo) 3099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a SOS marker */ 3109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 3119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int i, td, ta; 3129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jpeg_component_info *compptr; 3139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_SOS); 3159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */ 3179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->comps_in_scan); 3199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < cinfo->comps_in_scan; i++) { 3219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project compptr = cinfo->cur_comp_info[i]; 3229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, compptr->component_id); 3239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project td = compptr->dc_tbl_no; 3249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ta = compptr->ac_tbl_no; 3259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->progressive_mode) { 3269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Progressive mode: only DC or only AC tables are used in one scan; 3279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * furthermore, Huffman coding of DC refinement uses no table at all. 3289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * We emit 0 for unused field(s); this is recommended by the P&M text 3299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * but does not seem to be specified in the standard. 3309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 3319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->Ss == 0) { 3329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ta = 0; /* DC scan */ 3339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->Ah != 0 && !cinfo->arith_code) 3349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project td = 0; /* no DC table either */ 3359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } else { 3369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project td = 0; /* AC scan */ 3379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 3389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 3399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, (td << 4) + ta); 3409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 3419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->Ss); 3439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->Se); 3449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al); 3459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 3469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 3499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_jfif_app0 (j_compress_ptr cinfo) 3509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit a JFIF-compliant APP0 marker */ 3519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 3529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* 3539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Length of APP0 block (2 bytes) 3549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Block ID (4 bytes - ASCII "JFIF") 3559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Zero byte (1 byte to terminate the ID string) 3569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Version Major, Minor (2 bytes - major first) 3579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Units (1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm) 3589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Xdpu (2 bytes - dots per unit horizontal) 3599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Ydpu (2 bytes - dots per unit vertical) 3609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Thumbnail X size (1 byte) 3619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Thumbnail Y size (1 byte) 3629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 3639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_APP0); 3659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */ 3679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */ 3699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x46); 3709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x49); 3719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x46); 3729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0); 3739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */ 3749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->JFIF_minor_version); 3759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */ 3769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, (int) cinfo->X_density); 3779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, (int) cinfo->Y_density); 3789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0); /* No thumbnail image */ 3799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0); 3809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 3819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 3839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectLOCAL(void) 3849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectemit_adobe_app14 (j_compress_ptr cinfo) 3859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit an Adobe APP14 marker */ 3869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 3879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* 3889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Length of APP14 block (2 bytes) 3899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Block ID (5 bytes - ASCII "Adobe") 3909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Version Number (2 bytes - currently 100) 3919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Flags0 (2 bytes - currently 0) 3929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Flags1 (2 bytes - currently 0) 3939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Color transform (1 byte) 3949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 3959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Although Adobe TN 5116 mentions Version = 101, all the Adobe files 3969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * now in circulation seem to use Version = 100, so that's what we write. 3979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * 3989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * We write the color transform byte as 1 if the JPEG color space is 3999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * YCbCr, 2 if it's YCCK, 0 otherwise. Adobe's definition has to do with 4009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * whether the encoder performed a transformation, which is pretty useless. 4019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 4029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_APP14); 4049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */ 4069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */ 4089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x64); 4099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x6F); 4109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x62); 4119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0x65); 4129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 100); /* Version */ 4139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 0); /* Flags0 */ 4149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, 0); /* Flags1 */ 4159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project switch (cinfo->jpeg_color_space) { 4169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project case JCS_YCbCr: 4179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 1); /* Color transform = 1 */ 4189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project break; 4199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project case JCS_YCCK: 4209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 2); /* Color transform = 2 */ 4219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project break; 4229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project default: 4239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, 0); /* Color transform = 0 */ 4249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project break; 4259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 4269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 4279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 4309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * These routines allow writing an arbitrary marker with parameters. 4319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * The only intended use is to emit COM or APPn markers after calling 4329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * write_file_header and before calling write_frame_header. 4339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Other uses are not guaranteed to produce desirable results. 4349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Counting the parameter bytes properly is the caller's responsibility. 4359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 4369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectMETHODDEF(void) 4389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectwrite_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen) 4399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit an arbitrary marker header */ 4409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 4419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (datalen > (unsigned int) 65533) /* safety check */ 4429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ERREXIT(cinfo, JERR_BAD_LENGTH); 4439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, (JPEG_MARKER) marker); 4459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */ 4479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 4489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectMETHODDEF(void) 4509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectwrite_marker_byte (j_compress_ptr cinfo, int val) 4519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* Emit one byte of marker parameters following write_marker_header */ 4529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 4539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_byte(cinfo, val); 4549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 4559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 4589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Write datastream header. 4599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This consists of an SOI and optional APPn markers. 4609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * We recommend use of the JFIF marker, but not the Adobe marker, 4619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * when using YCbCr or grayscale data. The JFIF marker should NOT 4629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * be used for any other JPEG colorspace. The Adobe marker is helpful 4639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * to distinguish RGB, CMYK, and YCCK colorspaces. 4649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Note that an application can write additional header markers after 4659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * jpeg_start_compress returns. 4669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 4679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectMETHODDEF(void) 4699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectwrite_file_header (j_compress_ptr cinfo) 4709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 4719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project my_marker_ptr marker = (my_marker_ptr) cinfo->marker; 4729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_SOI); /* first the SOI */ 4749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* SOI is defined to reset restart interval to 0 */ 4769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->last_restart_interval = 0; 4779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */ 4799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_jfif_app0(cinfo); 4809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */ 4819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_adobe_app14(cinfo); 4829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 4839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 4869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Write frame header. 4879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This consists of DQT and SOFn markers. 4889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Note that we do not emit the SOF until we have emitted the DQT(s). 4899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This avoids compatibility problems with incorrect implementations that 4909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * try to error-check the quant table numbers as soon as they see the SOF. 4919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 4929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 4939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectMETHODDEF(void) 4949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectwrite_frame_header (j_compress_ptr cinfo) 4959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 4969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int ci, prec; 4979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project boolean is_baseline; 4989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jpeg_component_info *compptr; 4999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Emit DQT for each quantization table. 5019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Note that emit_dqt() suppresses any duplicate tables. 5029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 5039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project prec = 0; 5049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 5059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ci++, compptr++) { 5069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project prec += emit_dqt(cinfo, compptr->quant_tbl_no); 5079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* now prec is nonzero iff there are any 16-bit quant tables. */ 5099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Check for a non-baseline specification. 5119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Note we assume that Huffman table numbers won't be changed later. 5129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 5139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->arith_code || cinfo->progressive_mode || 5149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project cinfo->data_precision != 8) { 5159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project is_baseline = FALSE; 5169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } else { 5179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project is_baseline = TRUE; 5189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 5199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project ci++, compptr++) { 5209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1) 5219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project is_baseline = FALSE; 5229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (prec && is_baseline) { 5249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project is_baseline = FALSE; 5259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* If it's baseline except for quantizer size, warn the user */ 5269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project TRACEMS(cinfo, 0, JTRC_16BIT_TABLES); 5279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Emit the proper SOF marker */ 5319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->arith_code) { 5329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */ 5339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } else { 5349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->progressive_mode) 5359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */ 5369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project else if (is_baseline) 5379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */ 5389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project else 5399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */ 5409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 5429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 5459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Write scan header. 5469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This consists of DHT or DAC markers, optional DRI, and SOS. 5479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Compressed data will be written following the SOS. 5489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 5499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectMETHODDEF(void) 5519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectwrite_scan_header (j_compress_ptr cinfo) 5529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 5539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project my_marker_ptr marker = (my_marker_ptr) cinfo->marker; 5549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int i; 5559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project jpeg_component_info *compptr; 5569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->arith_code) { 5589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Emit arith conditioning info. We may have some duplication 5599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * if the file has multiple scans, but it's so small it's hardly 5609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * worth worrying about. 5619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 5629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dac(cinfo); 5639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } else { 5649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Emit Huffman tables. 5659f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Note that emit_dht() suppresses any duplicate tables. 5669f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 5679f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < cinfo->comps_in_scan; i++) { 5689f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project compptr = cinfo->cur_comp_info[i]; 5699f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->progressive_mode) { 5709f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Progressive mode: only DC or only AC tables are used in one scan */ 5719f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->Ss == 0) { 5729f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->Ah == 0) /* DC needs no table for refinement scan */ 5739f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dht(cinfo, compptr->dc_tbl_no, FALSE); 5749f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } else { 5759f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dht(cinfo, compptr->ac_tbl_no, TRUE); 5769f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5779f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } else { 5789f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Sequential mode: need both DC and AC tables */ 5799f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dht(cinfo, compptr->dc_tbl_no, FALSE); 5809f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dht(cinfo, compptr->ac_tbl_no, TRUE); 5819f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5829f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5839f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5849f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5859f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Emit DRI if required --- note that DRI value could change for each scan. 5869f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * We avoid wasting space with unnecessary DRIs, however. 5879f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 5889f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->restart_interval != marker->last_restart_interval) { 5899f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dri(cinfo); 5909f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->last_restart_interval = cinfo->restart_interval; 5919f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 5929f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5939f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_sos(cinfo); 5949f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 5959f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5969f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 5979f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 5989f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Write datastream trailer. 5999f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 6009f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6019f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectMETHODDEF(void) 6029f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectwrite_file_trailer (j_compress_ptr cinfo) 6039f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 6049f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_EOI); 6059f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 6069f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6079f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6089f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 6099f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Write an abbreviated table-specification datastream. 6109f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * This consists of SOI, DQT and DHT tables, and EOI. 6119f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Any table that is defined and not marked sent_table = TRUE will be 6129f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * emitted. Note that all tables will be marked sent_table = TRUE at exit. 6139f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 6149f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6159f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectMETHODDEF(void) 6169f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectwrite_tables_only (j_compress_ptr cinfo) 6179f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 6189f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project int i; 6199f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6209f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_SOI); 6219f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6229f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < NUM_QUANT_TBLS; i++) { 6239f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->quant_tbl_ptrs[i] != NULL) 6249f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project (void) emit_dqt(cinfo, i); 6259f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 6269f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6279f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (! cinfo->arith_code) { 6289f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project for (i = 0; i < NUM_HUFF_TBLS; i++) { 6299f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->dc_huff_tbl_ptrs[i] != NULL) 6309f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dht(cinfo, i, FALSE); 6319f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project if (cinfo->ac_huff_tbl_ptrs[i] != NULL) 6329f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_dht(cinfo, i, TRUE); 6339f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 6349f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project } 6359f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6369f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project emit_marker(cinfo, M_EOI); 6379f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 6389f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6399f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6409f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project/* 6419f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project * Initialize the marker writer module. 6429f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project */ 6439f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6449f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source ProjectGLOBAL(void) 6459f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Projectjinit_marker_writer (j_compress_ptr cinfo) 6469f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project{ 6479f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project my_marker_ptr marker; 6489f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project 6499f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Create the subobject */ 6509f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker = (my_marker_ptr) 6519f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 6529f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project SIZEOF(my_marker_writer)); 6539f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project cinfo->marker = (struct jpeg_marker_writer *) marker; 6549f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Initialize method pointers */ 6559f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->pub.write_file_header = write_file_header; 6569f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->pub.write_frame_header = write_frame_header; 6579f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->pub.write_scan_header = write_scan_header; 6589f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->pub.write_file_trailer = write_file_trailer; 6599f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->pub.write_tables_only = write_tables_only; 6609f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->pub.write_marker_header = write_marker_header; 6619f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->pub.write_marker_byte = write_marker_byte; 6629f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project /* Initialize private state */ 6639f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project marker->last_restart_interval = 0; 6649f5d49a1588e438ae7ceabd0c94172117e3303aaThe Android Open Source Project} 665