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

Function encode_scanline_zip

libavcodec/exrenc.c:279–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277}
278
279static int encode_scanline_zip(EXRContext *s, const AVFrame *frame)
280{
281 const int64_t element_size = s->pixel_type == EXR_HALF ? 2LL : 4LL;
282
283 for (int y = 0; y < s->nb_scanlines; y++) {
284 EXRScanlineData *scanline = &s->scanline[y];
285 const int scanline_height = FFMIN(s->scanline_height, frame->height - y * s->scanline_height);
286 int64_t tmp_size = element_size * s->planes * frame->width * scanline_height;
287 int64_t max_compressed_size = tmp_size * 3 / 2;
288 unsigned long actual_size, source_size;
289
290 av_fast_padded_malloc(&scanline->uncompressed_data, &scanline->uncompressed_size, tmp_size);
291 if (!scanline->uncompressed_data)
292 return AVERROR(ENOMEM);
293
294 av_fast_padded_malloc(&scanline->tmp, &scanline->tmp_size, tmp_size);
295 if (!scanline->tmp)
296 return AVERROR(ENOMEM);
297
298 av_fast_padded_malloc(&scanline->compressed_data, &scanline->compressed_size, max_compressed_size);
299 if (!scanline->compressed_data)
300 return AVERROR(ENOMEM);
301
302 switch (s->pixel_type) {
303 case EXR_FLOAT:
304 for (int l = 0; l < scanline_height; l++) {
305 const int scanline_size = frame->width * 4 * s->planes;
306
307 for (int p = 0; p < s->planes; p++) {
308 int ch = s->ch_order[p];
309
310 memcpy(scanline->uncompressed_data + scanline_size * l + p * frame->width * 4,
311 frame->data[ch] + (y * s->scanline_height + l) * frame->linesize[ch],
312 frame->width * 4);
313 }
314 }
315 break;
316 case EXR_HALF:
317 for (int l = 0; l < scanline_height; l++) {
318 const int scanline_size = frame->width * 2 * s->planes;
319
320 for (int p = 0; p < s->planes; p++) {
321 int ch = s->ch_order[p];
322 uint16_t *dst = (uint16_t *)(scanline->uncompressed_data + scanline_size * l + p * frame->width * 2);
323 const uint32_t *src = (const uint32_t *)(frame->data[ch] + (y * s->scanline_height + l) * frame->linesize[ch]);
324
325 for (int x = 0; x < frame->width; x++)
326 dst[x] = float2half(src[x], &s->f2h_tables);
327 }
328 }
329 break;
330 }
331
332 reorder_pixels(scanline->tmp, scanline->uncompressed_data, tmp_size);
333 predictor(scanline->tmp, tmp_size);
334 source_size = tmp_size;
335 actual_size = max_compressed_size;
336 compress(scanline->compressed_data, &actual_size,

Callers 1

encode_frameFunction · 0.85

Calls 4

av_fast_padded_mallocFunction · 0.85
float2halfFunction · 0.85
reorder_pixelsFunction · 0.85
predictorFunction · 0.70

Tested by

no test coverage detected