@@ -348,42 +348,90 @@ void close_yuv_frame(yuv_frame_t *frame)
348
348
free (frame -> v );
349
349
}
350
350
351
- void read_yuv_frame (yuv_frame_t * frame , int width , int height , FILE * infile )
351
+ /*Extend the edge into the padding.*/
352
+ static void img_plane_edge_ext8 (unsigned char * dst_data , int dstride ,
353
+ int plane_width , int plane_height , int horz_padding , int vert_padding ) {
354
+ unsigned char * dst ;
355
+ int x ;
356
+ int y ;
357
+ /*Right side.*/
358
+ for (y = 0 ; y < plane_height ; y ++ ) {
359
+ dst = dst_data + plane_width - 1 + dstride * y ;
360
+ for (x = 1 ; x <= horz_padding ; x ++ ) {
361
+ dst [x ] = dst [0 ];
362
+ }
363
+ }
364
+ /*Bottom.*/
365
+ dst = dst_data - horz_padding + plane_height * dstride ;
366
+ for (y = 0 ; y < vert_padding ; y ++ ) {
367
+ for (x = 0 ; x < plane_width + horz_padding ; x ++ ) {
368
+ dst [x ] = (dst - dstride )[x ];
369
+ }
370
+ dst += dstride ;
371
+ }
372
+ }
373
+
374
+ void read_yuv_frame (yuv_frame_t * frame , int crop_width , int crop_height ,
375
+ int width , int height , FILE * infile )
352
376
{
353
- {
354
- unsigned int ysize = width * height ;
355
- unsigned int csize = ysize /4 ;
356
- if (fread (frame -> y , sizeof (unsigned char ), ysize , infile ) != ysize )
357
- {
358
- fatalerror ("Error reading Y from file" );
359
- }
360
- if (fread (frame -> u , sizeof (unsigned char ), csize , infile ) != csize )
361
- {
362
- fatalerror ("Error reading U from file" );
363
- }
364
- if (fread (frame -> v , sizeof (unsigned char ), csize , infile ) != csize )
365
- {
366
- fatalerror ("Error reading V from file" );
367
- }
377
+ int pli ;
378
+ for (pli = 0 ; pli < 3 ; pli ++ ) {
379
+ int xdec = pli == 0 ? 0 : 1 ;
380
+ int plane_width = (crop_width + xdec ) >> xdec ;
381
+ int plane_height = (crop_height + xdec ) >> xdec ;
382
+ int outstride = width >> xdec ;
383
+ int y ;
384
+ unsigned char * plane ;
385
+ switch (pli ) {
386
+ case 0 :
387
+ plane = frame -> y ;
388
+ break ;
389
+ case 1 :
390
+ plane = frame -> u ;
391
+ break ;
392
+ case 2 :
393
+ plane = frame -> v ;
394
+ break ;
395
+ }
396
+ for (y = 0 ; y < plane_height ; y ++ ) {
397
+ if (fread (plane + y * outstride , sizeof (unsigned char ), plane_width , infile )
398
+ != plane_width ) {
399
+ fatalerror ("Error reading plane from file" );
400
+ }
401
+ }
402
+ img_plane_edge_ext8 (plane , outstride , plane_width , plane_height ,
403
+ (width >> xdec ) - plane_width , (height >> xdec ) - plane_height );
368
404
}
369
405
}
370
406
371
- void write_yuv_frame (yuv_frame_t * frame , int width , int height , FILE * outfile )
407
+ void write_yuv_frame (yuv_frame_t * frame , int crop_width , int crop_height ,
408
+ int width , int height , FILE * outfile )
372
409
{
373
- unsigned int ysize = width * height ;
374
- unsigned int csize = ysize /4 ;
375
- if (fwrite (frame -> y , sizeof (unsigned char ), ysize , outfile ) != ysize )
376
- {
377
- fatalerror ("Error writing Y to file" );
378
- }
379
- if (fwrite (frame -> u , sizeof (unsigned char ), csize , outfile ) != csize )
380
- {
381
- fatalerror ("Error writing U to file" );
382
- }
383
- if (fwrite (frame -> v , sizeof (unsigned char ), csize , outfile ) != csize )
384
- {
385
- fatalerror ("Error writing V to file" );
386
- }
410
+ int pli ;
411
+ for (pli = 0 ; pli < 3 ; pli ++ ) {
412
+ int xdec = pli == 0 ? 0 : 1 ;
413
+ int plane_width = (crop_width + xdec ) >> xdec ;
414
+ int plane_height = (crop_height + xdec ) >> xdec ;
415
+ int y ;
416
+ unsigned char * plane ;
417
+ switch (pli ) {
418
+ case 0 :
419
+ plane = frame -> y ;
420
+ break ;
421
+ case 1 :
422
+ plane = frame -> u ;
423
+ break ;
424
+ case 2 :
425
+ plane = frame -> v ;
426
+ break ;
427
+ }
428
+ for (y = 0 ; y < plane_height ; y ++ ) {
429
+ if (fwrite (plane + y * (width >>xdec ), sizeof (unsigned char ), plane_width , outfile )
430
+ != plane_width ) {
431
+ fatalerror ("Error writing plane from file" );
432
+ }
433
+ }
434
+ }
387
435
}
388
436
389
437
void create_reference_frame (yuv_frame_t * ref ,yuv_frame_t * rec )
0 commit comments