MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / dds_decode

Function dds_decode

libavcodec/dds.c:567–706  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

565}
566
567static int dds_decode(AVCodecContext *avctx, AVFrame *frame,
568 int *got_frame, AVPacket *avpkt)
569{
570 DDSContext *ctx = avctx->priv_data;
571 GetByteContext *gbc = &ctx->gbc;
572 int mipmap;
573 int ret;
574 int width, height;
575
576 ff_texturedsp_init(&ctx->texdsp);
577 bytestream2_init(gbc, avpkt->data, avpkt->size);
578
579 if (bytestream2_get_bytes_left(gbc) < 128) {
580 av_log(avctx, AV_LOG_ERROR, "Frame is too small (%d).\n",
581 bytestream2_get_bytes_left(gbc));
582 return AVERROR_INVALIDDATA;
583 }
584
585 if (bytestream2_get_le32(gbc) != MKTAG('D', 'D', 'S', ' ') ||
586 bytestream2_get_le32(gbc) != 124) { // header size
587 av_log(avctx, AV_LOG_ERROR, "Invalid DDS header.\n");
588 return AVERROR_INVALIDDATA;
589 }
590
591 bytestream2_skip(gbc, 4); // flags
592
593 height = bytestream2_get_le32(gbc);
594 width = bytestream2_get_le32(gbc);
595 ret = ff_set_dimensions(avctx, width, height);
596 if (ret < 0) {
597 av_log(avctx, AV_LOG_ERROR, "Invalid image size %dx%d.\n",
598 avctx->width, avctx->height);
599 return ret;
600 }
601
602 /* Since codec is based on 4x4 blocks, size is aligned to 4. */
603 avctx->coded_width = FFALIGN(avctx->width, TEXTURE_BLOCK_W);
604 avctx->coded_height = FFALIGN(avctx->height, TEXTURE_BLOCK_H);
605
606 bytestream2_skip(gbc, 4); // pitch
607 bytestream2_skip(gbc, 4); // depth
608 mipmap = bytestream2_get_le32(gbc);
609 if (mipmap != 0)
610 av_log(avctx, AV_LOG_VERBOSE, "Found %d mipmaps (ignored).\n", mipmap);
611
612 /* Extract pixel format information, considering additional elements
613 * in reserved1 and reserved2. */
614 ret = parse_pixel_format(avctx);
615 if (ret < 0)
616 return ret;
617
618 ret = ff_get_buffer(avctx, frame, 0);
619 if (ret < 0)
620 return ret;
621
622 if (ctx->compressed) {
623 int size = (avctx->coded_height / TEXTURE_BLOCK_H) *
624 (avctx->coded_width / TEXTURE_BLOCK_W) * ctx->dec.tex_ratio;

Callers

nothing calls this directly

Calls 12

ff_texturedsp_initFunction · 0.85
bytestream2_initFunction · 0.85
av_logFunction · 0.85
bytestream2_skipFunction · 0.85
ff_set_dimensionsFunction · 0.85
ff_get_bufferFunction · 0.85
bytestream2_get_bufferFunction · 0.85
av_image_get_linesizeFunction · 0.85
av_image_copy_planeFunction · 0.85
run_postprocFunction · 0.85
parse_pixel_formatFunction · 0.70

Tested by

no test coverage detected