Skip to content

Commit a646d50

Browse files
committed
Remove ImageInfo struct
Only `bounds` were being used, so I only keeped that.
1 parent abf7b11 commit a646d50

3 files changed

Lines changed: 19 additions & 42 deletions

File tree

library/src/main/cpp/image-decoder/decoder_vips.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ VipsDecoder* try_vips_decoder(std::shared_ptr<Stream>& stream, bool cropBorders,
2525

2626
VipsDecoder::VipsDecoder(std::shared_ptr<Stream>&& stream, bool cropBorders,
2727
cmsHPROFILE targetProfile)
28-
: stream(std::move(stream)), cropBorders(cropBorders),
29-
targetProfile(targetProfile) {
28+
: stream(std::move(stream)), targetProfile(targetProfile) {
3029

3130
if (VIPS_INIT("VipsDecoder")) {
3231
LOGE("Failed to initialize libvips.");
@@ -40,7 +39,19 @@ VipsDecoder::VipsDecoder(std::shared_ptr<Stream>&& stream, bool cropBorders,
4039
// random.
4140
VImage::option()->set("access", VIPS_ACCESS_RANDOM));
4241

43-
this->info = parseInfo();
42+
this->bounds = {.x = 0,
43+
.y = 0,
44+
.width = (uint32_t)image.width(),
45+
.height = (uint32_t)image.height()};
46+
47+
// Crop the image if `cropBorders` is enabled
48+
if (cropBorders) {
49+
// convert image to gray
50+
VImage gray_image =
51+
image.colourspace(VIPS_INTERPRETATION_B_W).cast(VIPS_FORMAT_UCHAR);
52+
this->bounds =
53+
findBorders((uint8_t*)gray_image.data(), image.width(), image.height());
54+
}
4455
}
4556

4657
void VipsDecoder::decode(uint8_t* outPixels, const Rect outRect,
@@ -74,24 +85,3 @@ void VipsDecoder::decode(uint8_t* outPixels, const Rect outRect,
7485
// ensure we didn't write past the end of the buffer
7586
assert(outline <= outPixelsEnd);
7687
}
77-
78-
ImageInfo VipsDecoder::parseInfo() {
79-
uint32_t imageWidth = this->image.width();
80-
uint32_t imageHeight = this->image.height();
81-
82-
Rect bounds = {.x = 0, .y = 0, .width = imageWidth, .height = imageHeight};
83-
84-
// Crop the image if `cropBorders` is enabled
85-
if (this->cropBorders) {
86-
// convert image to gray
87-
VImage gray_image = image.colourspace(VIPS_INTERPRETATION_B_W);
88-
bounds = findBorders((uint8_t*)gray_image.data(), imageWidth, imageHeight);
89-
}
90-
91-
return ImageInfo{
92-
.imageWidth = imageWidth,
93-
.imageHeight = imageHeight,
94-
.isAnimated = false,
95-
.bounds = bounds,
96-
};
97-
}

library/src/main/cpp/image-decoder/decoder_vips.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@
1313

1414
#include <vips/vips8>
1515

16-
struct ImageInfo {
17-
uint32_t imageWidth;
18-
uint32_t imageHeight;
19-
bool isAnimated;
20-
// Bound of the image, excluding the borders if `cropBorders` is true.
21-
Rect bounds;
22-
};
23-
2416
class VipsDecoder {
2517
public:
2618
/**
@@ -53,8 +45,9 @@ class VipsDecoder {
5345
*/
5446
void decode(uint8_t* outPixels, Rect outRect, uint32_t sampleSize);
5547

56-
// Metadata about the image being decoded.
57-
ImageInfo info;
48+
// The bounds of the image. If `cropBorders` is true, the bounds exclude
49+
// borders around the image.
50+
Rect bounds;
5851

5952
private:
6053
// The input stream for reading image data.
@@ -64,15 +57,9 @@ class VipsDecoder {
6457
// TODO: currently unused, keeping until color management is implemented.
6558
cmsHPROFILE targetProfile;
6659

67-
// Indicates whether to crop borders around the image.
68-
bool cropBorders;
69-
7060
// The VImage object. Have a reference to `stream`, so it must be declared
7161
// after it, to ensure it is destroyed first.
7262
vips::VImage image;
73-
74-
// Parse the image metadata.
75-
ImageInfo parseInfo();
7663
};
7764

7865
VipsDecoder* try_vips_decoder(std::shared_ptr<Stream>& stream, bool cropBorders,

library/src/main/cpp/image-decoder/java_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Java_dev_mihon_image_decoder_ImageDecoder_nativeNewInstance(
5757
return nullptr;
5858
}
5959

60-
Rect bounds = decoder->info.bounds;
60+
Rect bounds = decoder->bounds;
6161
return create_image_decoder(env, (jlong)decoder, bounds.width, bounds.height);
6262
}
6363

@@ -71,7 +71,7 @@ Java_dev_mihon_image_decoder_ImageDecoder_nativeDecode(JNIEnv* env, jobject,
7171

7272
// Bounds of the image when crop borders is enabled, otherwise it matches the
7373
// entire image.
74-
Rect bounds = decoder->info.bounds;
74+
Rect bounds = decoder->bounds;
7575

7676
// Translated requested bounds to the original image.
7777
Rect inRect = {x + bounds.x, y + bounds.y, (uint32_t)width, (uint32_t)height};

0 commit comments

Comments
 (0)