22 #include <libgtkcrnmm_config.h>
30 static Glib::RefPtr<Gdk::Pixbuf> pixbufFromCRNImageRGB(
const ImageRGB &img)
32 Glib::RefPtr<Gdk::Pixbuf> pb(Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB,
false, 8,
int(img.
GetWidth()),
int(img.
GetHeight())));
35 guint8 *pix = pb->get_pixels();
36 for (
size_t y = 0; y < img.
GetHeight(); y++)
39 for (
size_t x = 0; x < img.
GetWidth(); x++)
41 pix[pto++] = img.
At(offset).r;
42 pix[pto++] = img.
At(offset).g;
43 pix[pto++] = img.
At(offset++).b;
45 offsetpb += pb->get_rowstride();
50 static Glib::RefPtr<Gdk::Pixbuf> pixbufFromCRNImageGray(
const ImageGray &img)
52 Glib::RefPtr<Gdk::Pixbuf> pb(Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB,
false, 8,
int(img.
GetWidth()),
int(img.
GetHeight())));
55 guint8 *pix = pb->get_pixels();
56 for (
size_t y = 0; y < img.
GetHeight(); y++)
59 for (
size_t x = 0; x < img.
GetWidth(); x++)
61 uint8_t v = img.
At(offset++);
66 offsetpb += pb->get_rowstride();
71 static Glib::RefPtr<Gdk::Pixbuf> pixbufFromCRNImageBW(
const ImageBW &img)
73 Glib::RefPtr<Gdk::Pixbuf> pb(Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB,
false, 8,
int(img.
GetWidth()),
int(img.
GetHeight())));
76 guint8 *pix = pb->get_pixels();
77 for (
size_t y = 0; y < img.
GetHeight(); y++)
80 for (
size_t x = 0; x < img.
GetWidth(); x++)
82 uint8_t v = img.
At(offset++) ? 255 : 0;
87 offsetpb += pb->get_rowstride();
104 return pixbufFromCRNImageRGB(dynamic_cast<const ImageRGB&>(img));
109 return pixbufFromCRNImageGray(dynamic_cast<const ImageGray&>(img));
114 return pixbufFromCRNImageBW(dynamic_cast<const ImageBW&>(img));
130 if (ext ==
"png" || ext ==
"jpeg" || ext ==
"jpg")
133 return Gdk::Pixbuf::create_from_file(p.
CStr());
135 return Gdk::Pixbuf::create_from_file(p.
CStr());
153 guint8 *pix = pb->get_pixels();
154 auto imgrgb =
ImageRGB(pb->get_width(), pb->get_height());
157 int alpha = pb->get_has_alpha() ? 1 : 0;
158 for (
size_t y = 0; y < imgrgb.GetHeight(); y++)
161 for (
size_t x = 0; x < imgrgb.GetWidth(); x++)
164 imgrgb.At(offset).r = pix[tpo++];
165 imgrgb.At(offset).g = pix[tpo++];
166 imgrgb.At(offset++).b = pix[tpo++];
168 offsetpb += pb->get_rowstride();
173 #ifdef CRN_USING_GTKMM3
183 col.set_rgba(p.
r / 255.0, p.
g / 255.0, p.
b / 255.0);
195 return crn::pixel::RGB8(uint8_t(color.get_red() * 255), uint8_t(color.get_green() * 255), uint8_t(color.get_blue() * 255));
208 col.set_rgb_p(p.
r / 255.0, p.
g / 255.0, p.
b / 255.0);
220 return crn::pixel::RGB8(uint8_t(color.get_red_p() * 255), uint8_t(color.get_green_p() * 255), uint8_t(color.get_blue_p() * 255));
Glib::RefPtr< Gdk::Pixbuf > PixbufFromCRNImage(const crn::ImageBase &img)
Creates a Gdk::Pixbuf from a crn::Image.
Abstract class for images.
StringUTF8 & ToLower()
Converts the string to lowercase.
Glib::RefPtr< Gdk::Pixbuf > PixbufFromFile(const crn::Path &p)
Creates a Gdk::Pixbuf from a file.
crn::pixel::RGB8 CRNPixelRGBFromGdkColor(const Gdk::Color &color)
Creates a crn::PixelRGB from a Gdk::Color.
std::vector< pixel_type >::reference At(size_t x, size_t y) noexcept
Returns a reference to a pixel.
size_t GetHeight() const noexcept
Image< pixel::RGB< uint8_t >> ImageRGB
Color image class.
const char * CStr() const noexcept
Conversion to UTF8 cstring.
A convenience class for file paths.
crn::ImageRGB CRNImageFromPixbuf(const Glib::RefPtr< Gdk::Pixbuf > &pb)
Creates a crn::Image from a Gdk::Pixbuf.
UImage NewImageFromFile(const Path &fname)
Loads an image from a file.
size_t GetWidth() const noexcept
A character string class.
Gdk::Color ColorFromCRNPixel(const crn::pixel::RGB8 &p)
Creates a Gdk::Color from a crn::Pixel.
Path GetExtension() const
Returns the extension.
Invalid argument error (e.g.: nullptr pointer)