Invoke the MJPEG decoder to decode the tile. */
| 340 | |
| 341 | /* Invoke the MJPEG decoder to decode the tile. */ |
| 342 | static int tdsc_decode_jpeg_tile(AVCodecContext *avctx, int tile_size, |
| 343 | int x, int y, int w, int h) |
| 344 | { |
| 345 | TDSCContext *ctx = avctx->priv_data; |
| 346 | int ret; |
| 347 | |
| 348 | /* Prepare a packet and send to the MJPEG decoder */ |
| 349 | av_packet_unref(ctx->jpkt); |
| 350 | ctx->jpkt->data = ctx->tilebuffer; |
| 351 | ctx->jpkt->size = tile_size; |
| 352 | |
| 353 | ret = avcodec_send_packet(ctx->jpeg_avctx, ctx->jpkt); |
| 354 | if (ret < 0) { |
| 355 | av_log(avctx, AV_LOG_ERROR, "Error submitting a packet for decoding\n"); |
| 356 | return ret; |
| 357 | } |
| 358 | |
| 359 | ret = avcodec_receive_frame(ctx->jpeg_avctx, ctx->jpgframe); |
| 360 | if (ret < 0 || ctx->jpgframe->format != AV_PIX_FMT_YUVJ420P || |
| 361 | w > ctx->jpgframe->width || h > ctx->jpgframe->height) { |
| 362 | av_log(avctx, AV_LOG_ERROR, |
| 363 | "JPEG decoding error (%d).\n", ret); |
| 364 | |
| 365 | /* Normally skip, error if explode */ |
| 366 | if (avctx->err_recognition & AV_EF_EXPLODE) |
| 367 | return AVERROR_INVALIDDATA; |
| 368 | else |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | /* Let's paint onto the buffer */ |
| 373 | tdsc_blit(ctx->refframe->data[0] + x * 3 + ctx->refframe->linesize[0] * y, |
| 374 | ctx->refframe->linesize[0], |
| 375 | ctx->jpgframe->data[0], ctx->jpgframe->linesize[0], |
| 376 | ctx->jpgframe->data[1], ctx->jpgframe->data[2], |
| 377 | ctx->jpgframe->linesize[1], w, h); |
| 378 | |
| 379 | av_frame_unref(ctx->jpgframe); |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* Parse frame and either copy data or decode JPEG. */ |
| 385 | static int tdsc_decode_tiles(AVCodecContext *avctx, int number_tiles) |
no test coverage detected