MCPcopy Create free account
hub / github.com/AOMediaCodec/libavif / avifImageCopySamples

Function avifImageCopySamples

src/avif.c:187–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187void avifImageCopySamples(avifImage * dstImage, const avifImage * srcImage, avifPlanesFlags planes)
188{
189 assert(srcImage->depth == dstImage->depth);
190 if (planes & AVIF_PLANES_YUV) {
191 assert(srcImage->yuvFormat == dstImage->yuvFormat);
192 // Note that there may be a mismatch between srcImage->yuvRange and dstImage->yuvRange
193 // because libavif allows for 'colr' and AV1 OBU video range values to differ.
194 }
195 const size_t bytesPerPixel = avifImageUsesU16(srcImage) ? 2 : 1;
196
197 const avifBool skipColor = !(planes & AVIF_PLANES_YUV);
198 const avifBool skipAlpha = !(planes & AVIF_PLANES_A);
199 for (int c = AVIF_CHAN_Y; c <= AVIF_CHAN_A; ++c) {
200 const avifBool alpha = c == AVIF_CHAN_A;
201 if ((skipColor && !alpha) || (skipAlpha && alpha)) {
202 continue;
203 }
204
205 const uint32_t planeWidth = avifImagePlaneWidth(srcImage, c);
206 const uint32_t planeHeight = avifImagePlaneHeight(srcImage, c);
207 const uint8_t * srcRow = avifImagePlane(srcImage, c);
208 uint8_t * dstRow = avifImagePlane(dstImage, c);
209 const uint32_t srcRowBytes = avifImagePlaneRowBytes(srcImage, c);
210 const uint32_t dstRowBytes = avifImagePlaneRowBytes(dstImage, c);
211 assert(!srcRow == !dstRow);
212 if (!srcRow) {
213 continue;
214 }
215 assert(planeWidth == avifImagePlaneWidth(dstImage, c));
216 assert(planeHeight == avifImagePlaneHeight(dstImage, c));
217
218 const size_t planeWidthBytes = planeWidth * bytesPerPixel;
219 for (uint32_t y = 0; y < planeHeight; ++y) {
220 memcpy(dstRow, srcRow, planeWidthBytes);
221 srcRow += srcRowBytes;
222 dstRow += dstRowBytes;
223 }
224 }
225}
226
227static avifResult avifImageCopyProperties(avifImage * dstImage, const avifImage * srcImage)
228{

Callers 2

avifImageCopyFunction · 0.85

Calls 5

avifImageUsesU16Function · 0.85
avifImagePlaneWidthFunction · 0.85
avifImagePlaneHeightFunction · 0.85
avifImagePlaneFunction · 0.85
avifImagePlaneRowBytesFunction · 0.85

Tested by

no test coverage detected