| 136 | } |
| 137 | |
| 138 | static int decode_frame(AVCodecContext *avctx, AVFrame *frame, |
| 139 | int *got_frame, AVPacket *avpkt) |
| 140 | { |
| 141 | MSCCContext *s = avctx->priv_data; |
| 142 | z_stream *const zstream = &s->zstream.zstream; |
| 143 | const uint8_t *buf = avpkt->data; |
| 144 | int buf_size = avpkt->size; |
| 145 | GetByteContext gb; |
| 146 | PutByteContext pb; |
| 147 | int ret, j; |
| 148 | |
| 149 | if (avpkt->size < 3) |
| 150 | return buf_size; |
| 151 | |
| 152 | ret = inflateReset(zstream); |
| 153 | if (ret != Z_OK) { |
| 154 | av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", ret); |
| 155 | return AVERROR_UNKNOWN; |
| 156 | } |
| 157 | zstream->next_out = s->decomp_buf; |
| 158 | zstream->avail_out = s->decomp_size; |
| 159 | if (avctx->codec_id == AV_CODEC_ID_MSCC) { |
| 160 | const uint8_t start = avpkt->data[2] ^ avpkt->data[0]; |
| 161 | |
| 162 | zstream->next_in = &start; |
| 163 | zstream->avail_in = 1; |
| 164 | ret = inflate(zstream, Z_NO_FLUSH); |
| 165 | if (ret != Z_OK || zstream->avail_in != 0) |
| 166 | goto inflate_error; |
| 167 | |
| 168 | buf += 3; |
| 169 | buf_size -= 3; |
| 170 | } |
| 171 | zstream->next_in = buf; |
| 172 | zstream->avail_in = buf_size; |
| 173 | ret = inflate(zstream, Z_FINISH); |
| 174 | if (ret != Z_STREAM_END) { |
| 175 | inflate_error: |
| 176 | av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", ret); |
| 177 | return AVERROR_UNKNOWN; |
| 178 | } |
| 179 | if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) |
| 180 | return ret; |
| 181 | |
| 182 | if (avctx->pix_fmt == AV_PIX_FMT_PAL8) { |
| 183 | size_t size; |
| 184 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, &size); |
| 185 | |
| 186 | if (pal && size == AVPALETTE_SIZE) { |
| 187 | for (j = 0; j < 256; j++) |
| 188 | s->pal[j] = 0xFF000000 | AV_RL32(pal + j * 4); |
| 189 | } else if (pal) { |
| 190 | av_log(avctx, AV_LOG_ERROR, |
| 191 | "Palette size %zu is wrong\n", size); |
| 192 | } |
| 193 | memcpy(frame->data[1], s->pal, AVPALETTE_SIZE); |
| 194 | } |
| 195 |
nothing calls this directly
no test coverage detected