mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +00:00
LibGfx/TIFF: Modify the image according to the Orientation tag
Let's use the already existing logic (ExifOrientedBitmap) to modify the bitmap to honor the orientation tag.
This commit is contained in:
parent
367882ae23
commit
335097e446
3 changed files with 20 additions and 4 deletions
|
@ -546,6 +546,19 @@ TEST_CASE(test_tiff_deflate)
|
||||||
EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
|
EXPECT_EQ(frame.image->get_pixel(60, 75), Gfx::Color::NamedColor::Red);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(test_tiff_orientation)
|
||||||
|
{
|
||||||
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/orientation.tiff"sv)));
|
||||||
|
EXPECT(Gfx::TIFFImageDecoderPlugin::sniff(file->bytes()));
|
||||||
|
auto plugin_decoder = TRY_OR_FAIL(Gfx::TIFFImageDecoderPlugin::create(file->bytes()));
|
||||||
|
|
||||||
|
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 300, 400 }));
|
||||||
|
|
||||||
|
// Orientation is Rotate90Clockwise
|
||||||
|
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color::NamedColor::White);
|
||||||
|
EXPECT_EQ(frame.image->get_pixel(300 - 75, 60), Gfx::Color::NamedColor::Red);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(test_tiff_packed_bits)
|
TEST_CASE(test_tiff_packed_bits)
|
||||||
{
|
{
|
||||||
auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/packed_bits.tiff"sv)));
|
auto file = MUST(Core::MappedFile::map(TEST_INPUT("tiff/packed_bits.tiff"sv)));
|
||||||
|
|
BIN
Tests/LibGfx/test-inputs/tiff/orientation.tiff
Normal file
BIN
Tests/LibGfx/test-inputs/tiff/orientation.tiff
Normal file
Binary file not shown.
|
@ -13,6 +13,7 @@
|
||||||
#include <LibCompress/PackBitsDecoder.h>
|
#include <LibCompress/PackBitsDecoder.h>
|
||||||
#include <LibCompress/Zlib.h>
|
#include <LibCompress/Zlib.h>
|
||||||
#include <LibGfx/ImageFormats/CCITTDecoder.h>
|
#include <LibGfx/ImageFormats/CCITTDecoder.h>
|
||||||
|
#include <LibGfx/ImageFormats/ExifOrientedBitmap.h>
|
||||||
#include <LibGfx/ImageFormats/TIFFMetadata.h>
|
#include <LibGfx/ImageFormats/TIFFMetadata.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
@ -69,7 +70,7 @@ public:
|
||||||
|
|
||||||
IntSize size() const
|
IntSize size() const
|
||||||
{
|
{
|
||||||
return { *m_metadata.image_width(), *m_metadata.image_height() };
|
return ExifOrientedBitmap::oriented_size({ *m_metadata.image_width(), *m_metadata.image_height() }, *m_metadata.orientation());
|
||||||
}
|
}
|
||||||
|
|
||||||
Metadata const& metadata() const
|
Metadata const& metadata() const
|
||||||
|
@ -207,6 +208,8 @@ private:
|
||||||
auto const strips_offset = *m_metadata.strip_offsets();
|
auto const strips_offset = *m_metadata.strip_offsets();
|
||||||
auto const strip_byte_counts = *m_metadata.strip_byte_counts();
|
auto const strip_byte_counts = *m_metadata.strip_byte_counts();
|
||||||
|
|
||||||
|
auto oriented_bitmap = TRY(ExifOrientedBitmap::create(BitmapFormat::BGRA8888, { *metadata().image_width(), *metadata().image_height() }, *metadata().orientation()));
|
||||||
|
|
||||||
for (u32 strip_index = 0; strip_index < strips_offset.size(); ++strip_index) {
|
for (u32 strip_index = 0; strip_index < strips_offset.size(); ++strip_index) {
|
||||||
TRY(m_stream->seek(strips_offset[strip_index]));
|
TRY(m_stream->seek(strips_offset[strip_index]));
|
||||||
|
|
||||||
|
@ -231,20 +234,20 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
last_color = color;
|
last_color = color;
|
||||||
m_bitmap->set_pixel(column, scanline, color);
|
oriented_bitmap.set_pixel(column, scanline, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
decoded_stream->align_to_byte_boundary();
|
decoded_stream->align_to_byte_boundary();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_bitmap = oriented_bitmap.bitmap();
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<void> decode_frame_impl()
|
ErrorOr<void> decode_frame_impl()
|
||||||
{
|
{
|
||||||
m_bitmap = TRY(Bitmap::create(BitmapFormat::BGRA8888, size()));
|
|
||||||
|
|
||||||
switch (*m_metadata.compression()) {
|
switch (*m_metadata.compression()) {
|
||||||
case Compression::NoCompression: {
|
case Compression::NoCompression: {
|
||||||
auto identity = [&](u32 num_bytes) {
|
auto identity = [&](u32 num_bytes) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue