@@ -25,8 +25,7 @@ VipsDecoder* try_vips_decoder(std::shared_ptr<Stream>& stream, bool cropBorders,
2525
2626VipsDecoder::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
4657void 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- }
0 commit comments