X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fimage.cc;h=6835d0c26d967557df34fadfa06ba1e9680da53f;hb=71d56fbe3ba5974505469d2c8b7efcdef4eb8adc;hp=134172038fc04892615cd02af5593de2b4b626e8;hpb=3a626081718fe09edafb951ac9a69e44145bf551;p=dcpomatic.git diff --git a/src/lib/image.cc b/src/lib/image.cc index 134172038..6835d0c26 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -360,6 +360,7 @@ Image::make_black () case AV_PIX_FMT_RGB555LE: case AV_PIX_FMT_RGB48LE: case AV_PIX_FMT_RGB48BE: + case AV_PIX_FMT_XYZ12LE: memset (data()[0], 0, sample_size(0).height * stride()[0]); break; @@ -463,10 +464,35 @@ Image::alpha_blend (shared_ptr other, Position position) uint8_t* op = other->data()[0] + oy * other->stride()[0]; for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) { float const alpha = float (op[3]) / 255; - /* Blend high bytes */ - tp[1] = op[0] * alpha + tp[1] * (1 - alpha); + /* Blend high bytes; the RGBA in op appears to be BGRA */ + tp[1] = op[2] * alpha + tp[1] * (1 - alpha); tp[3] = op[1] * alpha + tp[3] * (1 - alpha); - tp[5] = op[2] * alpha + tp[5] * (1 - alpha); + tp[5] = op[0] * alpha + tp[5] * (1 - alpha); + + tp += this_bpp; + op += other_bpp; + } + } + break; + } + case AV_PIX_FMT_XYZ12LE: + { + int const this_bpp = 6; + for (int ty = start_ty, oy = start_oy; ty < size().height && oy < other->size().height; ++ty, ++oy) { + uint8_t* tp = data()[0] + ty * stride()[0] + start_tx * this_bpp; + uint8_t* op = other->data()[0] + oy * other->stride()[0]; + for (int tx = start_tx, ox = start_ox; tx < size().width && ox < other->size().width; ++tx, ++ox) { + float const alpha = float (op[3]) / 255; + + /* Convert sRGB to XYZ; op is BGRA */ + int const x = 0.4124564 + op[2] + 0.3575761 * op[1] + 0.1804375 * op[0]; + int const y = 0.2126729 + op[2] + 0.7151522 * op[1] + 0.0721750 * op[0]; + int const z = 0.0193339 + op[2] + 0.1191920 * op[1] + 0.9503041 * op[0]; + + /* Blend high bytes */ + tp[1] = min (x, 255) * alpha + tp[1] * (1 - alpha); + tp[3] = min (y, 255) * alpha + tp[3] * (1 - alpha); + tp[5] = min (z, 255) * alpha + tp[5] * (1 - alpha); tp += this_bpp; op += other_bpp; @@ -830,6 +856,7 @@ Image::fade (float f) case AV_PIX_FMT_YUVA422P10LE: case AV_PIX_FMT_YUVA444P10LE: case AV_PIX_FMT_RGB48LE: + case AV_PIX_FMT_XYZ12LE: /* 16-bit little-endian */ for (int c = 0; c < 3; ++c) { int const stride_pixels = stride()[c] / 2;