Lines Matching defs:avctx

154 static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
156 IffContext *s = avctx->priv_data;
158 const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata);
159 int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
161 if (avctx->bits_per_coded_sample > 8) {
162 av_log(avctx, AV_LOG_ERROR, "bits_per_coded_sample > 8 not supported\n");
166 count = 1 << avctx->bits_per_coded_sample;
178 count = 1 << avctx->bits_per_coded_sample;
181 pal[i] = 0xFF000000 | gray2rgb((i * 255) >> avctx->bits_per_coded_sample);
184 if ((1 << avctx->bits_per_coded_sample) < count) {
185 avpriv_request_sample(avctx, "overlapping mask");
188 memcpy(pal + (1 << avctx->bits_per_coded_sample), pal, count * 4);
192 s->transparency < 1 << avctx->bits_per_coded_sample)
201 * @param avctx the AVCodecContext where to extract extra context to
202 * @param avpkt the AVPacket to extract extra context from or NULL to use avctx
205 static int extract_header(AVCodecContext *const avctx,
208 IffContext *s = avctx->priv_data;
213 if (avctx->extradata_size < 2) {
214 av_log(avctx, AV_LOG_ERROR, "not enough extradata\n");
217 palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
219 if (avpkt && avctx->codec_tag == MKTAG('A', 'N', 'I', 'M')) {
268 buf = avctx->extradata;
271 av_log(avctx, AV_LOG_ERROR,
290 av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u\n", s->ham);
293 av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u, BPP: %u\n", s->ham, s->bpp);
300 avctx->pix_fmt = AV_PIX_FMT_RGB32;
304 av_log(avctx, AV_LOG_ERROR, "bpp %d too large for palette\n", s->bpp);
318 av_log(avctx, AV_LOG_ERROR, "Masking not supported\n");
322 av_log(avctx, AV_LOG_ERROR, "Invalid number of bitplanes: %u\n", s->bpp);
325 if (s->video_size && s->planesize * s->bpp * avctx->height > s->video_size)
334 const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata);
337 if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ') && s->ham == 4)
385 static av_cold int decode_end(AVCodecContext *avctx)
387 IffContext *s = avctx->priv_data;
399 static av_cold int decode_init(AVCodecContext *avctx)
401 IffContext *s = avctx->priv_data;
404 if (avctx->bits_per_coded_sample <= 8) {
407 if (avctx->extradata_size >= 2)
408 palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
411 avctx->pix_fmt = (avctx->bits_per_coded_sample < 8) ||
412 (avctx->extradata_size >= 2 && palette_size) ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8;
413 } else if (avctx->bits_per_coded_sample <= 32) {
414 if (avctx->codec_tag == MKTAG('R', 'G', 'B', '8')) {
415 avctx->pix_fmt = AV_PIX_FMT_RGB32;
416 } else if (avctx->codec_tag == MKTAG('R', 'G', 'B', 'N')) {
417 avctx->pix_fmt = AV_PIX_FMT_RGB444;
418 } else if (avctx->codec_tag != MKTAG('D', 'E', 'E', 'P')) {
419 if (avctx->bits_per_coded_sample == 24) {
420 avctx->pix_fmt = AV_PIX_FMT_0BGR32;
421 } else if (avctx->bits_per_coded_sample == 32) {
422 avctx->pix_fmt = AV_PIX_FMT_BGR32;
424 avpriv_request_sample(avctx, "unknown bits_per_coded_sample");
432 if ((err = av_image_check_size(avctx->width, avctx->height, 0, avctx)))
434 s->planesize = FFALIGN(avctx->width, 16) >> 3; // Align plane size in bits to word-boundary
435 s->planebuf = av_malloc(s->planesize * avctx->height + AV_INPUT_BUFFER_PADDING_SIZE);
439 s->bpp = avctx->bits_per_coded_sample;
441 if (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M')) {
442 s->video_size = FFALIGN(avctx->width, 2) * avctx->height * s->bpp;
445 s->video[0] = av_calloc(FFALIGN(avctx->width, 2) * avctx->height, s->bpp);
446 s->video[1] = av_calloc(FFALIGN(avctx->width, 2) * avctx->height, s->bpp);
452 if ((err = extract_header(avctx, NULL)) < 0)
1521 static int unsupported(AVCodecContext *avctx)
1523 IffContext *s = avctx->priv_data;
1524 avpriv_request_sample(avctx, "bitmap (compression 0x%0x, bpp %i, ham %i, interlaced %i)", s->compression, s->bpp, s->ham, s->is_interlaced);
1528 static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
1531 IffContext *s = avctx->priv_data;
1541 if ((res = extract_header(avctx, avpkt)) < 0)
1544 if ((res = ff_get_buffer(avctx, frame, 0)) < 0)
1550 desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1552 if (!s->init && avctx->bits_per_coded_sample <= 8 - (s->masking == MASK_HAS_MASK) &&
1553 avctx->pix_fmt == AV_PIX_FMT_PAL8) {
1554 if ((res = cmap_read_palette(avctx, (uint32_t *)frame->data[1])) < 0)
1556 } else if (!s->init && avctx->bits_per_coded_sample <= 8 &&
1557 avctx->pix_fmt == AV_PIX_FMT_RGB32) {
1558 if ((res = cmap_read_palette(avctx, s->mask_palbuf)) < 0)
1563 if (s->compression <= 0xff && (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M'))) {
1564 if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
1570 if (avctx->codec_tag == MKTAG('A', 'C', 'B', 'M')) {
1571 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
1572 memset(frame->data[0], 0, avctx->height * frame->linesize[0]);
1574 for (y = 0; y < avctx->height && buf < buf_end; y++) {
1581 memset(frame->data[0], 0, avctx->height * frame->linesize[0]);
1582 for (y = 0; y < avctx->height; y++) {
1586 const uint8_t * start = buf + (plane * avctx->height + y) * s->planesize;
1594 return unsupported(avctx);
1595 } else if (avctx->codec_tag == MKTAG('D', 'E', 'E', 'P')) {
1596 int raw_width = avctx->width * (av_get_bits_per_pixel(desc) >> 3);
1598 for (y = 0; y < avctx->height && buf < buf_end; y++) {
1602 if (avctx->pix_fmt == AV_PIX_FMT_BGR32) {
1603 for (x = 0; x < avctx->width; x++)
1607 } else if (avctx->codec_tag == MKTAG('I', 'L', 'B', 'M') || // interleaved
1608 avctx->codec_tag == MKTAG('A', 'N', 'I', 'M')) {
1609 if (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M'))
1611 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
1612 for (y = 0; y < avctx->height; y++) {
1614 memset(row, 0, avctx->width);
1621 for (y = 0; y < avctx->height; y++) {
1631 for (y = 0; y < avctx->height; y++) {
1633 memset(row, 0, avctx->width << 2);
1641 } else if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ')) { // IFF-PBM
1642 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
1643 for (y = 0; y < avctx->height && buf_end > buf; y++) {
1645 memcpy(row, buf, FFMIN(avctx->width, buf_end - buf));
1646 buf += avctx->width + (avctx->width % 2); // padding if odd
1649 for (y = 0; y < avctx->height && buf_end > buf; y++) {
1651 memcpy(s->ham_buf, buf, FFMIN(avctx->width, buf_end - buf));
1652 buf += avctx->width + (avctx->width & 1); // padding if odd
1656 return unsupported(avctx);
1658 return unsupported(avctx);
1662 if (avctx->codec_tag == MKTAG('I', 'L', 'B', 'M') || // interleaved
1663 avctx->codec_tag == MKTAG('A', 'N', 'I', 'M')) {
1664 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
1667 for (y = 0; y < avctx->height; y++) {
1669 memset(row, 0, avctx->width);
1672 if (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M')) {
1679 } else if (avctx->bits_per_coded_sample <= 8) { //8-bit (+ mask) to AV_PIX_FMT_BGR32
1680 for (y = 0; y < avctx->height; y++) {
1682 memset(s->mask_buf, 0, avctx->width * sizeof(uint32_t));
1687 lookup_pal_indicies((uint32_t *)row, s->mask_buf, s->mask_palbuf, avctx->width);
1691 for (y = 0; y < avctx->height; y++) {
1696 if (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M')) {
1705 for (y = 0; y < avctx->height; y++) {
1707 memset(row, 0, avctx->width << 2);
1714 } else if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ')) { // IFF-PBM
1715 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
1716 for (y = 0; y < avctx->height; y++) {
1718 buf += decode_byterun(row, avctx->width, gb);
1721 for (y = 0; y < avctx->height; y++) {
1723 buf += decode_byterun(s->ham_buf, avctx->width, gb);
1727 return unsupported(avctx);
1728 } else if (avctx->codec_tag == MKTAG('D', 'E', 'E', 'P')) { // IFF-DEEP
1730 decode_deep_rle32(frame->data[0], buf, buf_size, avctx->width, avctx->height, frame->linesize[0]);
1732 return unsupported(avctx);
1733 } else if (avctx->codec_tag == MKTAG('A', 'C', 'B', 'M')) {
1734 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
1735 memset(frame->data[0], 0, avctx->height * frame->linesize[0]);
1737 for (y = 0; y < avctx->height && buf < buf_end; y++) {
1744 memset(frame->data[0], 0, avctx->height * frame->linesize[0]);
1745 for (y = 0; y < avctx->height; y++) {
1749 const uint8_t * start = buf + (plane * avctx->height + y) * s->planesize;
1757 return unsupported(avctx);
1760 return unsupported(avctx);
1764 if (avctx->codec_tag == MKTAG('I', 'L', 'B', 'M') && avctx->pix_fmt == AV_PIX_FMT_PAL8) {
1766 decode_byterun2(s->planebuf, avctx->height, s->planesize, gb);
1767 for (y = 0; y < avctx->height; y++) {
1773 return unsupported(avctx);
1777 if (avctx->codec_tag == MKTAG('R', 'G', 'B', '8') && avctx->pix_fmt == AV_PIX_FMT_RGB32)
1778 decode_rgb8(gb, frame->data[0], avctx->width, avctx->height, frame->linesize[0]);
1779 else if (avctx->codec_tag == MKTAG('R', 'G', 'B', 'N') && avctx->pix_fmt == AV_PIX_FMT_RGB444)
1780 decode_rgbn(gb, frame->data[0], avctx->width, avctx->height, frame->linesize[0]);
1782 return unsupported(avctx);
1785 if (avctx->codec_tag == MKTAG('D', 'E', 'E', 'P')) {
1787 decode_deep_tvdc32(frame->data[0], buf, buf_size, avctx->width, avctx->height, frame->linesize[0], s->tvdc);
1789 return unsupported(avctx);
1791 return unsupported(avctx);
1795 decode_short_horizontal_delta(s->video[0], buf, buf_end, avctx->width, s->bpp, s->video_size);
1799 decode_byte_vertical_delta(s->video[0], buf, buf_end, avctx->width, s->is_brush, s->bpp, s->video_size);
1804 decode_short_vertical_delta(s->video[0], buf, buf_end, avctx->width, s->bpp, s->video_size);
1806 decode_long_vertical_delta(s->video[0], buf, buf_end, avctx->width, s->bpp, s->video_size);
1811 decode_short_vertical_delta2(s->video[0], buf, buf_end, avctx->width, s->bpp, s->video_size);
1813 decode_long_vertical_delta2(s->video[0], buf, buf_end, avctx->width, s->bpp, s->video_size);
1817 decode_delta_j(s->video[0], buf, buf_end, avctx->width, avctx->height, s->bpp, s->video_size);
1822 return unsupported(avctx);
1823 decode_delta_d(s->video[0], buf, buf_end, avctx->width, s->is_interlaced, s->bpp, s->video_size);
1828 return unsupported(avctx);
1829 decode_delta_e(s->video[0], buf, buf_end, avctx->width, s->is_interlaced, s->bpp, s->video_size);
1833 decode_delta_l(s->video[0], buf, buf_end, avctx->width, s->is_short, s->bpp, s->video_size);
1836 return unsupported(avctx);
1839 if (s->compression <= 0xff && (avctx->codec_tag == MKTAG('A', 'N', 'I', 'M'))) {
1844 if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
1846 for (y = 0; y < avctx->height; y++) {
1848 memset(row, 0, avctx->width);
1854 if (avctx->pix_fmt == AV_PIX_FMT_PAL8)
1878 for (y = 0; y < avctx->height; y++) {
1888 return unsupported(avctx);