Skip to content

Commit

Permalink
remove read_png24
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpoelen committed Feb 26, 2024
1 parent 5c15228 commit e43677f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 96 deletions.
53 changes: 0 additions & 53 deletions src/utils/png.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Transport*>(png_ptr->io_ptr)->recv_boom(data, length);
static_cast<Transport*>(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,
Expand Down
4 changes: 0 additions & 4 deletions src/utils/png.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions targets.jam
Original file line number Diff line number Diff line change
Expand Up @@ -4839,12 +4839,14 @@ test-run tests/utils/test_scaled_image24 :
<library>src/utils/bitmap.o
<library>src/utils/bitmap_data_allocator.o
<library>src/utils/bitmap_from_file.o
<library>src/utils/fileutils.o
<library>src/utils/png.o
<library>src/utils/rle.o
<library>src/utils/scaled_image24.o
<library>src/utils/stacktrace.o
<library>src/utils/strutils.o
<library>tests/includes/test_only/test_framework/check_img.o
<library>tests/includes/test_only/test_framework/working_directory.o
<library>tests/includes/test_only/transport/test_transport.o
$(BOOST_STACKTRACE_LINKFLAGS)
;
Expand Down
27 changes: 0 additions & 27 deletions tests/capture/test_capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions tests/utils/test_scaled_image24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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());
Expand All @@ -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");
}

0 comments on commit e43677f

Please sign in to comment.