Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (item_id == c->primary_item_id) {
- AVFrame *tile = av_frame_alloc();
- AVFrame *frame = av_frame_alloc();
- unsigned grid_width, grid_height, cnt, size;
- /* assuming 'grid' item is the primary item in tiled heif */
- pos = avio_tell(pb);
- if ((ret = avio_seek(pb, item_pos, SEEK_SET)) < 0)
- goto err;
- if ((ret = read_image_grid(c, pb)) < 0)
- goto err;
- if ((ret = avio_seek(pb, pos, SEEK_SET)) < 0)
- goto err;
- grid_width = c->tile_width * c->grid_cols;
- grid_height = c->tile_height * c->grid_rows;
- av_log(c->fc, AV_LOG_INFO, "tile res %dx%d, grid res %dx%d, output res %dx%d\n",
- c->tile_width, c->tile_height,
- grid_width, grid_height,
- c->output_width, c->output_height);
- for (cnt = 0; cnt < c->nb_tiles; cnt++) {
- AVPacket pkt;
- int plane;
- AVIndexEntry *e = &st->index_entries[cnt];
- item_pos = e->pos;
- ext_length = e->size;
- pos = avio_tell(pb);
- if ((avio_seek(pb, item_pos, SEEK_SET)) < 0)
- goto err;
- if ((ret = av_get_packet(pb, &pkt, ext_length)) < 0)
- goto err;
- if ((avio_seek(pb, pos, SEEK_SET)) < 0)
- goto err;
- ret = avcodec_send_packet(dec_ctx, &pkt);
- if (ret < 0) {
- av_log(c->fc, AV_LOG_ERROR, "Error sending tile for decoding\n");
- goto err;
- }
- ret = avcodec_receive_frame(dec_ctx, tile);
- if (ret < 0) {
- av_log(c->fc, AV_LOG_ERROR, "Error decoding tile\n");
- goto err;
- }
- if (!cnt) {
- av_frame_copy_props(frame, tile);
- frame->width = grid_width;
- frame->height = grid_height;
- frame->format = tile->format;
- ret = av_image_alloc(frame->data, frame->linesize,
- frame->width, frame->height,
- frame->format, 1);
- if (ret < 0)
- goto err;
- /*ret = av_frame_make_writable(frame);*/
- /*if (ret < 0)*/
- /*goto err;*/
- ret = av_image_fill_black(frame->data,
- (const ptrdiff_t *)frame->linesize,
- frame->format, frame->color_range,
- frame->width, frame->height);
- if (ret < 0)
- goto err;
- }
- av_log(c->fc, AV_LOG_INFO, "cnt %d\t\n", cnt);
- for (plane = 0; plane < 3; plane++) {
- uint8_t *p, *q;
- unsigned x, y, line;
- x = (cnt % c->grid_cols) * c->tile_width;
- y = (cnt / c->grid_cols) * c->tile_height;
- p = &tile->data[plane][0];
- q = &frame->data[plane][y * frame->linesize[plane] + x];
- av_log(c->fc, AV_LOG_INFO, "x, y: %d %d\t\n", x, y);
- for (line = 0; line < c->tile_height; line++) {
- memcpy(q, p, c->tile_width);
- p += tile->linesize[plane];
- q += frame->linesize[plane];
- }
- }
- }
- size = av_image_get_buffer_size(tile->format, frame->width,
- frame->height, 32);
- av_new_packet(&st->attached_pic, size);
- av_image_copy_to_buffer(st->attached_pic.data, size,
- (const uint8_t **)frame->data,
- frame->linesize, frame->format,
- frame->width, frame->height, 32);
- st->disposition |= AV_DISPOSITION_ATTACHED_PIC;
- st->attached_pic.stream_index = st->index;
- st->attached_pic.flags |= AV_PKT_FLAG_KEY;
- st->codecpar->width = grid_width;
- st->codecpar->height = grid_height;
- st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO;
- st->codecpar->format = frame->format;
- avcodec_close(dec_ctx);
- avcodec_free_context(&dec_ctx);
- av_frame_free(&tile);
- av_frame_free(&frame);
- av_freep(&st->index_entries);
Add Comment
Please, Sign In to add comment