Skip to content

Commit c7855dd

Browse files
committed
replace fill_image() with an implementation that supports HDR images and use this also for image initialization
1 parent 89c8411 commit c7855dd

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

libde265/image.cc

+62-7
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ static inline void *ALLOC_ALIGNED(size_t alignment, size_t size) {
5555
if (posix_memalign(&mem, alignment, size) != 0) {
5656
return NULL;
5757
}
58-
memset(mem, 0, size);
5958
return mem;
6059
};
6160
#define FREE_ALIGNED(mem) free((mem))
@@ -155,6 +154,8 @@ static int de265_image_get_buffer(de265_decoder_context* ctx,
155154
img->set_image_plane(1, p[1], chroma_stride, NULL);
156155
img->set_image_plane(2, p[2], chroma_stride, NULL);
157156

157+
img->fill_image(0,0,0);
158+
158159
return 1;
159160
}
160161

@@ -527,18 +528,72 @@ void de265_image::release()
527528
}
528529

529530

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+
530585
void de265_image::fill_image(int y,int cb,int cr)
531586
{
532-
if (y>=0) {
533-
memset(pixels[0], y, stride * height);
587+
if (pixels[0]) {
588+
fill_plane(0, y);
534589
}
535590

536-
if (cb>=0) {
537-
memset(pixels[1], cb, chroma_stride * chroma_height);
591+
if (pixels[1]) {
592+
fill_plane(1, cb);
538593
}
539594

540-
if (cr>=0) {
541-
memset(pixels[2], cr, chroma_stride * chroma_height);
595+
if (pixels[2]) {
596+
fill_plane(2, cr);
542597
}
543598
}
544599

libde265/image.h

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ struct de265_image {
244244
}
245245

246246
void fill_image(int y,int u,int v);
247+
void fill_plane(int channel, int value);
247248
de265_error copy_image(const de265_image* src);
248249
void copy_lines_from(const de265_image* src, int first, int end);
249250
void exchange_pixel_data_with(de265_image&);

0 commit comments

Comments
 (0)