X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Ficoenc.c;h=a7ada19fcd7c24777327171ff1e82cd08213b56b;hb=09dc6845662b74edb310c2088ffa4bb07c24fd76;hp=53d4420f37ab83113c98fc74cc4fff2a4667f505;hpb=e05704bd46b9107af25204dff47bd8b034868ae4;p=ffmpeg diff --git a/libavformat/icoenc.c b/libavformat/icoenc.c index 53d4420f37a..a7ada19fcd7 100644 --- a/libavformat/icoenc.c +++ b/libavformat/icoenc.c @@ -42,33 +42,33 @@ typedef struct { IcoImage *images; } IcoMuxContext; -static int ico_check_attributes(AVFormatContext *s, const AVCodecContext *c) +static int ico_check_attributes(AVFormatContext *s, const AVCodecParameters *p) { - if (c->codec_id == AV_CODEC_ID_BMP) { - if (c->pix_fmt == AV_PIX_FMT_PAL8 && AV_PIX_FMT_RGB32 != AV_PIX_FMT_BGRA) { + if (p->codec_id == AV_CODEC_ID_BMP) { + if (p->format == AV_PIX_FMT_PAL8 && AV_PIX_FMT_RGB32 != AV_PIX_FMT_BGRA) { av_log(s, AV_LOG_ERROR, "Wrong endianness for bmp pixel format\n"); return AVERROR(EINVAL); - } else if (c->pix_fmt != AV_PIX_FMT_PAL8 && - c->pix_fmt != AV_PIX_FMT_RGB555LE && - c->pix_fmt != AV_PIX_FMT_BGR24 && - c->pix_fmt != AV_PIX_FMT_BGRA) { + } else if (p->format != AV_PIX_FMT_PAL8 && + p->format != AV_PIX_FMT_RGB555LE && + p->format != AV_PIX_FMT_BGR24 && + p->format != AV_PIX_FMT_BGRA) { av_log(s, AV_LOG_ERROR, "BMP must be 1bit, 4bit, 8bit, 16bit, 24bit, or 32bit\n"); return AVERROR(EINVAL); } - } else if (c->codec_id == AV_CODEC_ID_PNG) { - if (c->pix_fmt != AV_PIX_FMT_RGBA) { + } else if (p->codec_id == AV_CODEC_ID_PNG) { + if (p->format != AV_PIX_FMT_RGBA) { av_log(s, AV_LOG_ERROR, "PNG in ico requires pixel format to be rgba\n"); return AVERROR(EINVAL); } } else { - const AVCodecDescriptor *codesc = avcodec_descriptor_get(c->codec_id); + const AVCodecDescriptor *codesc = avcodec_descriptor_get(p->codec_id); av_log(s, AV_LOG_ERROR, "Unsupported codec %s\n", codesc ? codesc->name : ""); return AVERROR(EINVAL); } - if (c->width > 256 || - c->height > 256) { - av_log(s, AV_LOG_ERROR, "Unsupported dimensions %dx%d (dimensions cannot exceed 256x256)\n", c->width, c->height); + if (p->width > 256 || + p->height > 256) { + av_log(s, AV_LOG_ERROR, "Unsupported dimensions %dx%d (dimensions cannot exceed 256x256)\n", p->width, p->height); return AVERROR(EINVAL); } @@ -95,7 +95,7 @@ static int ico_write_header(AVFormatContext *s) avio_skip(pb, 2); // skip the number of images for (i = 0; i < s->nb_streams; i++) { - if (ret = ico_check_attributes(s, s->streams[i]->codec)) + if (ret = ico_check_attributes(s, s->streams[i]->codecpar)) return ret; // Fill in later when writing trailer... @@ -116,7 +116,7 @@ static int ico_write_packet(AVFormatContext *s, AVPacket *pkt) IcoMuxContext *ico = s->priv_data; IcoImage *image; AVIOContext *pb = s->pb; - AVCodecContext *c = s->streams[pkt->stream_index]->codec; + AVCodecParameters *par = s->streams[pkt->stream_index]->codecpar; int i; if (ico->current_image >= ico->nb_images) { @@ -127,11 +127,11 @@ static int ico_write_packet(AVFormatContext *s, AVPacket *pkt) image = &ico->images[ico->current_image++]; image->offset = avio_tell(pb); - image->width = (c->width == 256) ? 0 : c->width; - image->height = (c->height == 256) ? 0 : c->height; + image->width = (par->width == 256) ? 0 : par->width; + image->height = (par->height == 256) ? 0 : par->height; - if (c->codec_id == AV_CODEC_ID_PNG) { - image->bits = c->bits_per_coded_sample; + if (par->codec_id == AV_CODEC_ID_PNG) { + image->bits = par->bits_per_coded_sample; image->size = pkt->size; avio_write(pb, pkt->data, pkt->size); @@ -142,13 +142,13 @@ static int ico_write_packet(AVFormatContext *s, AVPacket *pkt) } image->bits = AV_RL16(pkt->data + 28); // allows things like 1bit and 4bit images to be preserved - image->size = pkt->size - 14 + c->height * (c->width + 7) / 8; + image->size = pkt->size - 14 + par->height * (par->width + 7) / 8; avio_write(pb, pkt->data + 14, 8); // Skip the BITMAPFILEHEADER header avio_wl32(pb, AV_RL32(pkt->data + 22) * 2); // rewrite height as 2 * height avio_write(pb, pkt->data + 26, pkt->size - 26); - for (i = 0; i < c->height * (c->width + 7) / 8; ++i) + for (i = 0; i < par->height * (par->width + 7) / 8; ++i) avio_w8(pb, 0x00); // Write bitmask (opaque) } @@ -169,8 +169,8 @@ static int ico_write_trailer(AVFormatContext *s) avio_w8(pb, ico->images[i].width); avio_w8(pb, ico->images[i].height); - if (s->streams[i]->codec->codec_id == AV_CODEC_ID_BMP && - s->streams[i]->codec->pix_fmt == AV_PIX_FMT_PAL8) { + if (s->streams[i]->codecpar->codec_id == AV_CODEC_ID_BMP && + s->streams[i]->codecpar->format == AV_PIX_FMT_PAL8) { avio_w8(pb, (ico->images[i].bits >= 8) ? 0 : 1 << ico->images[i].bits); } else { avio_w8(pb, 0);