Beispiel #1
0
static void compare_colors(const Magick::ColorRGB & expected, const Magick::ColorRGB & observed, bool expected_has_alpha, bool observed_has_alpha ) {
    ASSERT_NEAR(expected.red(), observed.red(), 1.1f/(0x1<<8));
    ASSERT_NEAR(expected.green(), observed.green(), 1.1f/(0x1<<8));
    ASSERT_NEAR(expected.blue(), observed.blue(), 1.1f/(0x1<<8));
    if (expected_has_alpha) {
        ASSERT_NEAR(expected.alpha(), observed.alpha(), 1.1f / (0x1 << 8));
    }
    else if (observed_has_alpha) {
        ASSERT_NEAR(1.0f, observed.alpha(), 1.1f /(0x1 << 8));
    }
}
Beispiel #2
0
yuv_image magick_wrapper::xyuv_to_yuv_image_444(const xyuv::conversion_matrix &conversion_matrix) const {
    // Analyse the conversion matrix to discover if any plane is not present.
    bool has[3] = {false, false, false};
    for (uint32_t i = 0; i < 9; i++) {
        has[i / 3] = has[i / 3] || (conversion_matrix.rgb_to_yuv[i] != static_cast<pixel_quantum>(0));
    }
    bool has_a = image.matte();


    yuv_image image_out = create_yuv_image_444(
            static_cast<uint32_t>(image.columns()),
            static_cast<uint32_t>(image.rows()),
            has[channel::Y],
            has[channel::U],
            has[channel::V],
            has_a);


    // Create pixels with default values.
    // Note that this hides the lack of planes.
    rgb_color rgb;
    yuv_color yuv;

    const Magick::PixelPacket *pixels = image.getConstPixels(0, 0, image.columns(), image.rows());

    for (uint32_t y = 0; y < image_out.image_h; y++) {
        for (uint32_t x = 0; x < image_out.image_w; x++) {
            // Fetch color from ImageMagick
            const Magick::ColorRGB magick_rgb = Magick::Color(pixels[y * image.columns() + x]);
            rgb.r = static_cast<float>(magick_rgb.red());
            rgb.g = static_cast<float>(magick_rgb.green());
            rgb.b = static_cast<float>(magick_rgb.blue());
            // Imagemagick stores alpha as 0.0 = opaque
            rgb.a = static_cast<float>(1.0-magick_rgb.alpha());

            // Convert to yuv.
            to_yuv(&yuv, rgb, conversion_matrix);

            // Assign pixel
            set_yuv_color(image_out, yuv, x, y);
        }
    }
    // No syncing needed.

    return image_out;
}