コード例 #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));
    }
}
コード例 #2
0
ファイル: colorLevels.cpp プロジェクト: 2chen/colorlevels
ColorLevels::LAB
ColorLevels::LABColorToLAB(
    const Magick::ColorRGB &magickLAB)
{
	return (LAB{
	    magickLAB.red() * 100,
	    (magickLAB.green() * 256) - 100, 
	    (magickLAB.blue() * 256) - 100
	});
}
コード例 #3
0
ファイル: ColorImage.hpp プロジェクト: evangambit/Gif-Captain
Image<Color> imread(const std::string& file) {
    Magick::Image image(file);
    const size_t w = image.columns();
    const size_t h = image.rows();
    Magick::PixelPacket* pixels = image.getPixels(0, 0, w, h);
    Image<Color> rtn(h, w);
    for (size_t i = 0; i < w * h; ++i) {
        Magick::ColorRGB p = Magick::ColorRGB(pixels[i]);
        rtn(i) = Color(double(p.red()), double(p.green()), double(p.blue()));
    }
    return rtn;
}
コード例 #4
0
//Konverterer Magick::Image til QImage
QImage* image_wrapper::to_QImage(Magick::Image& image)
{
    qimg_ptr_helper = new QImage(image.columns(), image.rows(), QImage::Format_RGB32);
    const Magick::PixelPacket *pixels;
    Magick::ColorRGB rgb;
    for (int y = 0; y < qimg_ptr_helper->height(); y++) {
        pixels = image.getConstPixels(0, y, qimg_ptr_helper->width(), 1);
        for (int x = 0; x < qimg_ptr_helper->width(); x++) {
            rgb = (*(pixels + x));
            qimg_ptr_helper->setPixel(x, y, QColor((int) (255 * rgb.red())
                                             , (int) (255 * rgb.green())
                                             , (int) (255 * rgb.blue())).rgb());
        }
    }
    return qimg_ptr_helper;
}
コード例 #5
0
ファイル: magick_wrapper.cpp プロジェクト: Catuna/xyuv
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;
}
コード例 #6
0
//Konverterer et QImage til Magick::Image
void image_wrapper::to_Image(QImage& qimage)
{

    img_ptr_current = new Magick::Image(Magick::Geometry(qimage.width(), qimage.height()), Magick::ColorRGB(0.5, 0.2, 0.3));

    double scale = 1 / 256.0;
    img_ptr_current->modifyImage();
    Magick::PixelPacket *pixels;
    Magick::ColorRGB mgc;
    for (int y = 0; y < qimage.height(); y++) {
        pixels = img_ptr_current->setPixels(0, y, img_ptr_current->columns(), 1);
        for (int x = 0; x < qimage.width(); x++) {
            QColor pix = qimage.pixel(x, y);

            mgc.red(scale *pix.red());
            mgc.green(scale *pix.green());
            mgc.blue(scale *pix.blue());
            *pixels++ = mgc;
        }
        img_ptr_current->syncPixels();
    }
}