int sonix_decode(unsigned char * dst, unsigned char * src, int width, int height) { long dst_index = 0; int starting_row = 0; unsigned short bits; short c1val, c2val; int x, y; unsigned long bitBuf = 0; unsigned long bitBufCount = 0; /* Columns were reversed during compression ! */ for (y = starting_row; y < height; y++) { PEEK_BITS(8, bits); EAT_BITS(8); c2val = bits & 0xff; PEEK_BITS(8, bits); EAT_BITS(8); c1val = bits & 0xff; PUT_PIXEL_PAIR; for (x = 2; x < width ; x += 2) { PARSE_PIXEL(c2val); PARSE_PIXEL(c1val); PUT_PIXEL_PAIR; } } return GP_OK; }
decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) { phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy; int Al = cinfo->Al; int blkn; BITREAD_STATE_VARS; savable_state state; /* Process restart marker if needed; may have to suspend */ if (cinfo->restart_interval) { if (entropy->restarts_to_go == 0) if (! process_restart(cinfo)) return FALSE; } /* If we've run out of data, just leave the MCU set to zeroes. * This way, we return uniform gray for the remainder of the segment. */ if (! entropy->pub.insufficient_data) { /* Load up working state */ BITREAD_LOAD_STATE(cinfo,entropy->bitstate); ASSIGN_STATE(state, entropy->saved); /* Outer loop handles each block in the MCU */ for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) { JBLOCKROW block = MCU_data[blkn]; int ci = cinfo->MCU_membership[blkn]; d_derived_tbl * tbl = entropy->dc_derived_tbls[ci]; register int s; /* Decode a single block's worth of coefficients */ /* Section F.2.2.1: decode the DC coefficient difference */ { /* HUFFX_DECODE */ register int nb, look, t; if (bits_left < HUFFX_LOOKAHEAD) { register const JOCTET * next_input_byte = br_state.next_input_byte; register size_t bytes_in_buffer = br_state.bytes_in_buffer; if (cinfo->unread_marker == 0) { while (bits_left < MIN_GET_BITS) { register int c; if (bytes_in_buffer == 0 || (c = GETJOCTET(*next_input_byte)) == 0xFF) { goto label11; } bytes_in_buffer--; next_input_byte++; get_buffer = (get_buffer << 8) | c; bits_left += 8; } br_state.next_input_byte = next_input_byte; br_state.bytes_in_buffer = bytes_in_buffer; } else { label11: br_state.next_input_byte = next_input_byte; br_state.bytes_in_buffer = bytes_in_buffer; if (! jpeg_fill_bit_buffer(&br_state,get_buffer,bits_left, 0)) { return FALSE; } get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; if (bits_left < HUFFX_LOOKAHEAD) { nb = 1; goto label1; } } } look = PEEK_BITS(HUFFX_LOOKAHEAD); if ((nb = tbl->lookx_nbits[look]) != 0) { s = tbl->lookx_val[look]; if (nb <= HUFFX_LOOKAHEAD) { DROP_BITS(nb); } else { DROP_BITS(HUFFX_LOOKAHEAD); nb -= HUFFX_LOOKAHEAD; CHECK_BIT_BUFFER(br_state, nb, return FALSE); s += GET_BITS(nb); } } else { nb = HUFFX_LOOKAHEAD; label1: if ((s=jpeg_huff_decode(&br_state,get_buffer,bits_left,tbl,nb)) < 0) { return FALSE; } get_buffer = br_state.get_buffer; bits_left = br_state.bits_left; if (s) { CHECK_BIT_BUFFER(br_state, s, return FALSE); t = GET_BITS(s); s = HUFF_EXTEND(t, s); } } }