| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
#include <string.h> |
| 108 |
#include "hpip.h" |
| 109 |
#include "ipdefs.h" |
| 110 |
#include "xjpg_dct.h" |
| 111 |
#include "xjpg_mrk.h" |
| 112 |
|
| 113 |
|
| 114 |
#if 0 |
| 115 |
#include "stdio.h" |
| 116 |
#include <tchar.h> |
| 117 |
#define PRINT(msg,arg1,arg2) \ |
| 118 |
_ftprintf(stdout, _T("(jpeg) ") msg, (int)arg1, (int)arg2) |
| 119 |
#else |
| 120 |
#define PRINT(msg,arg1,arg2) |
| 121 |
#endif |
| 122 |
|
| 123 |
|
| 124 |
#define RUN_OF_16 0xf0 |
| 125 |
#define MAX_HEADER_SIZE 2000 |
| 126 |
#define MAX_BLOCKS_IN_MCU 6 |
| 127 |
#define MAX_MCU_SIZE (MAX_BLOCKS_IN_MCU*304) |
| 128 |
|
| 129 |
#define OUTBUF_NUM_MCUS 2 |
| 130 |
|
| 131 |
#define Q_DEFAULT 20 |
| 132 |
#define MONO_FACTORS 0x10001000u |
| 133 |
#define COLOR_FACTORS 0x21102110u |
| 134 |
|
| 135 |
#define CHECK_VALUE 0xAceC0de4U |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
typedef struct { |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
BYTE lum_quant[64]; |
| 160 |
BYTE chrom_quant[64]; |
| 161 |
|
| 162 |
int wino_lum_quant[64]; |
| 163 |
int wino_lum_quant_thres[64]; |
| 164 |
int wino_chrom_quant[64]; |
| 165 |
int wino_chrom_quant_thres[64]; |
| 166 |
|
| 167 |
BOOL input_subsampled; |
| 168 |
BOOL fDenali; |
| 169 |
BOOL fOutputDNL; |
| 170 |
BOOL fOutputG3APP1; |
| 171 |
DWORD dwDummyHeaderBytes; |
| 172 |
UINT rows_in_mcu; |
| 173 |
UINT cols_in_mcu; |
| 174 |
UINT mcus_in_row; |
| 175 |
DWORD sample_factors; |
| 176 |
BYTE horiz_sam_facs[4]; |
| 177 |
BYTE vert_sam_facs [4]; |
| 178 |
BYTE max_horiz_sam_fac; |
| 179 |
BYTE max_vert_sam_fac; |
| 180 |
BYTE dc_q_factor; |
| 181 |
BYTE ac_q_factor; |
| 182 |
BYTE comps_in_pixel; |
| 183 |
BYTE whitePixel[4]; |
| 184 |
UINT pixels_in_row; |
| 185 |
int rows_in_page; |
| 186 |
int xRes; |
| 187 |
int yRes; |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
DWORD wr_bit_buf; |
| 192 |
|
| 193 |
|
| 194 |
int wr_bits_avail; |
| 195 |
|
| 196 |
|
| 197 |
BYTE *wr_outbuf_beg; |
| 198 |
|
| 199 |
|
| 200 |
BYTE *write_buf_next; |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
int enc_block[64]; |
| 206 |
int *enc_block_zz[64+16]; |
| 207 |
int prior_DC[4]; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
UINT rows_received; |
| 212 |
UINT rows_loaded; |
| 213 |
UINT mcus_sent; |
| 214 |
BOOL loading_rows; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
IP_IMAGE_TRAITS traits; |
| 219 |
BYTE *in_rows_ap[4][32]; |
| 220 |
BOOL fDidHeader; |
| 221 |
DWORD dwInNextPos; |
| 222 |
DWORD dwOutNextPos; |
| 223 |
DWORD dwValidChk; |
| 224 |
|
| 225 |
} JENC_INST, *PJENC_INST; |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
#if 0 |
| 235 |
|
| 236 |
static const BYTE orig_lum_quant[64] = { |
| 237 |
16, 11, 10, 16, 24, 40, 51, 61, |
| 238 |
12, 12, 14, 19, 26, 58, 60, 55, |
| 239 |
14, 13, 16, 24, 40, 57, 69, 56, |
| 240 |
14, 17, 22, 29, 51, 87, 80, 62, |
| 241 |
18, 22, 37, 56, 68, 109, 103, 77, |
| 242 |
24, 35, 55, 64, 81, 104, 113, 92, |
| 243 |
49, 64, 78, 87, 103, 121, 120, 101, |
| 244 |
72, 92, 95, 98, 112, 100, 103, 99 |
| 245 |
}; |
| 246 |
|
| 247 |
|
| 248 |
static const BYTE orig_chrom_quant[64] = { |
| 249 |
17, 18, 24, 47, 99, 99, 99, 99, |
| 250 |
18, 21, 26, 66, 99, 99, 99, 99, |
| 251 |
24, 26, 56, 99, 99, 99, 99, 99, |
| 252 |
47, 66, 99, 99, 99, 99, 99, 99, |
| 253 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 254 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 255 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 256 |
99, 99, 99, 99, 99, 99, 99, 99 |
| 257 |
}; |
| 258 |
|
| 259 |
#endif |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
static const BYTE orig_lum_quant[64] = { |
| 269 |
#if 0 |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
10, 10, 10, 14, 12, 10, 16, 14, |
| 275 |
#else |
| 276 |
16, 11, 12, 14, 12, 10, 16, 14, |
| 277 |
#endif |
| 278 |
13, 14, 18, 17, 16, 19, 24, 40, |
| 279 |
26, 24, 22, 22, 24, 49, 35, 37, |
| 280 |
29, 40, 58, 51, 61, 60, 57, 51, |
| 281 |
56, 55, 64, 72, 92, 78, 64, 68, |
| 282 |
87, 69, 55, 56, 80, 109, 81, 87, |
| 283 |
95, 98, 103, 104, 103, 62, 77, 113, |
| 284 |
121, 112, 100, 120, 92, 101, 103, 99 |
| 285 |
}; |
| 286 |
|
| 287 |
|
| 288 |
static const BYTE orig_chrom_quant[64] = { |
| 289 |
#if 0 |
| 290 |
10, 14, 14, 24, 21, 24, 47, 26, |
| 291 |
#else |
| 292 |
17, 18, 18, 24, 21, 24, 47, 26, |
| 293 |
#endif |
| 294 |
26, 47, 99, 66, 56, 66, 99, 99, |
| 295 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 296 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 297 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 298 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 299 |
99, 99, 99, 99, 99, 99, 99, 99, |
| 300 |
99, 99, 99, 99, 99, 99, 99, 99 |
| 301 |
}; |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
static const BYTE codesize_array[256] = { |
| 311 |
0, |
| 312 |
1, |
| 313 |
2, 2, |
| 314 |
3, 3, 3, 3, |
| 315 |
4, 4, 4, 4, 4, 4, 4, 4, |
| 316 |
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
| 317 |
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 318 |
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
| 319 |
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 320 |
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 321 |
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 322 |
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
| 323 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 324 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 325 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 326 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 327 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 328 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 329 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
| 330 |
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 |
| 331 |
}; |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
static const BYTE lum_DC_counts[16] = { |
| 342 |
0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 343 |
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 344 |
}; |
| 345 |
|
| 346 |
static const BYTE lum_DC_values[12] = { |
| 347 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b |
| 348 |
}; |
| 349 |
|
| 350 |
static const BYTE chrom_DC_counts[16] = { |
| 351 |
0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 352 |
0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 353 |
}; |
| 354 |
|
| 355 |
static const BYTE chrom_DC_values[12] = { |
| 356 |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b |
| 357 |
}; |
| 358 |
|
| 359 |
static const BYTE lum_AC_counts[16] = { |
| 360 |
0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, |
| 361 |
0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7d |
| 362 |
}; |
| 363 |
|
| 364 |
static const BYTE lum_AC_counts_Denali[16] = { |
| 365 |
0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03, |
| 366 |
0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x00, 0x7e |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
}; |
| 378 |
|
| 379 |
static const BYTE lum_AC_values[162] = { |
| 380 |
0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, |
| 381 |
0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, |
| 382 |
0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, |
| 383 |
0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0, |
| 384 |
0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, |
| 385 |
0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, |
| 386 |
0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, |
| 387 |
0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, |
| 388 |
0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, |
| 389 |
0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, |
| 390 |
0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, |
| 391 |
0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, |
| 392 |
0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, |
| 393 |
0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, |
| 394 |
0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, |
| 395 |
0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, |
| 396 |
0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, |
| 397 |
0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, |
| 398 |
0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, |
| 399 |
0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, |
| 400 |
0xf9, 0xfa |
| 401 |
}; |
| 402 |
|
| 403 |
static const BYTE chrom_AC_counts[16] = { |
| 404 |
0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04, |
| 405 |
0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77 |
| 406 |
}; |
| 407 |
|
| 408 |
static const BYTE chrom_AC_values[162] = { |
| 409 |
0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, |
| 410 |
0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71, |
| 411 |
0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, |
| 412 |
0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0, |
| 413 |
0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, |
| 414 |
0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, |
| 415 |
0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, |
| 416 |
0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, |
| 417 |
0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, |
| 418 |
0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, |
| 419 |
0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, |
| 420 |
0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 421 |
0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, |
| 422 |
0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, |
| 423 |
0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, |
| 424 |
0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, |
| 425 |
0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, |
| 426 |
0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, |
| 427 |
0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, |
| 428 |
0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, |
| 429 |
0xf9, 0xfa |
| 430 |
}; |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
typedef struct { |
| 441 |
WORD code; |
| 442 |
BYTE size; |
| 443 |
} huff_elem_t; |
| 444 |
|
| 445 |
|
| 446 |
static const huff_elem_t lum_DC_table[] = { |
| 447 |
{ 0x0000, 2 }, { 0x0002, 3 }, { 0x0003, 3 }, { 0x0004, 3 }, |
| 448 |
{ 0x0005, 3 }, { 0x0006, 3 }, { 0x000e, 4 }, { 0x001e, 5 }, |
| 449 |
{ 0x003e, 6 }, { 0x007e, 7 }, { 0x00fe, 8 }, { 0x01fe, 9 }, |
| 450 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 451 |
{ 0x0000, 0 }, }; |
| 452 |
|
| 453 |
|
| 454 |
static const huff_elem_t lum_AC_table[] = { |
| 455 |
{ 0x000a, 4 }, { 0x0000, 2 }, { 0x0001, 2 }, { 0x0004, 3 }, |
| 456 |
{ 0x000b, 4 }, { 0x001a, 5 }, { 0x0078, 7 }, { 0x00f8, 8 }, |
| 457 |
{ 0x03f6, 10 }, { 0xff82, 16 }, { 0xff83, 16 }, { 0x0000, 0 }, |
| 458 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 459 |
{ 0x0000, 0 }, { 0x000c, 4 }, { 0x001b, 5 }, { 0x0079, 7 }, |
| 460 |
{ 0x01f6, 9 }, { 0x07f6, 11 }, { 0xff84, 16 }, { 0xff85, 16 }, |
| 461 |
{ 0xff86, 16 }, { 0xff87, 16 }, { 0xff88, 16 }, { 0x0000, 0 }, |
| 462 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 463 |
{ 0x0000, 0 }, { 0x001c, 5 }, { 0x00f9, 8 }, { 0x03f7, 10 }, |
| 464 |
{ 0x0ff4, 12 }, { 0xff89, 16 }, { 0xff8a, 16 }, { 0xff8b, 16 }, |
| 465 |
{ 0xff8c, 16 }, { 0xff8d, 16 }, { 0xff8e, 16 }, { 0x0000, 0 }, |
| 466 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 467 |
{ 0x0000, 0 }, { 0x003a, 6 }, { 0x01f7, 9 }, { 0x0ff5, 12 }, |
| 468 |
{ 0xff8f, 16 }, { 0xff90, 16 }, { 0xff91, 16 }, { 0xff92, 16 }, |
| 469 |
{ 0xff93, 16 }, { 0xff94, 16 }, { 0xff95, 16 }, { 0x0000, 0 }, |
| 470 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 471 |
{ 0x0000, 0 }, { 0x003b, 6 }, { 0x03f8, 10 }, { 0xff96, 16 }, |
| 472 |
{ 0xff97, 16 }, { 0xff98, 16 }, { 0xff99, 16 }, { 0xff9a, 16 }, |
| 473 |
{ 0xff9b, 16 }, { 0xff9c, 16 }, { 0xff9d, 16 }, { 0x0000, 0 }, |
| 474 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 475 |
{ 0x0000, 0 }, { 0x007a, 7 }, { 0x07f7, 11 }, { 0xff9e, 16 }, |
| 476 |
{ 0xff9f, 16 }, { 0xffa0, 16 }, { 0xffa1, 16 }, { 0xffa2, 16 }, |
| 477 |
{ 0xffa3, 16 }, { 0xffa4, 16 }, { 0xffa5, 16 }, { 0x0000, 0 }, |
| 478 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 479 |
{ 0x0000, 0 }, { 0x007b, 7 }, { 0x0ff6, 12 }, { 0xffa6, 16 }, |
| 480 |
{ 0xffa7, 16 }, { 0xffa8, 16 }, { 0xffa9, 16 }, { 0xffaa, 16 }, |
| 481 |
{ 0xffab, 16 }, { 0xffac, 16 }, { 0xffad, 16 }, { 0x0000, 0 }, |
| 482 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 483 |
{ 0x0000, 0 }, { 0x00fa, 8 }, { 0x0ff7, 12 }, { 0xffae, 16 }, |
| 484 |
{ 0xffaf, 16 }, { 0xffb0, 16 }, { 0xffb1, 16 }, { 0xffb2, 16 }, |
| 485 |
{ 0xffb3, 16 }, { 0xffb4, 16 }, { 0xffb5, 16 }, { 0x0000, 0 }, |
| 486 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 487 |
{ 0x0000, 0 }, { 0x01f8, 9 }, { 0x7fc0, 15 }, { 0xffb6, 16 }, |
| 488 |
{ 0xffb7, 16 }, { 0xffb8, 16 }, { 0xffb9, 16 }, { 0xffba, 16 }, |
| 489 |
{ 0xffbb, 16 }, { 0xffbc, 16 }, { 0xffbd, 16 }, { 0x0000, 0 }, |
| 490 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 491 |
{ 0x0000, 0 }, { 0x01f9, 9 }, { 0xffbe, 16 }, { 0xffbf, 16 }, |
| 492 |
{ 0xffc0, 16 }, { 0xffc1, 16 }, { 0xffc2, 16 }, { 0xffc3, 16 }, |
| 493 |
{ 0xffc4, 16 }, { 0xffc5, 16 }, { 0xffc6, 16 }, { 0x0000, 0 }, |
| 494 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 495 |
{ 0x0000, 0 }, { 0x01fa, 9 }, { 0xffc7, 16 }, { 0xffc8, 16 }, |
| 496 |
{ 0xffc9, 16 }, { 0xffca, 16 }, { 0xffcb, 16 }, { 0xffcc, 16 }, |
| 497 |
{ 0xffcd, 16 }, { 0xffce, 16 }, { 0xffcf, 16 }, { 0x0000, 0 }, |
| 498 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 499 |
{ 0x0000, 0 }, { 0x03f9, 10 }, { 0xffd0, 16 }, { 0xffd1, 16 }, |
| 500 |
{ 0xffd2, 16 }, { 0xffd3, 16 }, { 0xffd4, 16 }, { 0xffd5, 16 }, |
| 501 |
{ 0xffd6, 16 }, { 0xffd7, 16 }, { 0xffd8, 16 }, { 0x0000, 0 }, |
| 502 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 503 |
{ 0x0000, 0 }, { 0x03fa, 10 }, { 0xffd9, 16 }, { 0xffda, 16 }, |
| 504 |
{ 0xffdb, 16 }, { 0xffdc, 16 }, { 0xffdd, 16 }, { 0xffde, 16 }, |
| 505 |
{ 0xffdf, 16 }, { 0xffe0, 16 }, { 0xffe1, 16 }, { 0x0000, 0 }, |
| 506 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 507 |
{ 0x0000, 0 }, { 0x07f8, 11 }, { 0xffe2, 16 }, { 0xffe3, 16 }, |
| 508 |
{ 0xffe4, 16 }, { 0xffe5, 16 }, { 0xffe6, 16 }, { 0xffe7, 16 }, |
| 509 |
{ 0xffe8, 16 }, { 0xffe9, 16 }, { 0xffea, 16 }, { 0x0000, 0 }, |
| 510 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 511 |
{ 0x0000, 0 }, { 0xffeb, 16 }, { 0xffec, 16 }, { 0xffed, 16 }, |
| 512 |
{ 0xffee, 16 }, { 0xffef, 16 }, { 0xfff0, 16 }, { 0xfff1, 16 }, |
| 513 |
{ 0xfff2, 16 }, { 0xfff3, 16 }, { 0xfff4, 16 }, { 0x0000, 0 }, |
| 514 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 515 |
{ 0x07f9, 11 }, { 0xfff5, 16 }, { 0xfff6, 16 }, { 0xfff7, 16 }, |
| 516 |
{ 0xfff8, 16 }, { 0xfff9, 16 }, { 0xfffa, 16 }, { 0xfffb, 16 }, |
| 517 |
{ 0xfffc, 16 }, { 0xfffd, 16 }, { 0xfffe, 16 }, { 0x0000, 0 }, |
| 518 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 519 |
}; |
| 520 |
|
| 521 |
|
| 522 |
static const huff_elem_t lum_AC_table_Denali[] = { |
| 523 |
{ 0x000a, 4 }, { 0x0000, 2 }, { 0x0001, 2 }, { 0x0004, 3 }, |
| 524 |
{ 0x000b, 4 }, { 0x001a, 5 }, { 0x0078, 7 }, { 0x00f8, 8 }, |
| 525 |
{ 0x03f6, 10 }, { 0xff81, 16 }, { 0xff82, 16 }, { 0x0000, 0 }, |
| 526 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 527 |
{ 0x0000, 0 }, { 0x000c, 4 }, { 0x001b, 5 }, { 0x0079, 7 }, |
| 528 |
{ 0x01f6, 9 }, { 0x07f6, 11 }, { 0xff83, 16 }, { 0xff84, 16 }, |
| 529 |
{ 0xff85, 16 }, { 0xff86, 16 }, { 0xff87, 16 }, { 0x0000, 0 }, |
| 530 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 531 |
{ 0x0000, 0 }, { 0x001c, 5 }, { 0x00f9, 8 }, { 0x03f7, 10 }, |
| 532 |
{ 0x0ff4, 12 }, { 0xff88, 16 }, { 0xff89, 16 }, { 0xff8a, 16 }, |
| 533 |
{ 0xff8b, 16 }, { 0xff8c, 16 }, { 0xff8d, 16 }, { 0x0000, 0 }, |
| 534 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 535 |
{ 0x0000, 0 }, { 0x003a, 6 }, { 0x01f7, 9 }, { 0x0ff5, 12 }, |
| 536 |
{ 0xff8e, 16 }, { 0xff8f, 16 }, { 0xff90, 16 }, { 0xff91, 16 }, |
| 537 |
{ 0xff92, 16 }, { 0xff93, 16 }, { 0xff94, 16 }, { 0x0000, 0 }, |
| 538 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 539 |
{ 0x0000, 0 }, { 0x003b, 6 }, { 0x03f8, 10 }, { 0xff95, 16 }, |
| 540 |
{ 0xff96, 16 }, { 0xff97, 16 }, { 0xff98, 16 }, { 0xff99, 16 }, |
| 541 |
{ 0xff9a, 16 }, { 0xff9b, 16 }, { 0xff9c, 16 }, { 0x0000, 0 }, |
| 542 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 543 |
{ 0x0000, 0 }, { 0x007a, 7 }, { 0x07f7, 11 }, { 0xff9d, 16 }, |
| 544 |
{ 0xff9e, 16 }, { 0xff9f, 16 }, { 0xffa0, 16 }, { 0xffa1, 16 }, |
| 545 |
{ 0xffa2, 16 }, { 0xffa3, 16 }, { 0xffa4, 16 }, { 0x0000, 0 }, |
| 546 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 547 |
{ 0x0000, 0 }, { 0x007b, 7 }, { 0x0ff6, 12 }, { 0xffa5, 16 }, |
| 548 |
{ 0xffa6, 16 }, { 0xffa7, 16 }, { 0xffa8, 16 }, { 0xffa9, 16 }, |
| 549 |
{ 0xffaa, 16 }, { 0xffab, 16 }, { 0xffac, 16 }, { 0x0000, 0 }, |
| 550 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 551 |
{ 0x0000, 0 }, { 0x00fa, 8 }, { 0x0ff7, 12 }, { 0xffad, 16 }, |
| 552 |
{ 0xffae, 16 }, { 0xffaf, 16 }, { 0xffb0, 16 }, { 0xffb1, 16 }, |
| 553 |
{ 0xffb2, 16 }, { 0xffb3, 16 }, { 0xffb4, 16 }, { 0x0000, 0 }, |
| 554 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 555 |
{ 0x0000, 0 }, { 0x01f8, 9 }, { 0xff80, 16 }, { 0xffb5, 16 }, |
| 556 |
{ 0xffb6, 16 }, { 0xffb7, 16 }, { 0xffb8, 16 }, { 0xffb9, 16 }, |
| 557 |
{ 0xffba, 16 }, { 0xffbb, 16 }, { 0xffbc, 16 }, { 0x0000, 0 }, |
| 558 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 559 |
{ 0x0000, 0 }, { 0x01f9, 9 }, { 0xffbd, 16 }, { 0xffbe, 16 }, |
| 560 |
{ 0xffbf, 16 }, { 0xffc0, 16 }, { 0xffc1, 16 }, { 0xffc2, 16 }, |
| 561 |
{ 0xffc3, 16 }, { 0xffc4, 16 }, { 0xffc5, 16 }, { 0x0000, 0 }, |
| 562 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 563 |
{ 0x0000, 0 }, { 0x01fa, 9 }, { 0xffc6, 16 }, { 0xffc7, 16 }, |
| 564 |
{ 0xffc8, 16 }, { 0xffc9, 16 }, { 0xffca, 16 }, { 0xffcb, 16 }, |
| 565 |
{ 0xffcc, 16 }, { 0xffcd, 16 }, { 0xffce, 16 }, { 0x0000, 0 }, |
| 566 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 567 |
{ 0x0000, 0 }, { 0x03f9, 10 }, { 0xffcf, 16 }, { 0xffd0, 16 }, |
| 568 |
{ 0xffd1, 16 }, { 0xffd2, 16 }, { 0xffd3, 16 }, { 0xffd4, 16 }, |
| 569 |
{ 0xffd5, 16 }, { 0xffd6, 16 }, { 0xffd7, 16 }, { 0x0000, 0 }, |
| 570 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 571 |
{ 0x0000, 0 }, { 0x03fa, 10 }, { 0xffd8, 16 }, { 0xffd9, 16 }, |
| 572 |
{ 0xffda, 16 }, { 0xffdb, 16 }, { 0xffdc, 16 }, { 0xffdd, 16 }, |
| 573 |
{ 0xffde, 16 }, { 0xffdf, 16 }, { 0xffe0, 16 }, { 0x0000, 0 }, |
| 574 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 575 |
{ 0x0000, 0 }, { 0x07f8, 11 }, { 0xffe1, 16 }, { 0xffe2, 16 }, |
| 576 |
{ 0xffe3, 16 }, { 0xffe4, 16 }, { 0xffe5, 16 }, { 0xffe6, 16 }, |
| 577 |
{ 0xffe7, 16 }, { 0xffe8, 16 }, { 0xffe9, 16 }, { 0x0000, 0 }, |
| 578 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 579 |
{ 0x0000, 0 }, { 0xffea, 16 }, { 0xffeb, 16 }, { 0xffec, 16 }, |
| 580 |
{ 0xffed, 16 }, { 0xffee, 16 }, { 0xffef, 16 }, { 0xfff0, 16 }, |
| 581 |
{ 0xfff1, 16 }, { 0xfff2, 16 }, { 0xfff3, 16 }, { 0x0000, 0 }, |
| 582 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 583 |
{ 0x07f9, 11 }, { 0xfff4, 16 }, { 0xfff5, 16 }, { 0xfff6, 16 }, |
| 584 |
{ 0xfff7, 16 }, { 0xfff8, 16 }, { 0xfff9, 16 }, { 0xfffa, 16 }, |
| 585 |
{ 0xfffb, 16 }, { 0xfffc, 16 }, { 0xfffd, 16 }, { 0x0000, 0 }, |
| 586 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 587 |
}; |
| 588 |
|
| 589 |
|
| 590 |
static const huff_elem_t chrom_DC_table[] = { |
| 591 |
{ 0x0000, 2 }, { 0x0001, 2 }, { 0x0002, 2 }, { 0x0006, 3 }, |
| 592 |
{ 0x000e, 4 }, { 0x001e, 5 }, { 0x003e, 6 }, { 0x007e, 7 }, |
| 593 |
{ 0x00fe, 8 }, { 0x01fe, 9 }, { 0x03fe, 10 }, { 0x07fe, 11 }, |
| 594 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 595 |
{ 0x0000, 0 }, }; |
| 596 |
|
| 597 |
|
| 598 |
static const huff_elem_t chrom_AC_table[] = { |
| 599 |
{ 0x0000, 2 }, { 0x0001, 2 }, { 0x0004, 3 }, { 0x000a, 4 }, |
| 600 |
{ 0x0018, 5 }, { 0x0019, 5 }, { 0x0038, 6 }, { 0x0078, 7 }, |
| 601 |
{ 0x01f4, 9 }, { 0x03f6, 10 }, { 0x0ff4, 12 }, { 0x0000, 0 }, |
| 602 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 603 |
{ 0x0000, 0 }, { 0x000b, 4 }, { 0x0039, 6 }, { 0x00f6, 8 }, |
| 604 |
{ 0x01f5, 9 }, { 0x07f6, 11 }, { 0x0ff5, 12 }, { 0xff88, 16 }, |
| 605 |
{ 0xff89, 16 }, { 0xff8a, 16 }, { 0xff8b, 16 }, { 0x0000, 0 }, |
| 606 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 607 |
{ 0x0000, 0 }, { 0x001a, 5 }, { 0x00f7, 8 }, { 0x03f7, 10 }, |
| 608 |
{ 0x0ff6, 12 }, { 0x7fc2, 15 }, { 0xff8c, 16 }, { 0xff8d, 16 }, |
| 609 |
{ 0xff8e, 16 }, { 0xff8f, 16 }, { 0xff90, 16 }, { 0x0000, 0 }, |
| 610 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 611 |
{ 0x0000, 0 }, { 0x001b, 5 }, { 0x00f8, 8 }, { 0x03f8, 10 }, |
| 612 |
{ 0x0ff7, 12 }, { 0xff91, 16 }, { 0xff92, 16 }, { 0xff93, 16 }, |
| 613 |
{ 0xff94, 16 }, { 0xff95, 16 }, { 0xff96, 16 }, { 0x0000, 0 }, |
| 614 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 615 |
{ 0x0000, 0 }, { 0x003a, 6 }, { 0x01f6, 9 }, { 0xff97, 16 }, |
| 616 |
{ 0xff98, 16 }, { 0xff99, 16 }, { 0xff9a, 16 }, { 0xff9b, 16 }, |
| 617 |
{ 0xff9c, 16 }, { 0xff9d, 16 }, { 0xff9e, 16 }, { 0x0000, 0 }, |
| 618 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 619 |
{ 0x0000, 0 }, { 0x003b, 6 }, { 0x03f9, 10 }, { 0xff9f, 16 }, |
| 620 |
{ 0xffa0, 16 }, { 0xffa1, 16 }, { 0xffa2, 16 }, { 0xffa3, 16 }, |
| 621 |
{ 0xffa4, 16 }, { 0xffa5, 16 }, { 0xffa6, 16 }, { 0x0000, 0 }, |
| 622 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 623 |
{ 0x0000, 0 }, { 0x0079, 7 }, { 0x07f7, 11 }, { 0xffa7, 16 }, |
| 624 |
{ 0xffa8, 16 }, { 0xffa9, 16 }, { 0xffaa, 16 }, { 0xffab, 16 }, |
| 625 |
{ 0xffac, 16 }, { 0xffad, 16 }, { 0xffae, 16 }, { 0x0000, 0 }, |
| 626 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 627 |
{ 0x0000, 0 }, { 0x007a, 7 }, { 0x07f8, 11 }, { 0xffaf, 16 }, |
| 628 |
{ 0xffb0, 16 }, { 0xffb1, 16 }, { 0xffb2, 16 }, { 0xffb3, 16 }, |
| 629 |
{ 0xffb4, 16 }, { 0xffb5, 16 }, { 0xffb6, 16 }, { 0x0000, 0 }, |
| 630 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 631 |
{ 0x0000, 0 }, { 0x00f9, 8 }, { 0xffb7, 16 }, { 0xffb8, 16 }, |
| 632 |
{ 0xffb9, 16 }, { 0xffba, 16 }, { 0xffbb, 16 }, { 0xffbc, 16 }, |
| 633 |
{ 0xffbd, 16 }, { 0xffbe, 16 }, { 0xffbf, 16 }, { 0x0000, 0 }, |
| 634 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 635 |
{ 0x0000, 0 }, { 0x01f7, 9 }, { 0xffc0, 16 }, { 0xffc1, 16 }, |
| 636 |
{ 0xffc2, 16 }, { 0xffc3, 16 }, { 0xffc4, 16 }, { 0xffc5, 16 }, |
| 637 |
{ 0xffc6, 16 }, { 0xffc7, 16 }, { 0xffc8, 16 }, { 0x0000, 0 }, |
| 638 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 639 |
{ 0x0000, 0 }, { 0x01f8, 9 }, { 0xffc9, 16 }, { 0xffca, 16 }, |
| 640 |
{ 0xffcb, 16 }, { 0xffcc, 16 }, { 0xffcd, 16 }, { 0xffce, 16 }, |
| 641 |
{ 0xffcf, 16 }, { 0xffd0, 16 }, { 0xffd1, 16 }, { 0x0000, 0 }, |
| 642 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 643 |
{ 0x0000, 0 }, { 0x01f9, 9 }, { 0xffd2, 16 }, { 0xffd3, 16 }, |
| 644 |
{ 0xffd4, 16 }, { 0xffd5, 16 }, { 0xffd6, 16 }, { 0xffd7, 16 }, |
| 645 |
{ 0xffd8, 16 }, { 0xffd9, 16 }, { 0xffda, 16 }, { 0x0000, 0 }, |
| 646 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 647 |
{ 0x0000, 0 }, { 0x01fa, 9 }, { 0xffdb, 16 }, { 0xffdc, 16 }, |
| 648 |
{ 0xffdd, 16 }, { 0xffde, 16 }, { 0xffdf, 16 }, { 0xffe0, 16 }, |
| 649 |
{ 0xffe1, 16 }, { 0xffe2, 16 }, { 0xffe3, 16 }, { 0x0000, 0 }, |
| 650 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 651 |
{ 0x0000, 0 }, { 0x07f9, 11 }, { 0xffe4, 16 }, { 0xffe5, 16 }, |
| 652 |
{ 0xffe6, 16 }, { 0xffe7, 16 }, { 0xffe8, 16 }, { 0xffe9, 16 }, |
| 653 |
{ 0xffea, 16 }, { 0xffeb, 16 }, { 0xffec, 16 }, { 0x0000, 0 }, |
| 654 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 655 |
{ 0x0000, 0 }, { 0x3fe0, 14 }, { 0xffed, 16 }, { 0xffee, 16 }, |
| 656 |
{ 0xffef, 16 }, { 0xfff0, 16 }, { 0xfff1, 16 }, { 0xfff2, 16 }, |
| 657 |
{ 0xfff3, 16 }, { 0xfff4, 16 }, { 0xfff5, 16 }, { 0x0000, 0 }, |
| 658 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 659 |
{ 0x03fa, 10 }, { 0x7fc3, 15 }, { 0xfff6, 16 }, { 0xfff7, 16 }, |
| 660 |
{ 0xfff8, 16 }, { 0xfff9, 16 }, { 0xfffa, 16 }, { 0xfffb, 16 }, |
| 661 |
{ 0xfffc, 16 }, { 0xfffd, 16 }, { 0xfffe, 16 }, { 0x0000, 0 }, |
| 662 |
{ 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, { 0x0000, 0 }, |
| 663 |
}; |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
#define INITIAL_BITS_AVAIL (8*sizeof(DWORD)) |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
#define PUT_BYTE_STUFF(g, pbs_byte_expression) { \ |
| 707 |
BYTE pbs_byte; \ |
| 708 |
\ |
| 709 |
pbs_byte = (BYTE)(pbs_byte_expression); \ |
| 710 |
*(g->write_buf_next)++ = pbs_byte; \ |
| 711 |
if (pbs_byte == (BYTE)0xff) \ |
| 712 |
*(g->write_buf_next)++ = 0; \ |
| 713 |
} |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
static void write_init (PJENC_INST g) |
| 723 |
{ |
| 724 |
g->wr_bits_avail = INITIAL_BITS_AVAIL; |
| 725 |
g->wr_bit_buf = 0; |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
static void write_buf_open (PJENC_INST g, BYTE *buf_p) |
| 739 |
{ |
| 740 |
g->wr_outbuf_beg = g->write_buf_next = buf_p; |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
static int write_buf_close (PJENC_INST g) |
| 754 |
{ |
| 755 |
return g->write_buf_next - g->wr_outbuf_beg; |
| 756 |
} |
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
#define WRITE_BITS_OPEN(g) \ |
| 771 |
int tmp_bits_avail = g->wr_bits_avail; \ |
| 772 |
DWORD tmp_bit_buf = g->wr_bit_buf; |
| 773 |
|
| 774 |
|
| 775 |
#define WRITE_BITS_HIZERO(g,wb_value,wb_nbits) { \ |
| 776 |
DWORD bits_loc; \ |
| 777 |
int length_loc; \ |
| 778 |
\ |
| 779 |
length_loc = (int)(wb_nbits); \ |
| 780 |
bits_loc = (DWORD)(wb_value); \ |
| 781 |
\ |
| 782 |
if (length_loc > tmp_bits_avail) { \ |
| 783 |
do { \ |
| 784 |
PUT_BYTE_STUFF (g, tmp_bit_buf >> 24) \ |
| 785 |
tmp_bit_buf <<= 8; \ |
| 786 |
tmp_bits_avail += 8; \ |
| 787 |
} while (tmp_bits_avail <= 24); \ |
| 788 |
} \ |
| 789 |
\ |
| 790 |
tmp_bits_avail -= length_loc; \ |
| 791 |
tmp_bit_buf |= bits_loc << tmp_bits_avail; \ |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
#define WRITE_BITS(g,wb_value,wb_nbits) { \ |
| 796 |
int len_loc; \ |
| 797 |
\ |
| 798 |
len_loc = (int)(wb_nbits); \ |
| 799 |
WRITE_BITS_HIZERO (g, (DWORD )(wb_value) & ((1ul<<len_loc)-1), len_loc) \ |
| 800 |
} |
| 801 |
|
| 802 |
|
| 803 |
#define WRITE_BITS_CLOSE(g) { \ |
| 804 |
g->wr_bits_avail = tmp_bits_avail; \ |
| 805 |
g->wr_bit_buf = tmp_bit_buf; \ |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
static void write_bits_flush (PJENC_INST g) |
| 819 |
{ |
| 820 |
int bits_used; |
| 821 |
|
| 822 |
if (g->wr_bits_avail != INITIAL_BITS_AVAIL) { |
| 823 |
|
| 824 |
g->wr_bit_buf |= ((DWORD )1 << g->wr_bits_avail) - 1; |
| 825 |
|
| 826 |
for (bits_used = INITIAL_BITS_AVAIL - g->wr_bits_avail; |
| 827 |
bits_used > 0; |
| 828 |
bits_used -= 8) { |
| 829 |
PUT_BYTE_STUFF (g, g->wr_bit_buf >> 24) |
| 830 |
g->wr_bit_buf <<= 8; |
| 831 |
} |
| 832 |
|
| 833 |
g->wr_bits_avail = INITIAL_BITS_AVAIL; |
| 834 |
g->wr_bit_buf = 0; |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
#define PUT_MARKER(g,marker) \ |
| 858 |
do { \ |
| 859 |
*(g->write_buf_next)++ = 0xff; \ |
| 860 |
*(g->write_buf_next)++ = (BYTE)marker; \ |
| 861 |
} while (0) |
| 862 |
|
| 863 |
|
| 864 |
#define PUT_INT(g,value) \ |
| 865 |
do { \ |
| 866 |
unsigned loc_val = (unsigned)(value); \ |
| 867 |
*(g->write_buf_next)++ = loc_val >> 8; \ |
| 868 |
*(g->write_buf_next)++ = loc_val & 0xff; \ |
| 869 |
} while (0) |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
static void em_write_SOI (PJENC_INST g) |
| 879 |
{ |
| 880 |
PUT_MARKER(g, MARKER_SOI); |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
static void em_write_EOI (PJENC_INST g) |
| 890 |
{ |
| 891 |
PUT_MARKER(g, MARKER_EOI); |
| 892 |
} |
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
static void em_write_JFIF_APP0 ( |
| 901 |
PJENC_INST g, |
| 902 |
int xRes, |
| 903 |
int yRes) |
| 904 |
{ |
| 905 |
PUT_MARKER (g, MARKER_APP+0); |
| 906 |
PUT_INT (g, 16); |
| 907 |
|
| 908 |
|
| 909 |
*(g->write_buf_next)++ = 'J'; |
| 910 |
*(g->write_buf_next)++ = 'F'; |
| 911 |
*(g->write_buf_next)++ = 'I'; |
| 912 |
*(g->write_buf_next)++ = 'F'; |
| 913 |
*(g->write_buf_next)++ = '\0'; |
| 914 |
|
| 915 |
|
| 916 |
*(g->write_buf_next)++ = 0x01; |
| 917 |
*(g->write_buf_next)++ = 0x00; |
| 918 |
|
| 919 |
|
| 920 |
*(g->write_buf_next)++ = 0x01; |
| 921 |
|
| 922 |
PUT_INT(g, xRes); |
| 923 |
PUT_INT(g, yRes); |
| 924 |
|
| 925 |
|
| 926 |
*(g->write_buf_next)++ = 0x00; |
| 927 |
*(g->write_buf_next)++ = 0x00; |
| 928 |
} |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
static void em_write_G3_APP1 ( |
| 937 |
PJENC_INST g, |
| 938 |
int res) |
| 939 |
{ |
| 940 |
res = ((res+50)/100)*100; |
| 941 |
|
| 942 |
PUT_MARKER (g, MARKER_APP+1); |
| 943 |
PUT_INT (g, 12); |
| 944 |
|
| 945 |
|
| 946 |
*(g->write_buf_next)++ = 'G'; |
| 947 |
*(g->write_buf_next)++ = '3'; |
| 948 |
*(g->write_buf_next)++ = 'F'; |
| 949 |
*(g->write_buf_next)++ = 'A'; |
| 950 |
*(g->write_buf_next)++ = 'X'; |
| 951 |
*(g->write_buf_next)++ = 0; |
| 952 |
|
| 953 |
PUT_INT (g, 1994); |
| 954 |
PUT_INT (g, res); |
| 955 |
} |
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
static void em_write_SOF ( |
| 964 |
PJENC_INST g, |
| 965 |
int width, |
| 966 |
int height, |
| 967 |
int ncomps, |
| 968 |
BYTE h_sam_facs[], |
| 969 |
BYTE v_sam_facs[]) |
| 970 |
{ |
| 971 |
int i; |
| 972 |
|
| 973 |
PUT_MARKER(g, MARKER_SOF0); |
| 974 |
PUT_INT(g, 8 + ncomps*3); |
| 975 |
*(g->write_buf_next)++ = 8; |
| 976 |
PUT_INT(g, height); |
| 977 |
PUT_INT(g, width); |
| 978 |
*(g->write_buf_next)++ = ncomps; |
| 979 |
|
| 980 |
for (i=0; i<ncomps; i++) { |
| 981 |
*(g->write_buf_next)++ = i; |
| 982 |
*(g->write_buf_next)++ = h_sam_facs[i]<<4 | v_sam_facs[i]; |
| 983 |
*(g->write_buf_next)++ = (i==0 ? 0 : 1); |
| 984 |
} |
| 985 |
} |
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
static void em_write_DQT ( |
| 994 |
PJENC_INST g, |
| 995 |
int precision, |
| 996 |
int ident, |
| 997 |
BYTE elements[64]) |
| 998 |
{ |
| 999 |
PUT_MARKER(g, MARKER_DQT); |
| 1000 |
PUT_INT(g, 67); |
| 1001 |
*(g->write_buf_next)++ = (precision << 4) + ident; |
| 1002 |
memcpy (g->write_buf_next, elements, 64); |
| 1003 |
g->write_buf_next += 64; |
| 1004 |
} |
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
static void em_write_DHTs ( |
| 1013 |
PJENC_INST g, |
| 1014 |
int ntables, |
| 1015 |
BYTE hclass[], |
| 1016 |
BYTE ident[], |
| 1017 |
const BYTE *counts[], |
| 1018 |
const BYTE *huffval[]) |
| 1019 |
{ |
| 1020 |
int nvals, i, j; |
| 1021 |
|
| 1022 |
nvals = 0; |
| 1023 |
for (i=0; i<ntables; i++) { |
| 1024 |
for (j=0; j<16; j++) |
| 1025 |
nvals += counts[i][j]; |
| 1026 |
} |
| 1027 |
|
| 1028 |
PUT_MARKER(g, MARKER_DHT); |
| 1029 |
PUT_INT(g, 2 + 17*ntables + nvals); |
| 1030 |
|
| 1031 |
for (i=0; i<ntables; i++) { |
| 1032 |
for (nvals=j=0; j<16; j++) |
| 1033 |
nvals += counts[i][j]; |
| 1034 |
|
| 1035 |
*(g->write_buf_next)++ = hclass[i]<<4 | ident[i]; |
| 1036 |
for (j=0; j<16; j++) *(g->write_buf_next)++ = counts[i][j]; |
| 1037 |
for (j=0; j<nvals; j++) *(g->write_buf_next)++ = huffval[i][j]; |
| 1038 |
} |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
static void em_write_SOS ( |
| 1048 |
PJENC_INST g, |
| 1049 |
int ncomps) |
| 1050 |
{ |
| 1051 |
int i; |
| 1052 |
|
| 1053 |
PUT_MARKER(g, MARKER_SOS); |
| 1054 |
PUT_INT(g, 6 + 2*ncomps); |
| 1055 |
*(g->write_buf_next)++ = ncomps; |
| 1056 |
|
| 1057 |
for (i=0; i<ncomps; i++) { |
| 1058 |
*(g->write_buf_next)++ = i; |
| 1059 |
*(g->write_buf_next)++ = (i==0 ? 0x00 : 0x11); |
| 1060 |
} |
| 1061 |
|
| 1062 |
*(g->write_buf_next)++ = 0; |
| 1063 |
*(g->write_buf_next)++ = 63; |
| 1064 |
*(g->write_buf_next)++ = 0; |
| 1065 |
} |
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
static void em_write_DNL ( |
| 1074 |
PJENC_INST g, |
| 1075 |
int nlines) |
| 1076 |
{ |
| 1077 |
PUT_MARKER(g, MARKER_DNL); |
| 1078 |
PUT_INT(g, 4); |
| 1079 |
PUT_INT(g, nlines); |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
static void em_write_short_header ( |
| 1094 |
PJENC_INST g, |
| 1095 |
UINT rows_in_page, |
| 1096 |
UINT pixels_in_row, |
| 1097 |
UINT xRes, |
| 1098 |
UINT yRes, |
| 1099 |
UINT dc_q_factor, |
| 1100 |
UINT ac_q_factor, |
| 1101 |
UINT comps_in_pixel, |
| 1102 |
DWORD sample_factors) |
| 1103 |
{ |
| 1104 |
PUT_MARKER (g, MARKER_SHORT_HEADER); |
| 1105 |
PUT_INT (g, 18); |
| 1106 |
PUT_INT (g, rows_in_page); |
| 1107 |
PUT_INT (g, pixels_in_row); |
| 1108 |
PUT_INT (g, xRes); |
| 1109 |
PUT_INT (g, yRes); |
| 1110 |
*(g->write_buf_next)++ = ac_q_factor * 5 / 2; |
| 1111 |
*(g->write_buf_next)++ = comps_in_pixel; |
| 1112 |
PUT_INT (g, sample_factors >> 16); |
| 1113 |
PUT_INT (g, sample_factors & 0x0000ffffu); |
| 1114 |
*(g->write_buf_next)++ = dc_q_factor * 5 / 2; |
| 1115 |
*(g->write_buf_next)++ = 0; |
| 1116 |
} |
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
#define BITS_IN_DCT_FRAC 15 |
| 1131 |
#define ROUND(x) (((x)+(1l<<(BITS_IN_DCT_FRAC-1))) >> BITS_IN_DCT_FRAC) |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
#define a1 23170L |
| 1143 |
#define a2 17734L |
| 1144 |
#define a3 23170L |
| 1145 |
#define a4 42813L |
| 1146 |
#define a5 12540L |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
static float const wino_norm_tbl[] = { |
| 1156 |
0.125000f, 0.090120f, 0.090120f, 0.095671f, |
| 1157 |
0.064973f, 0.095671f, 0.106304f, 0.068975f, |
| 1158 |
0.068975f, 0.106304f, 0.125000f, 0.076641f, |
| 1159 |
0.073223f, 0.076641f, 0.125000f, 0.159095f, |
| 1160 |
0.090120f, 0.081361f, 0.081361f, 0.090120f, |
| 1161 |
0.159095f, 0.230970f, 0.114701f, 0.095671f, |
| 1162 |
0.090404f, 0.095671f, 0.114701f, 0.230970f, |
| 1163 |
0.453064f, 0.166520f, 0.121766f, 0.106304f, |
| 1164 |
0.106304f, 0.121766f, 0.166520f, 0.453064f, |
| 1165 |
0.326641f, 0.176777f, 0.135299f, 0.125000f, |
| 1166 |
0.135299f, 0.176777f, 0.326641f, 0.346760f, |
| 1167 |
0.196424f, 0.159095f, 0.159095f, 0.196424f, |
| 1168 |
0.346760f, 0.385299f, 0.230970f, 0.202489f, |
| 1169 |
0.230970f, 0.385299f, 0.453064f, 0.293969f, |
| 1170 |
0.293969f, 0.453064f, 0.576641f, 0.426777f, |
| 1171 |
0.576641f, 0.837153f, 0.837153f, 1.642134f |
| 1172 |
}; |
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
static void scale_for_wino ( |
| 1181 |
BYTE *in, |
| 1182 |
int *out, |
| 1183 |
int *thresh) |
| 1184 |
{ |
| 1185 |
#define FIX(x) ((long) ((x)*(1l<<BITS_IN_DCT_FRAC) + 0.5)) |
| 1186 |
float const *fptr; |
| 1187 |
int i, q; |
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
if (in[63] < 2) in[63] = 2; |
| 1195 |
|
| 1196 |
fptr = wino_norm_tbl; |
| 1197 |
for (i=0; i<64; i++) { |
| 1198 |
q = FIX (*fptr++ / (float)(*in++)); |
| 1199 |
*out++ = q; |
| 1200 |
if (q == 0) *thresh++ = 32767; |
| 1201 |
else *thresh++ = (1 << (BITS_IN_DCT_FRAC-1)) / q; |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
static const BYTE zigzag_index_table[64] = { |
| 1218 |
0, 1, 8, 16, 9, 2, 3, 10, |
| 1219 |
17, 24, 32, 25, 18, 11, 4, 5, |
| 1220 |
12, 19, 26, 33, 40, 48, 41, 34, |
| 1221 |
27, 20, 13, 6, 7, 14, 21, 28, |
| 1222 |
35, 42, 49, 56, 57, 50, 43, 36, |
| 1223 |
29, 22, 15, 23, 30, 37, 44, 51, |
| 1224 |
58, 59, 52, 45, 38, 31, 39, 46, |
| 1225 |
53, 60, 61, 54, 47, 55, 62, 63 |
| 1226 |
}; |
| 1227 |
|
| 1228 |
|
| 1229 |
#define WRITE_HUFF_CODE(g,val,huffman) { \ |
| 1230 |
int whc_val = (int)(val); \ |
| 1231 |
WRITE_BITS_HIZERO (g, huffman[whc_val].code, huffman[whc_val].size) \ |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
static void zero_prior_DC (PJENC_INST g) |
| 1237 |
{ |
| 1238 |
g->prior_DC[0] = g->prior_DC[1] = g->prior_DC[2] = g->prior_DC[3] = 0; |
| 1239 |
} |
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
static void encode_init (PJENC_INST g) |
| 1249 |
{ |
| 1250 |
BYTE const *zig_p; |
| 1251 |
int **block_pp; |
| 1252 |
|
| 1253 |
zig_p = zigzag_index_table; |
| 1254 |
for (block_pp=g->enc_block_zz; block_pp<g->enc_block_zz+(64+16); block_pp++) |
| 1255 |
*block_pp = &(g->enc_block[*zig_p++]); |
| 1256 |
} |
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
static void encode_block ( |
| 1273 |
PJENC_INST g, |
| 1274 |
int comp, |
| 1275 |
const huff_elem_t *dc_huff_p, |
| 1276 |
const huff_elem_t *ac_huff_p, |
| 1277 |
int *quant_p, |
| 1278 |
int *thresh_p) |
| 1279 |
{ |
| 1280 |
int **block_p; |
| 1281 |
int i, data, absdata, run, siz; |
| 1282 |
int diff, absdiff; |
| 1283 |
WRITE_BITS_OPEN(g) |
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
thresh_p++; |
| 1290 |
block_p = g->enc_block_zz; |
| 1291 |
data = ROUND ((long)*(*block_p++) * (*quant_p++)); |
| 1292 |
absdiff = diff = data - g->prior_DC[comp]; |
| 1293 |
if (absdiff < 0) absdiff = -absdiff; |
| 1294 |
g->prior_DC[comp] = data; |
| 1295 |
|
| 1296 |
if (absdiff < 256) siz = codesize_array[absdiff]; |
| 1297 |
else siz = codesize_array[absdiff>>8] + 8; |
| 1298 |
|
| 1299 |
WRITE_HUFF_CODE (g, siz, dc_huff_p) |
| 1300 |
WRITE_BITS (g, diff<0 ? diff-1 : diff, siz) |
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
run = 0; |
| 1307 |
|
| 1308 |
for (i=63; i>0; i--) |
| 1309 |
{ |
| 1310 |
absdata = data = *(*block_p++); |
| 1311 |
if (absdata < 0) absdata = -absdata; |
| 1312 |
|
| 1313 |
if (absdata <= *thresh_p++) { |
| 1314 |
|
| 1315 |
quant_p++; |
| 1316 |
run++; |
| 1317 |
} |
| 1318 |
else |
| 1319 |
{ |
| 1320 |
while (run >= 16) { |
| 1321 |
WRITE_HUFF_CODE (g, RUN_OF_16, ac_huff_p) |
| 1322 |
run -= 16; |
| 1323 |
} |
| 1324 |
|
| 1325 |
absdata = ROUND ((DWORD )absdata * (DWORD )(*quant_p++)); |
| 1326 |
if (absdata < 256) siz = codesize_array[absdata]; |
| 1327 |
else siz = codesize_array[absdata>>8] + 8; |
| 1328 |
|
| 1329 |
|
| 1330 |
WRITE_HUFF_CODE (g, (run<<4) + siz, ac_huff_p) |
| 1331 |
WRITE_BITS (g, data<0 ? ~absdata : absdata, siz) |
| 1332 |
run = 0; |
| 1333 |
} |
| 1334 |
} |
| 1335 |
|
| 1336 |
if (run>0 || g->fDenali) |
| 1337 |
WRITE_HUFF_CODE (g, 0, ac_huff_p) |
| 1338 |
|
| 1339 |
WRITE_BITS_CLOSE(g) |
| 1340 |
} |
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
static void encode_MCU ( |
| 1350 |
PJENC_INST g, |
| 1351 |
UINT mcu_index) |
| 1352 |
{ |
| 1353 |
int *block_p; |
| 1354 |
UINT comp; |
| 1355 |
UINT h_block, v_block; |
| 1356 |
UINT ul_row, ul_col; |
| 1357 |
UINT row; |
| 1358 |
BYTE **row_pp; |
| 1359 |
BYTE *row_p; |
| 1360 |
|
| 1361 |
for (comp=0; comp<g->comps_in_pixel; comp++) { |
| 1362 |
for (v_block=0; v_block<g->vert_sam_facs[comp]; v_block++) { |
| 1363 |
for (h_block=0; h_block<g->horiz_sam_facs[comp]; h_block++) { |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
ul_row = v_block*8; |
| 1368 |
ul_col = (mcu_index*g->horiz_sam_facs[comp] + h_block) * 8; |
| 1369 |
row_pp = &(g->in_rows_ap[comp][ul_row]); |
| 1370 |
block_p = g->enc_block; |
| 1371 |
|
| 1372 |
for (row=0; row<8; row++) { |
| 1373 |
row_p = *row_pp++ + ul_col; |
| 1374 |
|
| 1375 |
*block_p++ = (int)(UINT)*row_p++ - 128; |
| 1376 |
*block_p++ = (int)(UINT)*row_p++ - 128; |
| 1377 |
*block_p++ = (int)(UINT)*row_p++ - 128; |
| 1378 |
*block_p++ = (int)(UINT)*row_p++ - 128; |
| 1379 |
*block_p++ = (int)(UINT)*row_p++ - 128; |
| 1380 |
*block_p++ = (int)(UINT)*row_p++ - 128; |
| 1381 |
*block_p++ = (int)(UINT)*row_p++ - 128; |
| 1382 |
*block_p++ = (int)(UINT)*row_p - 128; |
| 1383 |
} |
| 1384 |
|
| 1385 |
dct_forward (g->enc_block); |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
if (comp == 0) { |
| 1390 |
encode_block (g, comp, lum_DC_table, g->fDenali ? lum_AC_table_Denali : lum_AC_table, |
| 1391 |
g->wino_lum_quant, g->wino_lum_quant_thres); |
| 1392 |
} else { |
| 1393 |
encode_block (g, comp, chrom_DC_table, chrom_AC_table, |
| 1394 |
g->wino_chrom_quant, g->wino_chrom_quant_thres); |
| 1395 |
} |
| 1396 |
} |
| 1397 |
} |
| 1398 |
} |
| 1399 |
} |
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
static void copy_in_rows ( |
| 1437 |
PJENC_INST g, |
| 1438 |
UINT row_index, |
| 1439 |
BYTE *inbuf_p, |
| 1440 |
UINT *n_rows_p, |
| 1441 |
UINT *n_bytes_p) |
| 1442 |
{ |
| 1443 |
BYTE *in_p; |
| 1444 |
UINT comp; |
| 1445 |
UINT vert_period, vert_mod; |
| 1446 |
|
| 1447 |
vert_period = row_index / g->max_vert_sam_fac; |
| 1448 |
vert_mod = row_index % g->max_vert_sam_fac; |
| 1449 |
|
| 1450 |
if (!g->input_subsampled || (g->max_vert_sam_fac==1 && g->max_horiz_sam_fac==1)) |
| 1451 |
{ |
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
BYTE *row_p; |
| 1457 |
UINT sam_fac; |
| 1458 |
UINT col, horiz_mod; |
| 1459 |
UINT inc; |
| 1460 |
|
| 1461 |
for (comp=0; comp<g->comps_in_pixel; comp++) { |
| 1462 |
sam_fac = g->vert_sam_facs[comp]; |
| 1463 |
|
| 1464 |
if (vert_mod < sam_fac) { |
| 1465 |
in_p = inbuf_p + comp; |
| 1466 |
row_p = g->in_rows_ap[comp][vert_period*sam_fac + vert_mod]; |
| 1467 |
horiz_mod = 0; |
| 1468 |
sam_fac = g->horiz_sam_facs[comp]; |
| 1469 |
|
| 1470 |
if (sam_fac == g->max_horiz_sam_fac) { |
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
if (g->comps_in_pixel == 1) { |
| 1475 |
memcpy (row_p, in_p, g->pixels_in_row); |
| 1476 |
} else { |
| 1477 |
for (col=0; col<g->pixels_in_row; col+=4) { |
| 1478 |
*row_p++ = *in_p; in_p += g->comps_in_pixel; |
| 1479 |
*row_p++ = *in_p; in_p += g->comps_in_pixel; |
| 1480 |
*row_p++ = *in_p; in_p += g->comps_in_pixel; |
| 1481 |
*row_p++ = *in_p; in_p += g->comps_in_pixel; |
| 1482 |
} |
| 1483 |
} |
| 1484 |
|
| 1485 |
} else if (sam_fac==1 && g->max_horiz_sam_fac==2) { |
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
inc = 2 * g->comps_in_pixel; |
| 1490 |
for (col=0; col<g->pixels_in_row; col+=8) { |
| 1491 |
*row_p++ = *in_p; in_p += inc; |
| 1492 |
*row_p++ = *in_p; in_p += inc; |
| 1493 |
*row_p++ = *in_p; in_p += inc; |
| 1494 |
*row_p++ = *in_p; in_p += inc; |
| 1495 |
} |
| 1496 |
|
| 1497 |
} else { |
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
for (col=0; col<g->pixels_in_row; col++) { |
| 1502 |
if (horiz_mod < sam_fac) *row_p++ = *in_p; |
| 1503 |
in_p += g->comps_in_pixel; |
| 1504 |
horiz_mod += 1; |
| 1505 |
if (horiz_mod == g->max_horiz_sam_fac) horiz_mod = 0; |
| 1506 |
} |
| 1507 |
} |
| 1508 |
} |
| 1509 |
} |
| 1510 |
|
| 1511 |
*n_rows_p = 1; |
| 1512 |
*n_bytes_p = g->comps_in_pixel * g->pixels_in_row; |
| 1513 |
|
| 1514 |
} else { |
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
UINT horiz_period, periods_in_row; |
| 1521 |
UINT ul_row, ul_col, row, col; |
| 1522 |
BYTE *row_y1_p, *row_y2_p, *row_cb_p, *row_cr_p; |
| 1523 |
|
| 1524 |
in_p = inbuf_p; |
| 1525 |
periods_in_row = g->mcus_in_row * 8; |
| 1526 |
|
| 1527 |
if (g->sample_factors == 0x21102110u) { |
| 1528 |
row_y1_p = g->in_rows_ap[0][2*vert_period]; |
| 1529 |
row_y2_p = g->in_rows_ap[0][2*vert_period+1]; |
| 1530 |
row_cb_p = g->in_rows_ap[1][vert_period]; |
| 1531 |
row_cr_p = g->in_rows_ap[2][vert_period]; |
| 1532 |
for (horiz_period=0; horiz_period<periods_in_row; horiz_period++) { |
| 1533 |
*row_y1_p++ = *in_p++; |
| 1534 |
*row_y1_p++ = *in_p++; |
| 1535 |
*row_y2_p++ = *in_p++; |
| 1536 |
*row_y2_p++ = *in_p++; |
| 1537 |
*row_cb_p++ = *in_p++; |
| 1538 |
*row_cr_p++ = *in_p++; |
| 1539 |
} |
| 1540 |
} else { |
| 1541 |
|
| 1542 |
for (horiz_period=0; horiz_period<periods_in_row; horiz_period++) { |
| 1543 |
for (comp=0; comp<g->comps_in_pixel; comp++) { |
| 1544 |
ul_row = vert_period * g->vert_sam_facs[comp]; |
| 1545 |
ul_col = horiz_period * g->horiz_sam_facs[comp]; |
| 1546 |
|
| 1547 |
for (row=ul_row; row<ul_row+ g->vert_sam_facs[comp]; row++) |
| 1548 |
for (col=ul_col; col<ul_col+g->horiz_sam_facs[comp]; col++) { |
| 1549 |
g->in_rows_ap[comp][row][col] = *in_p++; |
| 1550 |
} |
| 1551 |
} |
| 1552 |
} |
| 1553 |
} |
| 1554 |
|
| 1555 |
*n_rows_p = g->max_vert_sam_fac; |
| 1556 |
*n_bytes_p = in_p - inbuf_p; |
| 1557 |
} |
| 1558 |
} |
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
static void scale_q_table ( |
| 1577 |
UINT dc_q_factor, |
| 1578 |
UINT ac_q_factor, |
| 1579 |
const BYTE *in, |
| 1580 |
BYTE *out) |
| 1581 |
{ |
| 1582 |
#define FINAL_DC_INDEX 9 |
| 1583 |
|
| 1584 |
UINT i, val; |
| 1585 |
UINT q; |
| 1586 |
|
| 1587 |
q = dc_q_factor; |
| 1588 |
|
| 1589 |
for (i=0; i<64; i++) { |
| 1590 |
val = ((*in++)*q + Q_DEFAULT/2) / Q_DEFAULT; |
| 1591 |
if (val < 1) val = 1; |
| 1592 |
if (val > 255) val = 255; |
| 1593 |
*out++ = (BYTE)val; |
| 1594 |
if (i == FINAL_DC_INDEX) |
| 1595 |
q = ac_q_factor; |
| 1596 |
} |
| 1597 |
} |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
static UINT output_header ( |
| 1611 |
PJENC_INST g, |
| 1612 |
BYTE *buf_p) |
| 1613 |
{ |
| 1614 |
BYTE hclass[4]; |
| 1615 |
BYTE ident[4]; |
| 1616 |
const BYTE *counts[4]; |
| 1617 |
const BYTE *huffval[4]; |
| 1618 |
|
| 1619 |
hclass [0] = 0; |
| 1620 |
ident [0] = 0; |
| 1621 |
counts [0] = lum_DC_counts; |
| 1622 |
huffval[0] = lum_DC_values; |
| 1623 |
|
| 1624 |
hclass [1] = 1; |
| 1625 |
ident [1] = 0; |
| 1626 |
counts [1] = g->fDenali ? lum_AC_counts_Denali : lum_AC_counts; |
| 1627 |
huffval[1] = lum_AC_values; |
| 1628 |
|
| 1629 |
hclass [2] = 0; |
| 1630 |
ident [2] = 1; |
| 1631 |
counts [2] = chrom_DC_counts; |
| 1632 |
huffval[2] = chrom_DC_values; |
| 1633 |
|
| 1634 |
hclass [3] = 1; |
| 1635 |
ident [3] = 1; |
| 1636 |
counts [3] = chrom_AC_counts; |
| 1637 |
huffval[3] = chrom_AC_values; |
| 1638 |
|
| 1639 |
write_buf_open (g, buf_p); |
| 1640 |
em_write_SOI (g); |
| 1641 |
|
| 1642 |
if (0 ) { |
| 1643 |
em_write_short_header (g, g->rows_in_page<0 ? 0 : g->rows_in_page, |
| 1644 |
g->pixels_in_row, |
| 1645 |
g->xRes, g->yRes, |
| 1646 |
g->dc_q_factor, g->ac_q_factor, |
| 1647 |
g->comps_in_pixel, |
| 1648 |
g->sample_factors); |
| 1649 |
} else { |
| 1650 |
if (g->fOutputG3APP1) |
| 1651 |
em_write_G3_APP1 (g, g->xRes); |
| 1652 |
else |
| 1653 |
em_write_JFIF_APP0 (g, g->xRes, g->yRes); |
| 1654 |
em_write_SOF (g, g->pixels_in_row, g->rows_in_page<0 ? 0 : g->rows_in_page, |
| 1655 |
g->comps_in_pixel, g->horiz_sam_facs, g->vert_sam_facs); |
| 1656 |
em_write_DQT (g, 0, 0, g->lum_quant); |
| 1657 |
if (g->comps_in_pixel > 1) |
| 1658 |
em_write_DQT (g, 0, 1, g->chrom_quant); |
| 1659 |
em_write_DHTs (g, g->comps_in_pixel==1 ? 2 : 4, |
| 1660 |
hclass, ident, counts, huffval); |
| 1661 |
em_write_SOS (g, g->comps_in_pixel); |
| 1662 |
} |
| 1663 |
return write_buf_close (g); |
| 1664 |
} |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
static WORD jpgEncode_openXform ( |
| 1682 |
IP_XFORM_HANDLE *pXform) |
| 1683 |
{ |
| 1684 |
PJENC_INST g; |
| 1685 |
|
| 1686 |
INSURE (pXform != NULL); |
| 1687 |
IP_MEM_ALLOC (sizeof(JENC_INST), g); |
| 1688 |
*pXform = g; |
| 1689 |
memset (g, 0, sizeof(JENC_INST)); |
| 1690 |
g->dwValidChk = CHECK_VALUE; |
| 1691 |
return IP_DONE; |
| 1692 |
|
| 1693 |
fatal_error: |
| 1694 |
return IP_FATAL_ERROR; |
| 1695 |
} |
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
|
| 1706 |
|
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
static WORD jpgEncode_setDefaultInputTraits ( |
| 1715 |
IP_XFORM_HANDLE hXform, |
| 1716 |
PIP_IMAGE_TRAITS pTraits) |
| 1717 |
{ |
| 1718 |
PJENC_INST g; |
| 1719 |
|
| 1720 |
HANDLE_TO_PTR (hXform, g); |
| 1721 |
g->traits = *pTraits; |
| 1722 |
|
| 1723 |
INSURE (g->traits.iPixelsPerRow > 0); |
| 1724 |
INSURE (g->traits.iComponentsPerPixel==1 || g->traits.iComponentsPerPixel==3); |
| 1725 |
|
| 1726 |
g->pixels_in_row = g->traits.iPixelsPerRow; |
| 1727 |
g->comps_in_pixel = g->traits.iComponentsPerPixel; |
| 1728 |
g->rows_in_page = g->traits.lNumRows; |
| 1729 |
g->xRes = g->traits.lHorizDPI >> 16; |
| 1730 |
g->yRes = g->traits.lVertDPI >> 16; |
| 1731 |
if (g->xRes < 0) g->xRes = 300; |
| 1732 |
if (g->yRes < 0) g->yRes = 300; |
| 1733 |
|
| 1734 |
g->fDidHeader = FALSE; |
| 1735 |
return IP_DONE; |
| 1736 |
|
| 1737 |
fatal_error: |
| 1738 |
return IP_FATAL_ERROR; |
| 1739 |
} |
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
static WORD jpgEncode_setXformSpec ( |
| 1750 |
IP_XFORM_HANDLE hXform, |
| 1751 |
DWORD_OR_PVOID aXformInfo[]) |
| 1752 |
{ |
| 1753 |
PJENC_INST g; |
| 1754 |
UINT qfacs; |
| 1755 |
|
| 1756 |
HANDLE_TO_PTR (hXform, g); |
| 1757 |
|
| 1758 |
qfacs = aXformInfo[IP_JPG_ENCODE_QUALITY_FACTORS].dword; |
| 1759 |
g->sample_factors = aXformInfo[IP_JPG_ENCODE_SAMPLE_FACTORS].dword; |
| 1760 |
g->input_subsampled = aXformInfo[IP_JPG_ENCODE_ALREADY_SUBSAMPLED].dword; |
| 1761 |
g->fDenali = (BOOL)aXformInfo[IP_JPG_ENCODE_FOR_DENALI].dword; |
| 1762 |
g->fOutputDNL = (BOOL)aXformInfo[IP_JPG_ENCODE_OUTPUT_DNL].dword; |
| 1763 |
g->fOutputG3APP1 = (BOOL)aXformInfo[IP_JPG_ENCODE_FOR_COLOR_FAX].dword; |
| 1764 |
g->dwDummyHeaderBytes = aXformInfo[IP_JPG_ENCODE_DUMMY_HEADER_LEN].dword; |
| 1765 |
|
| 1766 |
g->dc_q_factor = (BYTE)(qfacs >> 8); |
| 1767 |
g->ac_q_factor = (BYTE)(qfacs); |
| 1768 |
|
| 1769 |
return IP_DONE; |
| 1770 |
|
| 1771 |
fatal_error: |
| 1772 |
return IP_FATAL_ERROR; |
| 1773 |
} |
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
static WORD jpgEncode_getHeaderBufSize ( |
| 1784 |
IP_XFORM_HANDLE hXform, |
| 1785 |
DWORD *pdwInBufLen) |
| 1786 |
{ |
| 1787 |
PJENC_INST g; |
| 1788 |
|
| 1789 |
HANDLE_TO_PTR (hXform, g); |
| 1790 |
|
| 1791 |
*pdwInBufLen = 0; |
| 1792 |
return IP_DONE; |
| 1793 |
|
| 1794 |
fatal_error: |
| 1795 |
return IP_FATAL_ERROR; |
| 1796 |
} |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
static WORD jpgEncode_getActualTraits ( |
| 1807 |
IP_XFORM_HANDLE hXform, |
| 1808 |
DWORD dwInputAvail, |
| 1809 |
PBYTE pbInputBuf, |
| 1810 |
PDWORD pdwInputUsed, |
| 1811 |
PDWORD pdwInputNextPos, |
| 1812 |
PIP_IMAGE_TRAITS pInTraits, |
| 1813 |
PIP_IMAGE_TRAITS pOutTraits) |
| 1814 |
{ |
| 1815 |
PJENC_INST g; |
| 1816 |
|
| 1817 |
HANDLE_TO_PTR (hXform, g); |
| 1818 |
|
| 1819 |
|
| 1820 |
*pdwInputUsed = 0; |
| 1821 |
*pdwInputNextPos = 0; |
| 1822 |
|
| 1823 |
|
| 1824 |
*pInTraits = g->traits; |
| 1825 |
*pOutTraits = g->traits; |
| 1826 |
|
| 1827 |
return IP_DONE | IP_READY_FOR_DATA; |
| 1828 |
|
| 1829 |
fatal_error: |
| 1830 |
return IP_FATAL_ERROR; |
| 1831 |
} |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
static WORD jpgEncode_getActualBufSizes ( |
| 1842 |
IP_XFORM_HANDLE hXform, |
| 1843 |
PDWORD pdwMinInBufLen, |
| 1844 |
PDWORD pdwMinOutBufLen) |
| 1845 |
{ |
| 1846 |
PJENC_INST g; |
| 1847 |
WORD n; |
| 1848 |
|
| 1849 |
HANDLE_TO_PTR (hXform, g); |
| 1850 |
*pdwMinInBufLen = g->comps_in_pixel * g->pixels_in_row; |
| 1851 |
|
| 1852 |
n = OUTBUF_NUM_MCUS * MAX_MCU_SIZE; |
| 1853 |
if (n < MAX_HEADER_SIZE) n = MAX_HEADER_SIZE; |
| 1854 |
*pdwMinOutBufLen = n; |
| 1855 |
|
| 1856 |
return IP_DONE; |
| 1857 |
|
| 1858 |
fatal_error: |
| 1859 |
return IP_FATAL_ERROR; |
| 1860 |
} |
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
static WORD jpgEncode_convert ( |
| 1871 |
IP_XFORM_HANDLE hXform, |
| 1872 |
DWORD dwInputAvail, |
| 1873 |
PBYTE pbInputBuf, |
| 1874 |
PDWORD pdwInputUsed, |
| 1875 |
PDWORD pdwInputNextPos, |
| 1876 |
DWORD dwOutputAvail, |
| 1877 |
PBYTE pbOutputBuf, |
| 1878 |
PDWORD pdwOutputUsed, |
| 1879 |
PDWORD pdwOutputThisPos) |
| 1880 |
{ |
| 1881 |
PJENC_INST g; |
| 1882 |
unsigned ret_val; |
| 1883 |
UINT row, n_rows, n_bytes; |
| 1884 |
int comp; |
| 1885 |
UINT row_len; |
| 1886 |
UINT n_loaded; |
| 1887 |
|
| 1888 |
HANDLE_TO_PTR (hXform, g); |
| 1889 |
|
| 1890 |
*pdwInputNextPos = g->dwInNextPos; |
| 1891 |
*pdwInputUsed = 0; |
| 1892 |
*pdwOutputThisPos = g->dwOutNextPos; |
| 1893 |
*pdwOutputUsed = 0; |
| 1894 |
ret_val = IP_READY_FOR_DATA; |
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
if (! g->fDidHeader) { |
| 1901 |
UINT row_len; |
| 1902 |
BYTE *p; |
| 1903 |
DWORD factors; |
| 1904 |
UINT fac; |
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
g->rows_loaded = 0; |
| 1909 |
g->mcus_sent = 0; |
| 1910 |
g->loading_rows = TRUE; |
| 1911 |
write_init (g); |
| 1912 |
zero_prior_DC (g); |
| 1913 |
encode_init (g); |
| 1914 |
|
| 1915 |
if (g->ac_q_factor == 0) |
| 1916 |
g->ac_q_factor = Q_DEFAULT; |
| 1917 |
if (g->dc_q_factor == 0) |
| 1918 |
g->dc_q_factor = g->ac_q_factor; |
| 1919 |
|
| 1920 |
if (g->sample_factors == 0) |
| 1921 |
g->sample_factors = g->comps_in_pixel==1 ? MONO_FACTORS : COLOR_FACTORS; |
| 1922 |
|
| 1923 |
factors = g->sample_factors >> 16; |
| 1924 |
g->max_horiz_sam_fac = 0; |
| 1925 |
for (comp=3; comp>=0; comp--) { |
| 1926 |
fac = factors & 0x0fu; |
| 1927 |
if (fac > g->max_horiz_sam_fac) g->max_horiz_sam_fac = fac; |
| 1928 |
g->horiz_sam_facs[comp] = fac; |
| 1929 |
factors >>= 4; |
| 1930 |
} |
| 1931 |
|
| 1932 |
factors = g->sample_factors & 0x0000ffffu; |
| 1933 |
g->max_vert_sam_fac = 0; |
| 1934 |
for (comp=3; comp>=0; comp--) { |
| 1935 |
fac = factors & 0x0fu; |
| 1936 |
if (fac > g->max_vert_sam_fac) g->max_vert_sam_fac = fac; |
| 1937 |
g->vert_sam_facs[comp] = fac; |
| 1938 |
factors >>= 4; |
| 1939 |
} |
| 1940 |
|
| 1941 |
g->cols_in_mcu = g->max_horiz_sam_fac * 8; |
| 1942 |
g->rows_in_mcu = g->max_vert_sam_fac * 8; |
| 1943 |
g->mcus_in_row = (g->pixels_in_row + g->cols_in_mcu - 1) / g->cols_in_mcu; |
| 1944 |
|
| 1945 |
scale_q_table (g->dc_q_factor, g->ac_q_factor, orig_lum_quant, g->lum_quant); |
| 1946 |
scale_q_table (g->dc_q_factor, g->ac_q_factor, orig_chrom_quant, g->chrom_quant); |
| 1947 |
|
| 1948 |
|
| 1949 |
scale_for_wino (g->lum_quant, g->wino_lum_quant, g->wino_lum_quant_thres); |
| 1950 |
scale_for_wino (g->chrom_quant, g->wino_chrom_quant, g->wino_chrom_quant_thres); |
| 1951 |
|
| 1952 |
g->whitePixel[0] = 255; |
| 1953 |
g->whitePixel[1] = 128; |
| 1954 |
g->whitePixel[2] = 128; |
| 1955 |
g->whitePixel[3] = 255; |
| 1956 |
|
| 1957 |
g->dwOutNextPos = *pdwOutputUsed = (g->dwDummyHeaderBytes == 0) |
| 1958 |
? output_header (g,pbOutputBuf) |
| 1959 |
: g->dwDummyHeaderBytes; |
| 1960 |
|
| 1961 |
*pdwOutputThisPos = 0; |
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
memset (g->in_rows_ap, 0, sizeof(g->in_rows_ap)); |
| 1966 |
|
| 1967 |
for (comp=0; comp<(int)g->comps_in_pixel; comp++) { |
| 1968 |
row_len = g->horiz_sam_facs[comp] * g->mcus_in_row * 8; |
| 1969 |
n_rows = g->vert_sam_facs[comp] * 8; |
| 1970 |
|
| 1971 |
for (row=0; row<n_rows; row++) { |
| 1972 |
IP_MEM_ALLOC (row_len, p); |
| 1973 |
g->in_rows_ap[comp][row] = p; |
| 1974 |
} |
| 1975 |
} |
| 1976 |
|
| 1977 |
*pdwInputUsed = 0; |
| 1978 |
*pdwInputNextPos = 0; |
| 1979 |
g->dwInNextPos = 0; |
| 1980 |
g->fDidHeader = TRUE; |
| 1981 |
|
| 1982 |
return IP_READY_FOR_DATA; |
| 1983 |
} |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
if (g->loading_rows) { |
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
n_loaded = g->rows_loaded % g->rows_in_mcu; |
| 1994 |
|
| 1995 |
if (n_loaded == 0) { |
| 1996 |
for (comp=0; comp<g->comps_in_pixel; comp++) { |
| 1997 |
row_len = g->horiz_sam_facs[comp] * g->mcus_in_row * 8; |
| 1998 |
n_rows = g->vert_sam_facs[comp] * 8; |
| 1999 |
|
| 2000 |
for (row=0; row<n_rows; row++) |
| 2001 |
memset (g->in_rows_ap[comp][row], g->whitePixel[comp], row_len); |
| 2002 |
} |
| 2003 |
} |
| 2004 |
|
| 2005 |
if (pbInputBuf == NULL) { |
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
if (n_loaded != 0) { |
| 2010 |
|
| 2011 |
g->loading_rows = FALSE; |
| 2012 |
|
| 2013 |
|
| 2014 |
g->rows_loaded += g->rows_in_mcu - n_loaded; |
| 2015 |
} else if ((g->rows_in_page<0 || (int)g->rows_received<g->rows_in_page) |
| 2016 |
&& g->dwDummyHeaderBytes == 0) { |
| 2017 |
|
| 2018 |
g->rows_in_page = g->rows_received; |
| 2019 |
*pdwOutputUsed = output_header (g, pbOutputBuf); |
| 2020 |
*pdwOutputThisPos = 0; |
| 2021 |
} else { |
| 2022 |
|
| 2023 |
PRINT (_T("jpeg_encode_convert_row: Done\n"),0,0); |
| 2024 |
write_buf_open (g, pbOutputBuf); |
| 2025 |
write_bits_flush (g); |
| 2026 |
if (g->fOutputDNL) |
| 2027 |
em_write_DNL (g, g->rows_received); |
| 2028 |
em_write_EOI (g); |
| 2029 |
*pdwOutputUsed = write_buf_close (g); |
| 2030 |
ret_val |= IP_DONE; |
| 2031 |
} |
| 2032 |
} else { |
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
copy_in_rows ( |
| 2037 |
g, |
| 2038 |
n_loaded, |
| 2039 |
pbInputBuf, |
| 2040 |
&n_rows, |
| 2041 |
&n_bytes); |
| 2042 |
|
| 2043 |
*pdwInputUsed = n_bytes; |
| 2044 |
*pdwInputNextPos = (g->dwInNextPos += n_bytes); |
| 2045 |
g->rows_loaded += n_rows; |
| 2046 |
g->rows_received += n_rows; |
| 2047 |
n_loaded = g->rows_loaded % g->rows_in_mcu; |
| 2048 |
|
| 2049 |
|
| 2050 |
if (n_rows > 0) |
| 2051 |
ret_val |= IP_CONSUMED_ROW | IP_PRODUCED_ROW; |
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
if (n_loaded == 0) { |
| 2056 |
|
| 2057 |
g->loading_rows = FALSE; |
| 2058 |
} |
| 2059 |
} |
| 2060 |
} |
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
while (!g->loading_rows && |
| 2067 |
dwOutputAvail-*pdwOutputUsed > MAX_MCU_SIZE) { |
| 2068 |
PRINT (_T("jpeg_encode_convert_row: Encoding MCU, mcus_sent=%d\n"), |
| 2069 |
g->mcus_sent, 0); |
| 2070 |
|
| 2071 |
write_buf_open (g, pbOutputBuf + *pdwOutputUsed); |
| 2072 |
encode_MCU (g, g->mcus_sent); |
| 2073 |
n_bytes = write_buf_close (g); |
| 2074 |
|
| 2075 |
g->dwOutNextPos += n_bytes; |
| 2076 |
*pdwOutputUsed += n_bytes; |
| 2077 |
|
| 2078 |
g->mcus_sent += 1; |
| 2079 |
if (g->mcus_sent >= g->mcus_in_row) { |
| 2080 |
g->loading_rows = TRUE; |
| 2081 |
g->mcus_sent = 0; |
| 2082 |
} |
| 2083 |
} |
| 2084 |
|
| 2085 |
PRINT (_T("jpeg_encode_convert_row: Returning %04x, out_used=%d\n"), |
| 2086 |
ret_val, *pdwOutputUsed); |
| 2087 |
return ret_val; |
| 2088 |
|
| 2089 |
fatal_error: |
| 2090 |
return IP_FATAL_ERROR; |
| 2091 |
} |
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
static WORD jpgEncode_insertedData ( |
| 2102 |
IP_XFORM_HANDLE hXform, |
| 2103 |
DWORD dwNumBytes) |
| 2104 |
{ |
| 2105 |
fatalBreakPoint (); |
| 2106 |
return IP_FATAL_ERROR; |
| 2107 |
} |
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
static WORD jpgEncode_newPage ( |
| 2118 |
IP_XFORM_HANDLE hXform) |
| 2119 |
{ |
| 2120 |
PJENC_INST g; |
| 2121 |
|
| 2122 |
HANDLE_TO_PTR (hXform, g); |
| 2123 |
|
| 2124 |
return IP_DONE; |
| 2125 |
|
| 2126 |
fatal_error: |
| 2127 |
return IP_FATAL_ERROR; |
| 2128 |
} |
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
static WORD jpgEncode_closeXform (IP_XFORM_HANDLE hXform) |
| 2139 |
{ |
| 2140 |
PJENC_INST g; |
| 2141 |
BYTE **row_pp, **after_pp, *p; |
| 2142 |
|
| 2143 |
HANDLE_TO_PTR (hXform, g); |
| 2144 |
row_pp = &(g->in_rows_ap[0][0]); |
| 2145 |
after_pp = row_pp + (sizeof(g->in_rows_ap)/sizeof(BYTE*)); |
| 2146 |
|
| 2147 |
for ( ; row_pp<after_pp; row_pp++) { |
| 2148 |
p = *row_pp; |
| 2149 |
if (p != NULL) { |
| 2150 |
IP_MEM_FREE (p); |
| 2151 |
*row_pp = NULL; |
| 2152 |
} |
| 2153 |
} |
| 2154 |
|
| 2155 |
g->dwValidChk = 0; |
| 2156 |
IP_MEM_FREE (g); |
| 2157 |
return IP_DONE; |
| 2158 |
|
| 2159 |
fatal_error: |
| 2160 |
return IP_FATAL_ERROR; |
| 2161 |
} |
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
IP_XFORM_TBL jpgEncodeTbl = { |
| 2172 |
jpgEncode_openXform, |
| 2173 |
jpgEncode_setDefaultInputTraits, |
| 2174 |
jpgEncode_setXformSpec, |
| 2175 |
jpgEncode_getHeaderBufSize, |
| 2176 |
jpgEncode_getActualTraits, |
| 2177 |
jpgEncode_getActualBufSizes, |
| 2178 |
jpgEncode_convert, |
| 2179 |
jpgEncode_newPage, |
| 2180 |
jpgEncode_insertedData, |
| 2181 |
jpgEncode_closeXform |
| 2182 |
}; |
| 2183 |
|
| 2184 |
|