static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end,
                const uint8_t *in_buf, const uint8_t *in_end, SgiState* s)
{
    int x, y, z;
    const uint8_t *ptr;
    unsigned int offset = s->height * s->width;
    if (offset * s->depth > in_end - in_buf) {
       return -1;
    }
    for (y = s->height - 1; y >= 0; y--) {
        out_end = out_buf + (y * s->linesize);
        for (x = s->width; x > 0; x--) {
            ptr = in_buf++;
            for(z = 0; z < s->depth; z ++) {
                bytestream_put_byte(&out_end, *ptr);
                ptr += offset;
            }
        }
    }
    return 0;
}
['static int decode_frame(AVCodecContext *avctx,\n                        void *data, int *data_size,\n                        const uint8_t *in_buf, int buf_size)\n{\n    SgiState *s = avctx->priv_data;\n    AVFrame *picture = data;\n    AVFrame *p = &s->picture;\n    const uint8_t *in_end = in_buf + buf_size;\n    unsigned int dimension, bytes_per_channel, rle;\n    int ret = 0;\n    uint8_t *out_buf, *out_end;\n    if (buf_size < SGI_HEADER_SIZE){\n        av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\\n", buf_size);\n        return -1;\n    }\n    if (bytestream_get_be16(&in_buf) != SGI_MAGIC) {\n        av_log(avctx, AV_LOG_ERROR, "bad magic number\\n");\n        return -1;\n    }\n    rle = bytestream_get_byte(&in_buf);\n    bytes_per_channel = bytestream_get_byte(&in_buf);\n    dimension = bytestream_get_be16(&in_buf);\n    s->width  = bytestream_get_be16(&in_buf);\n    s->height = bytestream_get_be16(&in_buf);\n    s->depth  = bytestream_get_be16(&in_buf);\n    if (bytes_per_channel != 1) {\n        av_log(avctx, AV_LOG_ERROR, "wrong channel number\\n");\n        return -1;\n    }\n    if (dimension != 2 && dimension != 3) {\n        av_log(avctx, AV_LOG_ERROR, "wrong dimension number\\n");\n        return -1;\n    }\n    if (s->depth == SGI_GRAYSCALE) {\n        avctx->pix_fmt = PIX_FMT_GRAY8;\n    } else if (s->depth == SGI_RGB) {\n        avctx->pix_fmt = PIX_FMT_RGB24;\n    } else if (s->depth == SGI_RGBA) {\n        avctx->pix_fmt = PIX_FMT_RGBA;\n    } else {\n        av_log(avctx, AV_LOG_ERROR, "wrong picture format\\n");\n        return -1;\n    }\n    if (avcodec_check_dimensions(avctx, s->width, s->height))\n        return -1;\n    avcodec_set_dimensions(avctx, s->width, s->height);\n    if (p->data[0])\n        avctx->release_buffer(avctx, p);\n    p->reference = 0;\n    if (avctx->get_buffer(avctx, p) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed.\\n");\n        return -1;\n    }\n    p->pict_type = FF_I_TYPE;\n    p->key_frame = 1;\n    out_buf = p->data[0];\n    out_end = out_buf + p->linesize[0] * s->height;\n    s->linesize = p->linesize[0];\n    in_buf += SGI_HEADER_SIZE - 12;\n    if (rle) {\n        ret = read_rle_sgi(out_end, in_buf, in_end, s);\n    } else {\n        ret = read_uncompressed_sgi(out_buf, out_end, in_buf, in_end, s);\n    }\n    if (ret == 0) {\n        *picture   = s->picture;\n        *data_size = sizeof(AVPicture);\n        return buf_size;\n    } else {\n        return -1;\n    }\n}', 'DEF  (be16, 2, AV_RB16, AV_WB16)', 'static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end,\n                const uint8_t *in_buf, const uint8_t *in_end, SgiState* s)\n{\n    int x, y, z;\n    const uint8_t *ptr;\n    unsigned int offset = s->height * s->width;\n    if (offset * s->depth > in_end - in_buf) {\n       return -1;\n    }\n    for (y = s->height - 1; y >= 0; y--) {\n        out_end = out_buf + (y * s->linesize);\n        for (x = s->width; x > 0; x--) {\n            ptr = in_buf++;\n            for(z = 0; z < s->depth; z ++) {\n                bytestream_put_byte(&out_end, *ptr);\n                ptr += offset;\n            }\n        }\n    }\n    return 0;\n}']