Skip to content

Commit 103d6a0

Browse files
LucasCholletnico
authored andcommitted
LibGfx: Add BilevelImage::as_subbitmap()
This allows a simple conversion to the `BilevelSubImage` type.
1 parent 41a227f commit 103d6a0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Userland/Libraries/LibGfx/ImageFormats/BilevelImage.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ BilevelSubImage BilevelImage::subbitmap(Gfx::IntRect const& rect) const
132132
return BilevelSubImage { *this, rect };
133133
}
134134

135+
BilevelSubImage BilevelImage::as_subbitmap() const
136+
{
137+
return subbitmap(IntRect(0, 0, m_width, m_height));
138+
}
139+
135140
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> BilevelImage::to_gfx_bitmap() const
136141
{
137142
auto bitmap = TRY(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRx8888, { m_width, m_height }));

Userland/Libraries/LibGfx/ImageFormats/BilevelImage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class BilevelImage : public RefCounted<BilevelImage> {
7474
void composite_onto(BilevelImage& out, IntPoint position, CompositionType) const;
7575

7676
BilevelSubImage subbitmap(Gfx::IntRect const& rect) const;
77+
BilevelSubImage as_subbitmap() const;
7778

7879
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> to_gfx_bitmap() const;
7980
ErrorOr<ByteBuffer> to_byte_buffer() const;

Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,7 +1956,7 @@ static ErrorOr<NonnullRefPtr<BilevelImage>> text_region_decoding_procedure(TextR
19561956
refinement_inputs.is_typical_prediction_used = false;
19571957
refinement_inputs.adaptive_template_pixels = inputs.refinement_adaptive_template_pixels;
19581958
auto result = TRY(generic_refinement_region_decoding_procedure(refinement_inputs, *decoder, refinement_contexts.value()));
1959-
refinement_result = result->subbitmap(IntRect(0, 0, result->width(), result->height()));
1959+
refinement_result = result->as_subbitmap();
19601960
return &refinement_result.value();
19611961
};
19621962

@@ -2380,7 +2380,7 @@ static ErrorOr<Vector<BilevelSubImage>> symbol_dictionary_decoding_procedure(Sym
23802380
// FIXME: Doing this eagerly is pretty wasteful. Decode on demand instead?
23812381
if (!inputs.uses_huffman_encoding || inputs.uses_refinement_or_aggregate_coding) {
23822382
auto bitmap = TRY(read_symbol_bitmap(symbol_width, height_class_height));
2383-
new_symbols.append(bitmap->subbitmap(IntRect(0, 0, bitmap->width(), bitmap->height())));
2383+
new_symbols.append(bitmap->as_subbitmap());
23842384
}
23852385

23862386
// "iii) If SDHUFF is 1 and SDREFAGG is 0, then set:
@@ -3764,7 +3764,7 @@ static ErrorOr<void> decode_immediate_generic_refinement_region(JBIG2LoadingCont
37643764
inputs.region_width = information_field.width;
37653765
inputs.region_height = information_field.height;
37663766
inputs.gr_template = arithmetic_coding_template;
3767-
auto subbitmap = reference_bitmap->subbitmap(IntRect(0, 0, reference_bitmap->width(), reference_bitmap->height()));
3767+
auto subbitmap = reference_bitmap->as_subbitmap();
37683768
inputs.reference_bitmap = &subbitmap;
37693769
inputs.reference_x_offset = 0;
37703770
inputs.reference_y_offset = 0;

0 commit comments

Comments
 (0)