Support RGBA with auto-crop.
authorCarl Hetherington <cth@carlh.net>
Thu, 8 Aug 2024 22:42:34 +0000 (00:42 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 8 Aug 2024 22:42:34 +0000 (00:42 +0200)
src/lib/guess_crop.cc

index 3538f14dee4356ebec6bb52aa8e59b9862c7cb41..5eb7e66e8adc4c5caa2ea6c966125e9b2402864e 100644 (file)
@@ -42,8 +42,9 @@ guess_crop (shared_ptr<const Image> image, double threshold)
 
                switch (image->pixel_format()) {
                case AV_PIX_FMT_RGB24:
+               case AV_PIX_FMT_RGBA:
                {
-                       uint8_t const* data = image->data()[0] + start_x * 3 + start_y * image->stride()[0];
+                       uint8_t const* data = image->data()[0] + start_x * std::lround(image->bytes_per_pixel(0)) + start_y * image->stride()[0];
                        for (int p = 0; p < pixels; ++p) {
                                /* Averaging R, G and B */
                                brightest = std::max(brightest, static_cast<double>(data[0] + data[1] + data[2]) / (3 * 256));