From e43677f45eb9eac3657d885ab159000484c00719 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 26 Feb 2024 15:47:41 +0100 Subject: [PATCH] remove read_png24 --- src/utils/png.cpp | 53 ----------------------------- src/utils/png.hpp | 4 --- targets.jam | 2 ++ tests/capture/test_capture.cpp | 27 --------------- tests/utils/test_scaled_image24.cpp | 16 +++------ 5 files changed, 6 insertions(+), 96 deletions(-) diff --git a/src/utils/png.cpp b/src/utils/png.cpp index da5c68ba4d..a31743315e 100644 --- a/src/utils/png.cpp +++ b/src/utils/png.cpp @@ -166,26 +166,6 @@ namespace } } } - - void read_png24_impl( - PngReadStruct & png, uint8_t * data, - const size_t width, const size_t height, const size_t rowsize) - { - png_read_info(png.ppng, png.pinfo); - - assert(height == png_get_image_height(png.ppng, png.pinfo)); - assert(width == png_get_image_width(png.ppng, png.pinfo)); - assert(width <= rowsize); - - (void)width; - - for (size_t k = 0; k < height; ++k) { - png_read_row(png.ppng, data, nullptr); - data += rowsize; - } - - png_read_end(png.ppng, png.pinfo); - } } // namespace struct NoExceptTransport @@ -319,39 +299,6 @@ void dump_png24(const char * filename, ImageView const & image_view, bool bgr) } -void read_png24(const char * filename, WritableImageView const & mutable_image_view) -{ - if (File f{filename, "r"}) { - read_png24(f.get(), mutable_image_view); - } -} - -void read_png24(std::FILE * file, WritableImageView const & mutable_image_view) -{ - PngReadStruct png; - png_init_io(png.ppng, file); - read_png24_impl(png, mutable_image_view.mutable_data(), - mutable_image_view.width(), mutable_image_view.height(), - mutable_image_view.line_size()); -} - -void read_png24(Transport & trans, WritableImageView const & mutable_image_view) -{ - assert(BytesPerPixel{3} == mutable_image_view.bytes_per_pixel()); - - auto png_read_data_fn = [](png_structp png_ptr, png_bytep data, png_size_t length) { - // TODO catch exception ? - // static_cast(png_ptr->io_ptr)->recv_boom(data, length); - static_cast(png_get_io_ptr(png_ptr))->recv_boom(data, length); - }; - - PngReadStruct png; - png_set_read_fn(png.ppng, &trans, png_read_data_fn); - read_png24_impl(png, mutable_image_view.mutable_data(), - mutable_image_view.width(), mutable_image_view.height(), - mutable_image_view.line_size()); -} - // TODO void read_png24_by_line(read_fn:size_t(writable_bytes_view), f:void(bytes_view)) void set_rows_from_image_chunk( Transport & trans, diff --git a/src/utils/png.hpp b/src/utils/png.hpp index bf0231cde3..a5b5d5c530 100644 --- a/src/utils/png.hpp +++ b/src/utils/png.hpp @@ -64,10 +64,6 @@ void dump_png24(std::FILE * file, ImageView const & image_view, bool bgr); void dump_png24(Transport & trans, ImageView const & image_view, bool bgr); void dump_png24(const char * filename, ImageView const & image_view, bool bgr); -void read_png24(std::FILE * file, WritableImageView const & mutable_image_view); -void read_png24(Transport & trans, WritableImageView const & mutable_image_view); -void read_png24(const char * filename, WritableImageView const & mutable_image_view); - void set_rows_from_image_chunk( Transport & trans, WrmChunkType chunk_type, diff --git a/targets.jam b/targets.jam index ec8dffb54f..04ad1d5500 100644 --- a/targets.jam +++ b/targets.jam @@ -4839,12 +4839,14 @@ test-run tests/utils/test_scaled_image24 : src/utils/bitmap.o src/utils/bitmap_data_allocator.o src/utils/bitmap_from_file.o + src/utils/fileutils.o src/utils/png.o src/utils/rle.o src/utils/scaled_image24.o src/utils/stacktrace.o src/utils/strutils.o tests/includes/test_only/test_framework/check_img.o + tests/includes/test_only/test_framework/working_directory.o tests/includes/test_only/transport/test_transport.o $(BOOST_STACKTRACE_LINKFLAGS) ; diff --git a/tests/capture/test_capture.cpp b/tests/capture/test_capture.cpp index 93dd899e81..ace6dbd436 100644 --- a/tests/capture/test_capture.cpp +++ b/tests/capture/test_capture.cpp @@ -40,7 +40,6 @@ REDEMPTION_DIAGNOSTIC_POP() #include "transport/file_transport.hpp" #include "utils/drawable.hpp" #include "utils/fileutils.hpp" -#include "utils/png.hpp" #include "utils/stream.hpp" #include "utils/strutils.hpp" #include "utils/bitmap_from_file.hpp" @@ -2068,32 +2067,6 @@ RED_AUTO_TEST_CASE(TestImagePNGSmallChunks) // drawable.dump_png24(png_trans, true); true); } -RED_AUTO_TEST_CASE(TestReadPNGFromTransport) -{ - force_paris_timezone(); - auto source_png = - "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" //.PNG.... - "\x00\x00\x00\x0d\x49\x48\x44\x52" //....IHDR - "\x00\x00\x00\x14\x00\x00\x00\x0a\x08\x02\x00\x00\x00" //............. - "\x3b\x37\xe9\xb1" //;7.. - "\x00\x00\x00\x32\x49\x44\x41\x54" //...2IDAT - "\x28\x91\x63\xfc\xcf\x80\x17\xfc\xff\xcf\xc0\xc8\x88\x4b\x92\x09" //(.c..........K.. - "\xbf\x5e\xfc\x60\x88\x6a\x66\x41\xe3\x33\x32\xa0\x84\xe0\x7f\x54" //.^.`.jfA.32....T - "\x91\xff\x0c\x28\x81\x37\x70\xce\x66\x1c\xb0\x78\x06\x00\x69\xdc" //...(.7p.f..x..i. - "\x0a\x12" //.. - "\x86\x4a\x0c\x44" //.J.D - "\x00\x00\x00\x00\x49\x45\x4e\x44" //....IEND - "\xae\x42\x60\x82" //.B`. - ""_av - ; - - RDPDrawable d(20, 10); - GeneratorTransport in_png_trans(source_png); - read_png24(in_png_trans, gdi::get_writable_image_view(d)); - BufTransport png_trans; - dump_png24(png_trans, d, true); -} - const char source_wrm_png[] = /* 0000 */ "\xEE\x03\x1C\x00\x00\x00\x01\x00" // 03EE: META 0010: chunk_len=16 0001: 1 order "\x03\x00\x14\x00\x0A\x00\x18\x00" // WRM version 3, width = 20, height=10, bpp=24 PAD: 2 bytes diff --git a/tests/utils/test_scaled_image24.cpp b/tests/utils/test_scaled_image24.cpp index cf1126798c..690103af39 100644 --- a/tests/utils/test_scaled_image24.cpp +++ b/tests/utils/test_scaled_image24.cpp @@ -22,9 +22,9 @@ #include "utils/scaled_image24.hpp" #include "utils/bitmap_from_file.hpp" -#include "utils/png.hpp" #include "test_only/test_framework/redemption_unit_tests.hpp" +#include "test_only/test_framework/working_directory.hpp" #include "test_only/test_framework/check_img.hpp" #include "test_only/transport/test_transport.hpp" @@ -106,7 +106,7 @@ RED_AUTO_TEST_CASE(TestSimpleShrink) RED_CHECK(make_array_view(expected) == make_array_view(scaled_buffer)); } -RED_AUTO_TEST_CASE(TestScaleImage) +RED_AUTO_TEST_CASE_WF(TestScaleImage, wf) { RED_CHECK(!ScaledPng24(0, 0).is_scaled()); RED_CHECK(!ScaledPng24(10, 0).is_scaled()); @@ -120,20 +120,12 @@ RED_AUTO_TEST_CASE(TestScaleImage) // Zoom 50 const uint16_t width = 400; const uint16_t height = 300; - const unsigned line_size = ((width + 3) & 0xffc) * 3; - BufTransport trans; ScaledPng24 scaled_png(width, height); RED_CHECK(scaled_png.is_scaled()); - scaled_png.dump_png24(trans, bmp, false); + scaled_png.dump_png24(wf.c_str(), bmp, true); - uint8_t data[line_size * height]; - WritableImageView img{ - data, width, height, line_size, - BitsPerPixel::BitsPP24, ImageView::Storage::TopToBottom - }; - - read_png24(trans, img); + auto img = bitmap_from_file(wf.c_str(), BGRColor()); RED_CHECK_IMG(img, FIXTURES_PATH "/scaled_image24/win2008capture10_50_percent.png"); }