- }
-
- switch(correction_type_sp[lp2 & 0x01][k]) {
- case 0:
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
- cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1);
- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- cur_lp[0] = cur_lp[width_tbl[1]];
- cur_lp[1] = cur_lp[width_tbl[1]+1];
- }
- lp2++;
- break;
-
- case 1:
- cur_lp[width_tbl[1]] = le2me_32(((le2me_32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1);
- cur_lp[width_tbl[1]+1] = le2me_32(((le2me_32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1);
- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) {
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
- } else {
- cur_lp[0] = cur_lp[width_tbl[1]];
- cur_lp[1] = cur_lp[width_tbl[1]+1];
- }
- buf1++;
- lp2++;
- break;
-
- case 2:
- if(lp2 == 0) {
- if(flag1 != 0) {
- for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) {
- cur_lp[j] = lv1;
- cur_lp[j+1] = lv2;
- }
- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE;
- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE;
+ return a;
+}
+
+
+/* Fill n lines with 64bit pixel value pix */
+static inline void fill_64(uint8_t *dst, const uint64_t pix, int32_t n,
+ int32_t row_offset)
+{
+ for (; n > 0; dst += row_offset, n--)
+ AV_WN64A(dst, pix);
+}
+
+
+/* Error codes for cell decoding. */
+enum {
+ IV3_NOERR = 0,
+ IV3_BAD_RLE = 1,
+ IV3_BAD_DATA = 2,
+ IV3_BAD_COUNTER = 3,
+ IV3_UNSUPPORTED = 4,
+ IV3_OUT_OF_DATA = 5
+};
+
+
+#define BUFFER_PRECHECK \
+if (*data_ptr >= last_ptr) \
+ return IV3_OUT_OF_DATA; \
+
+#define RLE_BLOCK_COPY \
+ if (cell->mv_ptr || !skip_flag) \
+ ctx->hdsp.put_pixels_tab[2][0](dst, ref, row_offset, 4 << v_zoom)
+
+#define RLE_BLOCK_COPY_8 \
+ pix64 = AV_RN64(ref);\
+ if (is_first_row) {/* special prediction case: top line of a cell */\
+ pix64 = replicate64(pix64);\
+ fill_64(dst + row_offset, pix64, 7, row_offset);\
+ AVG_64(dst, ref, dst + row_offset);\
+ } else \
+ fill_64(dst, pix64, 8, row_offset)
+
+#define RLE_LINES_COPY \
+ ctx->hdsp.put_pixels_tab[2][0](dst, ref, row_offset, num_lines << v_zoom)
+
+#define RLE_LINES_COPY_M10 \
+ pix64 = AV_RN64(ref);\
+ if (is_top_of_cell) {\
+ pix64 = replicate64(pix64);\
+ fill_64(dst + row_offset, pix64, (num_lines << 1) - 1, row_offset);\
+ AVG_64(dst, ref, dst + row_offset);\
+ } else \
+ fill_64(dst, pix64, num_lines << 1, row_offset)
+
+#define APPLY_DELTA_4 \
+ AV_WN16A(dst + line_offset ,\
+ (AV_RN16(ref ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
+ AV_WN16A(dst + line_offset + 2,\
+ (AV_RN16(ref + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
+ if (mode >= 3) {\
+ if (is_top_of_cell && !cell->ypos) {\
+ AV_COPY32U(dst, dst + row_offset);\
+ } else {\
+ AVG_32(dst, ref, dst + row_offset);\
+ }\
+ }
+
+#define APPLY_DELTA_8 \
+ /* apply two 32-bit VQ deltas to next even line */\
+ if (is_top_of_cell) { \
+ AV_WN32A(dst + row_offset , \
+ (replicate32(AV_RN32(ref )) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
+ AV_WN32A(dst + row_offset + 4, \
+ (replicate32(AV_RN32(ref + 4)) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
+ } else { \
+ AV_WN32A(dst + row_offset , \
+ (AV_RN32(ref ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
+ AV_WN32A(dst + row_offset + 4, \
+ (AV_RN32(ref + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
+ } \
+ /* odd lines are not coded but rather interpolated/replicated */\
+ /* first line of the cell on the top of image? - replicate */\
+ /* otherwise - interpolate */\
+ if (is_top_of_cell && !cell->ypos) {\
+ AV_COPY64U(dst, dst + row_offset);\
+ } else \
+ AVG_64(dst, ref, dst + row_offset);
+
+
+#define APPLY_DELTA_1011_INTER \
+ if (mode == 10) { \
+ AV_WN32A(dst , \
+ (AV_RN32(dst ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
+ AV_WN32A(dst + 4 , \
+ (AV_RN32(dst + 4 ) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
+ AV_WN32A(dst + row_offset , \
+ (AV_RN32(dst + row_offset ) + delta_tab->deltas_m10[dyad1]) & 0x7F7F7F7F);\
+ AV_WN32A(dst + row_offset + 4, \
+ (AV_RN32(dst + row_offset + 4) + delta_tab->deltas_m10[dyad2]) & 0x7F7F7F7F);\
+ } else { \
+ AV_WN16A(dst , \
+ (AV_RN16(dst ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
+ AV_WN16A(dst + 2 , \
+ (AV_RN16(dst + 2 ) + delta_tab->deltas[dyad2]) & 0x7F7F);\
+ AV_WN16A(dst + row_offset , \
+ (AV_RN16(dst + row_offset ) + delta_tab->deltas[dyad1]) & 0x7F7F);\
+ AV_WN16A(dst + row_offset + 2, \
+ (AV_RN16(dst + row_offset + 2) + delta_tab->deltas[dyad2]) & 0x7F7F);\
+ }
+
+
+static int decode_cell_data(Indeo3DecodeContext *ctx, Cell *cell,
+ uint8_t *block, uint8_t *ref_block,
+ int pitch, int h_zoom, int v_zoom, int mode,
+ const vqEntry *delta[2], int swap_quads[2],
+ const uint8_t **data_ptr, const uint8_t *last_ptr)
+{
+ int x, y, line, num_lines;
+ int rle_blocks = 0;
+ uint8_t code, *dst, *ref;
+ const vqEntry *delta_tab;
+ unsigned int dyad1, dyad2;
+ uint64_t pix64;
+ int skip_flag = 0, is_top_of_cell, is_first_row = 1;
+ int row_offset, blk_row_offset, line_offset;
+
+ row_offset = pitch;
+ blk_row_offset = (row_offset << (2 + v_zoom)) - (cell->width << 2);
+ line_offset = v_zoom ? row_offset : 0;
+
+ if (cell->height & v_zoom || cell->width & h_zoom)
+ return IV3_BAD_DATA;
+
+ for (y = 0; y < cell->height; is_first_row = 0, y += 1 + v_zoom) {
+ for (x = 0; x < cell->width; x += 1 + h_zoom) {
+ ref = ref_block;
+ dst = block;
+
+ if (rle_blocks > 0) {
+ if (mode <= 4) {
+ RLE_BLOCK_COPY;
+ } else if (mode == 10 && !cell->mv_ptr) {
+ RLE_BLOCK_COPY_8;
+ }
+ rle_blocks--;
+ } else {
+ for (line = 0; line < 4;) {
+ num_lines = 1;
+ is_top_of_cell = is_first_row && !line;
+
+ /* select primary VQ table for odd, secondary for even lines */
+ if (mode <= 4)
+ delta_tab = delta[line & 1];
+ else
+ delta_tab = delta[1];
+ BUFFER_PRECHECK;
+ code = bytestream_get_byte(data_ptr);
+ if (code < 248) {
+ if (code < delta_tab->num_dyads) {
+ BUFFER_PRECHECK;
+ dyad1 = bytestream_get_byte(data_ptr);
+ dyad2 = code;
+ if (dyad1 >= delta_tab->num_dyads || dyad1 >= 248)
+ return IV3_BAD_DATA;