@@ -55,7 +55,6 @@ static inline void *ALLOC_ALIGNED(size_t alignment, size_t size) {
55
55
if (posix_memalign (&mem, alignment, size) != 0 ) {
56
56
return NULL ;
57
57
}
58
- memset (mem, 0 , size);
59
58
return mem;
60
59
};
61
60
#define FREE_ALIGNED (mem ) free((mem))
@@ -155,6 +154,8 @@ static int de265_image_get_buffer(de265_decoder_context* ctx,
155
154
img->set_image_plane (1 , p[1 ], chroma_stride, NULL );
156
155
img->set_image_plane (2 , p[2 ], chroma_stride, NULL );
157
156
157
+ img->fill_image (0 ,0 ,0 );
158
+
158
159
return 1 ;
159
160
}
160
161
@@ -527,18 +528,72 @@ void de265_image::release()
527
528
}
528
529
529
530
531
+ void de265_image::fill_plane (int channel, int value)
532
+ {
533
+ int bytes_per_pixel = get_bytes_per_pixel (channel);
534
+ assert (value >= 0 ); // needed for the shift operation in the check below
535
+
536
+ if (bytes_per_pixel == 1 ) {
537
+ if (channel==0 ) {
538
+ memset (pixels[channel], value, stride * height);
539
+ }
540
+ else {
541
+ memset (pixels[channel], value, chroma_stride * chroma_height);
542
+ }
543
+ }
544
+ else if ((value >> 8 ) == (value & 0xFF )) {
545
+ assert (bytes_per_pixel == 2 );
546
+
547
+ // if we fill the same byte value to all bytes, we can still use memset()
548
+ if (channel==0 ) {
549
+ memset (pixels[channel], 0 , stride * height * bytes_per_pixel);
550
+ }
551
+ else {
552
+ memset (pixels[channel], 0 , chroma_stride * chroma_height * bytes_per_pixel);
553
+ }
554
+ }
555
+ else {
556
+ assert (bytes_per_pixel == 2 );
557
+ uint16_t v = value;
558
+
559
+ if (channel==0 ) {
560
+ // copy value into first row
561
+ for (int x = 0 ; x < width; x++) {
562
+ *(uint16_t *) (&pixels[channel][2 * x]) = v;
563
+ }
564
+
565
+ // copy first row into remaining rows
566
+ for (int y = 1 ; y < height; y++) {
567
+ memcpy (pixels[channel] + y * stride * 2 , pixels[channel], chroma_width * 2 );
568
+ }
569
+ }
570
+ else {
571
+ // copy value into first row
572
+ for (int x = 0 ; x < chroma_width; x++) {
573
+ *(uint16_t *) (&pixels[channel][2 * x]) = v;
574
+ }
575
+
576
+ // copy first row into remaining rows
577
+ for (int y = 1 ; y < chroma_height; y++) {
578
+ memcpy (pixels[channel] + y * chroma_stride * 2 , pixels[channel], chroma_width * 2 );
579
+ }
580
+ }
581
+ }
582
+ }
583
+
584
+
530
585
void de265_image::fill_image (int y,int cb,int cr)
531
586
{
532
- if (y>= 0 ) {
533
- memset (pixels[ 0 ] , y, stride * height );
587
+ if (pixels[ 0 ] ) {
588
+ fill_plane ( 0 , y);
534
589
}
535
590
536
- if (cb>= 0 ) {
537
- memset (pixels[ 1 ] , cb, chroma_stride * chroma_height );
591
+ if (pixels[ 1 ] ) {
592
+ fill_plane ( 1 , cb);
538
593
}
539
594
540
- if (cr>= 0 ) {
541
- memset (pixels[ 2 ] , cr, chroma_stride * chroma_height );
595
+ if (pixels[ 2 ] ) {
596
+ fill_plane ( 2 , cr);
542
597
}
543
598
}
544
599
0 commit comments