| 371 | } |
| 372 | |
| 373 | static void encode_block(MpegEncContext *s, DCTELEM *block, int n) |
| 374 | { |
| 375 | int mant, nbits, code, i, j; |
| 376 | int component, dc, run, last_index, val; |
| 377 | MJpegContext *m = s->mjpeg_ctx; |
| 378 | uint8_t *huff_size_ac; |
| 379 | uint16_t *huff_code_ac; |
| 380 | |
| 381 | /* DC coef */ |
| 382 | component = (n <= 3 ? 0 : (n&1) + 1); |
| 383 | dc = block[0]; /* overflow is impossible */ |
| 384 | val = dc - s->last_dc[component]; |
| 385 | if (n < 4) { |
| 386 | ff_mjpeg_encode_dc(s, val, m->huff_size_dc_luminance, m->huff_code_dc_luminance); |
| 387 | huff_size_ac = m->huff_size_ac_luminance; |
| 388 | huff_code_ac = m->huff_code_ac_luminance; |
| 389 | } else { |
| 390 | ff_mjpeg_encode_dc(s, val, m->huff_size_dc_chrominance, m->huff_code_dc_chrominance); |
| 391 | huff_size_ac = m->huff_size_ac_chrominance; |
| 392 | huff_code_ac = m->huff_code_ac_chrominance; |
| 393 | } |
| 394 | s->last_dc[component] = dc; |
| 395 | |
| 396 | /* AC coefs */ |
| 397 | |
| 398 | run = 0; |
| 399 | last_index = s->block_last_index[n]; |
| 400 | for(i=1;i<=last_index;i++) { |
| 401 | j = s->intra_scantable.permutated[i]; |
| 402 | val = block[j]; |
| 403 | if (val == 0) { |
| 404 | run++; |
| 405 | } else { |
| 406 | while (run >= 16) { |
| 407 | put_bits(&s->pb, huff_size_ac[0xf0], huff_code_ac[0xf0]); |
| 408 | run -= 16; |
| 409 | } |
| 410 | mant = val; |
| 411 | if (val < 0) { |
| 412 | val = -val; |
| 413 | mant--; |
| 414 | } |
| 415 | |
| 416 | nbits= av_log2(val) + 1; |
| 417 | code = (run << 4) | nbits; |
| 418 | |
| 419 | put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]); |
| 420 | |
| 421 | put_sbits(&s->pb, nbits, mant); |
| 422 | run = 0; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | /* output EOB only if not already 64 values */ |
| 427 | if (last_index < 63 || run != 0) |
| 428 | put_bits(&s->pb, huff_size_ac[0], huff_code_ac[0]); |
| 429 | } |
| 430 |
no test coverage detected