From 4c494156cc416ac46dde1bfc7e694802bad30c3e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Jul 2013 23:43:22 +0100 Subject: Fix cropping of YUV images by amounts that are finer than the U/V resolution (and add a test for that). --- src/lib/image.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/image.cc b/src/lib/image.cc index 0eabbe84d..ac30f4ff0 100644 --- a/src/lib/image.cc +++ b/src/lib/image.cc @@ -214,7 +214,11 @@ Image::crop (Crop crop, bool aligned) const for (int c = 0; c < components(); ++c) { int const crop_left_in_bytes = bytes_per_pixel(c) * crop.left; - int const cropped_width_in_bytes = bytes_per_pixel(c) * cropped_size.width; + /* bytes_per_pixel() could be a fraction; in this case the stride will be rounded + up, and we need to make sure that we copy over the width (up to the stride) + rather than short of the width; hence the ceil() here. + */ + int const cropped_width_in_bytes = ceil (bytes_per_pixel(c) * cropped_size.width); /* Start of the source line, cropped from the top but not the left */ uint8_t* in_p = data()[c] + (crop.top / out->line_factor(c)) * stride()[c]; -- cgit v1.2.3