mirror of
https://github.com/RGBCube/serenity
synced 2025-07-14 05:27:35 +00:00
LibGfx+PDFViewer: Add RotationDirection::Flip and use it in PDFViewer
No behavior change.
This commit is contained in:
parent
5b223080ae
commit
29f5182e51
3 changed files with 22 additions and 10 deletions
|
@ -350,15 +350,13 @@ PDF::PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> PDFViewer::render_page(u32 page_inde
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page.rotate + m_rotations != 0) {
|
int rotation_count = ((page.rotate + m_rotations) / 90) % 4;
|
||||||
int rotation_count = ((page.rotate + m_rotations) / 90) % 4;
|
if (rotation_count == 1)
|
||||||
if (rotation_count == 3) {
|
bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::Clockwise));
|
||||||
bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::CounterClockwise));
|
else if (rotation_count == 2)
|
||||||
} else {
|
bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::Flip));
|
||||||
for (int i = 0; i < rotation_count; i++)
|
else if (rotation_count == 3)
|
||||||
bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::Clockwise));
|
bitmap = TRY(bitmap->rotated(Gfx::RotationDirection::CounterClockwise));
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,6 +277,19 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::clone() const
|
||||||
|
|
||||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const
|
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::rotated(Gfx::RotationDirection rotation_direction) const
|
||||||
{
|
{
|
||||||
|
if (rotation_direction == Gfx::RotationDirection::Flip) {
|
||||||
|
auto new_bitmap = TRY(Gfx::Bitmap::create(format(), { width(), height() }, scale()));
|
||||||
|
|
||||||
|
auto w = this->physical_width();
|
||||||
|
auto h = this->physical_height();
|
||||||
|
for (int i = 0; i < w; i++) {
|
||||||
|
for (int j = 0; j < h; j++)
|
||||||
|
new_bitmap->set_pixel(w - i - 1, h - j - 1, this->get_pixel(i, j));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
auto new_bitmap = TRY(Gfx::Bitmap::create(this->format(), { height(), width() }, scale()));
|
auto new_bitmap = TRY(Gfx::Bitmap::create(this->format(), { height(), width() }, scale()));
|
||||||
|
|
||||||
auto w = this->physical_width();
|
auto w = this->physical_width();
|
||||||
|
|
|
@ -86,7 +86,8 @@ struct BackingStore;
|
||||||
|
|
||||||
enum class RotationDirection {
|
enum class RotationDirection {
|
||||||
CounterClockwise,
|
CounterClockwise,
|
||||||
Clockwise
|
Flip,
|
||||||
|
Clockwise,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Bitmap : public RefCounted<Bitmap> {
|
class Bitmap : public RefCounted<Bitmap> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue