| 92 | } |
| 93 | |
| 94 | static int jpeg_create_header(uint8_t *buf, int size, uint32_t type, uint32_t w, |
| 95 | uint32_t h, const uint8_t *qtable, int nb_qtable, |
| 96 | int dri) |
| 97 | { |
| 98 | PutByteContext pbc; |
| 99 | uint8_t *dht_size_ptr; |
| 100 | int dht_size, i; |
| 101 | |
| 102 | bytestream2_init_writer(&pbc, buf, size); |
| 103 | |
| 104 | /* Convert from blocks to pixels. */ |
| 105 | w <<= 3; |
| 106 | h <<= 3; |
| 107 | |
| 108 | /* SOI */ |
| 109 | jpeg_put_marker(&pbc, SOI); |
| 110 | |
| 111 | /* JFIF header */ |
| 112 | jpeg_put_marker(&pbc, APP0); |
| 113 | bytestream2_put_be16(&pbc, 16); |
| 114 | bytestream2_put_buffer(&pbc, "JFIF", 5); |
| 115 | bytestream2_put_be16(&pbc, 0x0102); |
| 116 | bytestream2_put_byte(&pbc, 0); |
| 117 | bytestream2_put_be16(&pbc, 1); |
| 118 | bytestream2_put_be16(&pbc, 1); |
| 119 | bytestream2_put_byte(&pbc, 0); |
| 120 | bytestream2_put_byte(&pbc, 0); |
| 121 | |
| 122 | if (dri) { |
| 123 | jpeg_put_marker(&pbc, DRI); |
| 124 | bytestream2_put_be16(&pbc, 4); |
| 125 | bytestream2_put_be16(&pbc, dri); |
| 126 | } |
| 127 | |
| 128 | /* DQT */ |
| 129 | jpeg_put_marker(&pbc, DQT); |
| 130 | bytestream2_put_be16(&pbc, 2 + nb_qtable * (1 + 64)); |
| 131 | |
| 132 | for (i = 0; i < nb_qtable; i++) { |
| 133 | bytestream2_put_byte(&pbc, i); |
| 134 | |
| 135 | /* Each table is an array of 64 values given in zig-zag |
| 136 | * order, identical to the format used in a JFIF DQT |
| 137 | * marker segment. */ |
| 138 | bytestream2_put_buffer(&pbc, qtable + 64 * i, 64); |
| 139 | } |
| 140 | |
| 141 | /* DHT */ |
| 142 | jpeg_put_marker(&pbc, DHT); |
| 143 | dht_size_ptr = pbc.buffer; |
| 144 | bytestream2_put_be16(&pbc, 0); |
| 145 | |
| 146 | dht_size = 2; |
| 147 | dht_size += jpeg_create_huffman_table(&pbc, 0, 0,ff_mjpeg_bits_dc_luminance, |
| 148 | ff_mjpeg_val_dc); |
| 149 | dht_size += jpeg_create_huffman_table(&pbc, 0, 1, ff_mjpeg_bits_dc_chrominance, |
| 150 | ff_mjpeg_val_dc); |
| 151 | dht_size += jpeg_create_huffman_table(&pbc, 1, 0, ff_mjpeg_bits_ac_luminance, |
no test coverage detected