PNG support for PixelBuffer taken from Qt also if Qt bindings are off

This commit is contained in:
Matthias Koefferlein 2023-02-19 20:25:21 +01:00
parent 79868c40cd
commit 817bb396f6
2 changed files with 12 additions and 21 deletions

View File

@ -62,7 +62,7 @@ static tl::PixelBuffer read_pixel_buffer (const std::string &file)
#if defined(HAVE_PNG)
tl::InputStream stream (file);
return tl::PixelBuffer::read_png (stream);
#elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS)
#elif defined(HAVE_QT)
// QImage is fallback
QImage img;
img.load (tl::to_qstring (file), "PNG");
@ -80,7 +80,7 @@ static tl::PixelBuffer pixel_buffer_from_png (const std::vector<char> &data)
tl::InputMemoryStream data_stream (data.begin ().operator-> (), data.size ());
tl::InputStream stream (data_stream);
return tl::PixelBuffer::read_png (stream);
#elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS)
#elif defined(HAVE_QT)
// QImage is fallback
tl_assert (data.size () < std::numeric_limits<int>::max ());
QImage img = QImage::fromData ((const uchar *) data.begin ().operator-> (), int (data.size ()));
@ -96,7 +96,7 @@ static void write_pixel_buffer (const tl::PixelBuffer *pb, const std::string &fi
#if defined(HAVE_PNG)
tl::OutputStream stream (file);
pb->write_png (stream);
#elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS)
#elif defined(HAVE_QT)
// QImage is fallback
QImage img = pb->to_image ();
img.save (tl::to_qstring (file), "PNG");
@ -115,7 +115,7 @@ static std::vector<char> pixel_buffer_to_png (const tl::PixelBuffer *pb)
pb->write_png (stream);
}
return std::vector<char> (data_stream.data (), data_stream.data () + data_stream.size ());
#elif defined(HAVE_QT) && defined(HAVE_QTBINDINGS)
#elif defined(HAVE_QT)
// QImage is fallback
QImage img = pb->to_image ();
QBuffer data;

View File

@ -139,25 +139,16 @@ class LAYPixelBuffer_TestClass < TestBase
assert_equal(compare(pb, pb_copy), true)
end
png = nil
begin
png = pb.to_png_data
rescue => ex
# No PNG support
end
png = pb.to_png_data
if png
assert_equal(png.size > 20 && png.size < 200, true) # some range because implementations may differ
pb_copy = RBA::PixelBuffer.from_png_data(png)
assert_equal(compare(pb, pb_copy), true)
assert_equal(png.size > 20 && png.size < 200, true) # some range because implementations may differ
pb_copy = RBA::PixelBuffer.from_png_data(png)
assert_equal(compare(pb, pb_copy), true)
tmp = File::join($ut_testtmp, "tmp.png")
pb.write_png(tmp)
pb_copy = RBA::PixelBuffer.read_png(tmp)
assert_equal(compare(pb, pb_copy), true)
end
tmp = File::join($ut_testtmp, "tmp.png")
pb.write_png(tmp)
pb_copy = RBA::PixelBuffer.read_png(tmp)
assert_equal(compare(pb, pb_copy), true)
end