diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
index c33265d..34ac38a 100644
|
a
|
b
|
static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
|
| 51 | 51 | AVFrame *picture = data; |
| 52 | 52 | AVFrame * const p = &s->picture; |
| 53 | 53 | unsigned int w, h, depth, type, maptype, maplength, stride, x, y, len, alen; |
| 54 | | uint8_t *ptr; |
| | 54 | uint8_t *ptr, *ptr2; |
| 55 | 55 | const uint8_t *bufstart = buf; |
| 56 | 56 | |
| 57 | 57 | if (avpkt->size < 32) |
| … |
… |
static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
|
| 90 | 90 | |
| 91 | 91 | switch (depth) { |
| 92 | 92 | case 1: |
| 93 | | avctx->pix_fmt = PIX_FMT_MONOWHITE; |
| | 93 | avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_MONOWHITE; |
| | 94 | break; |
| | 95 | case 4: |
| | 96 | avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_NONE; |
| 94 | 97 | break; |
| 95 | 98 | case 8: |
| 96 | 99 | avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_GRAY8; |
| … |
… |
static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
|
| 118 | 121 | if (buf_end - buf < maplength) |
| 119 | 122 | return AVERROR_INVALIDDATA; |
| 120 | 123 | |
| 121 | | if (depth != 8 && maplength) { |
| | 124 | if (depth > 8 && maplength) { |
| 122 | 125 | av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n"); |
| 123 | 126 | |
| 124 | 127 | } else if (maplength) { |
| … |
… |
static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
|
| 140 | 143 | |
| 141 | 144 | buf += maplength; |
| 142 | 145 | |
| | 146 | if (maplength && depth < 8) { |
| | 147 | ptr = ptr2 = av_malloc((w + 15) * h); |
| | 148 | stride = (w + 15 >> 3) * depth; |
| | 149 | } else { |
| 143 | 150 | ptr = p->data[0]; |
| 144 | 151 | stride = p->linesize[0]; |
| | 152 | } |
| 145 | 153 | |
| 146 | 154 | /* scanlines are aligned on 16 bit boundaries */ |
| 147 | 155 | len = (depth * w + 7) >> 3; |
| … |
… |
static int sunrast_decode_frame(AVCodecContext *avctx, void *data,
|
| 182 | 190 | buf += alen; |
| 183 | 191 | } |
| 184 | 192 | } |
| | 193 | if (avctx->pix_fmt == PIX_FMT_PAL8 && depth < 8) { |
| | 194 | uint8_t *ptr_free = ptr2; |
| | 195 | ptr = p->data[0]; |
| | 196 | for (y=0; y<h; y++) { |
| | 197 | x = (w + 7 >> 3) * depth; |
| | 198 | do { |
| | 199 | if (depth == 1) { |
| | 200 | ptr[8*x+7] = ptr2[x] & 1; |
| | 201 | ptr[8*x+6] = ptr2[x] >> 1 & 1; |
| | 202 | ptr[8*x+5] = ptr2[x] >> 2 & 1; |
| | 203 | ptr[8*x+4] = ptr2[x] >> 3 & 1; |
| | 204 | ptr[8*x+3] = ptr2[x] >> 4 & 1; |
| | 205 | ptr[8*x+2] = ptr2[x] >> 5 & 1; |
| | 206 | ptr[8*x+1] = ptr2[x] >> 6 & 1; |
| | 207 | ptr[8*x] = ptr2[x] >> 7; |
| | 208 | } else { |
| | 209 | ptr[2*x+1] = ptr2[x] & 0xF; |
| | 210 | ptr[2*x] = ptr2[x] >> 4; |
| | 211 | } |
| | 212 | } while (x--); |
| | 213 | ptr += p->linesize[0]; |
| | 214 | ptr2 += (w + 15 >> 3) * depth; |
| | 215 | } |
| | 216 | av_freep(&ptr_free); |
| | 217 | } |
| 185 | 218 | |
| 186 | 219 | *picture = s->picture; |
| 187 | 220 | *data_size = sizeof(AVFrame); |
| … |
… |
AVCodec ff_sunrast_decoder = {
|
| 206 | 239 | .init = sunrast_init, |
| 207 | 240 | .close = sunrast_end, |
| 208 | 241 | .decode = sunrast_decode_frame, |
| 209 | | .capabilities = CODEC_CAP_DR1, |
| | 242 | // .capabilities = CODEC_CAP_DR1, |
| 210 | 243 | .long_name = NULL_IF_CONFIG_SMALL("Sun Rasterfile image"), |
| 211 | 244 | }; |