summaryrefslogtreecommitdiff
path: root/src/lib/image.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-06-16 14:53:35 +0100
committerCarl Hetherington <cth@carlh.net>2013-06-16 14:53:35 +0100
commit4699463e19b2a153d64aeb0e00c62be1157bfc1b (patch)
tree971d505d0b5a8253a24eb95854effb5e34893c8c /src/lib/image.cc
parent12074b64d64c1fe76a9cf07a46683b7db96fc56e (diff)
Some work on cropping in the film viewer; also prevent player from always scaling up to DCP resolution.
Diffstat (limited to 'src/lib/image.cc')
-rw-r--r--src/lib/image.cc31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/lib/image.cc b/src/lib/image.cc
index 17c969cf2..5f7d3f034 100644
--- a/src/lib/image.cc
+++ b/src/lib/image.cc
@@ -53,22 +53,28 @@ Image::swap (Image& other)
std::swap (_pixel_format, other._pixel_format);
}
-/** @param n Component index.
- * @return Number of lines in the image for the given component.
- */
int
-Image::lines (int n) const
+Image::line_factor (int n) const
{
if (n == 0) {
- return size().height;
+ return 1;
}
-
+
AVPixFmtDescriptor const * d = av_pix_fmt_desc_get(_pixel_format);
if (!d) {
throw PixelFormatError (N_("lines()"), _pixel_format);
}
- return size().height / pow(2.0f, d->log2_chroma_h);
+ return pow (2.0f, d->log2_chroma_h);
+}
+
+/** @param n Component index.
+ * @return Number of lines in the image for the given component.
+ */
+int
+Image::lines (int n) const
+{
+ return size().height / line_factor (n);
}
/** @return Number of components */
@@ -207,9 +213,9 @@ 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;
-
+
/* Start of the source line, cropped from the top but not the left */
- uint8_t* in_p = data()[c] + crop.top * stride()[c];
+ uint8_t* in_p = data()[c] + (crop.top / out->line_factor(c)) * stride()[c];
uint8_t* out_p = out->data()[c];
for (int y = 0; y < out->lines(c); ++y) {
@@ -502,12 +508,11 @@ SimpleImage::SimpleImage (AVFrame* frame)
}
}
-SimpleImage::SimpleImage (shared_ptr<const Image> other)
+SimpleImage::SimpleImage (shared_ptr<const Image> other, bool aligned)
: Image (*other.get())
+ , _size (other->size())
+ , _aligned (aligned)
{
- _size = other->size ();
- _aligned = true;
-
allocate ();
for (int i = 0; i < components(); ++i) {