+}
+
+#define WRITE_FRAME(D, PIXEL) \
+ static inline void write_frame_ ## D(Jpeg2000DecoderContext * s, Jpeg2000Tile * tile, \
+ AVFrame * picture) \
+ { \
+ int linesize = picture->linesize[0] / sizeof(PIXEL); \
+ int compno; \
+ int x, y; \
+ \
+ for (compno = 0; compno < s->ncomponents; compno++) { \
+ Jpeg2000Component *comp = tile->comp + compno; \
+ Jpeg2000CodingStyle *codsty = tile->codsty + compno; \
+ PIXEL *line; \
+ float *datap = comp->f_data; \
+ int32_t *i_datap = comp->i_data; \
+ int cbps = s->cbps[compno]; \
+ int w = tile->comp[compno].coord[0][1] - s->image_offset_x; \
+ \
+ y = tile->comp[compno].coord[1][0] - s->image_offset_y; \
+ line = (PIXEL *)picture->data[0] + y * linesize; \
+ for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) { \
+ PIXEL *dst; \
+ \
+ x = tile->comp[compno].coord[0][0] - s->image_offset_x; \
+ dst = line + x * s->ncomponents + compno; \
+ \
+ if (codsty->transform == FF_DWT97) { \
+ for (; x < w; x += s->cdx[compno]) { \
+ int val = lrintf(*datap) + (1 << (cbps - 1)); \
+ /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ \
+ val = av_clip(val, 0, (1 << cbps) - 1); \
+ *dst = val << (8 * sizeof(PIXEL) - cbps); \
+ datap++; \
+ dst += s->ncomponents; \
+ } \
+ } else { \
+ for (; x < w; x += s->cdx[compno]) { \
+ int val = *i_datap + (1 << (cbps - 1)); \
+ /* DC level shift and clip see ISO 15444-1:2002 G.1.2 */ \
+ val = av_clip(val, 0, (1 << cbps) - 1); \
+ *dst = val << (8 * sizeof(PIXEL) - cbps); \
+ i_datap++; \
+ dst += s->ncomponents; \
+ } \
+ } \
+ line += linesize; \
+ } \
+ } \
+ \
+ }
+
+WRITE_FRAME(8, uint8_t)
+WRITE_FRAME(16, uint16_t)
+
+#undef WRITE_FRAME
+
+static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile *tile,
+ AVFrame *picture)
+{
+ tile_codeblocks(s, tile);