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

Function parse_pixel_format

libavcodec/dds.c:111–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109} DDSContext;
110
111static int parse_pixel_format(AVCodecContext *avctx)
112{
113 DDSContext *ctx = avctx->priv_data;
114 GetByteContext *gbc = &ctx->gbc;
115 uint32_t flags, fourcc, gimp_tag;
116 enum DDSDXGIFormat dxgi;
117 int size, bpp, r, g, b, a;
118 int alpha_exponent, ycocg_classic, ycocg_scaled, normal_map, array;
119
120 /* Alternative DDS implementations use reserved1 as custom header. */
121 bytestream2_skip(gbc, 4 * 3);
122 gimp_tag = bytestream2_get_le32(gbc);
123 alpha_exponent = gimp_tag == MKTAG('A', 'E', 'X', 'P');
124 ycocg_classic = gimp_tag == MKTAG('Y', 'C', 'G', '1');
125 ycocg_scaled = gimp_tag == MKTAG('Y', 'C', 'G', '2');
126 bytestream2_skip(gbc, 4 * 7);
127
128 /* Now the real DDPF starts. */
129 size = bytestream2_get_le32(gbc);
130 if (size != 32) {
131 av_log(avctx, AV_LOG_ERROR, "Invalid pixel format header %d.\n", size);
132 return AVERROR_INVALIDDATA;
133 }
134 flags = bytestream2_get_le32(gbc);
135 ctx->compressed = flags & DDPF_FOURCC;
136 ctx->paletted = flags & DDPF_PALETTE;
137 normal_map = flags & DDPF_NORMALMAP;
138 fourcc = bytestream2_get_le32(gbc);
139
140 if (ctx->compressed && ctx->paletted) {
141 av_log(avctx, AV_LOG_WARNING,
142 "Disabling invalid palette flag for compressed dds.\n");
143 ctx->paletted = 0;
144 }
145
146 bpp = ctx->bpp = bytestream2_get_le32(gbc); // rgbbitcount
147 r = bytestream2_get_le32(gbc); // rbitmask
148 g = bytestream2_get_le32(gbc); // gbitmask
149 b = bytestream2_get_le32(gbc); // bbitmask
150 a = bytestream2_get_le32(gbc); // abitmask
151
152 bytestream2_skip(gbc, 4); // caps
153 bytestream2_skip(gbc, 4); // caps2
154 bytestream2_skip(gbc, 4); // caps3
155 bytestream2_skip(gbc, 4); // caps4
156 bytestream2_skip(gbc, 4); // reserved2
157
158 av_log(avctx, AV_LOG_VERBOSE, "fourcc %s bpp %d "
159 "r 0x%x g 0x%x b 0x%x a 0x%x\n", av_fourcc2str(fourcc), bpp, r, g, b, a);
160 if (gimp_tag)
161 av_log(avctx, AV_LOG_VERBOSE, "and GIMP-DDS tag %s\n", av_fourcc2str(gimp_tag));
162
163 if (ctx->compressed)
164 avctx->pix_fmt = AV_PIX_FMT_RGBA;
165
166 if (ctx->compressed) {
167 ctx->dec.raw_ratio = 16;
168 switch (fourcc) {

Callers 1

dds_decodeFunction · 0.70

Calls 2

bytestream2_skipFunction · 0.85
av_logFunction · 0.85

Tested by

no test coverage detected