// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
// Rectangular region in image(s). Factoring this out of Image instead of // shifting the pointer by x0/y0 allows this to apply to multiple images with // different resolutions (e.g. color transform and quantization field). // Can compare using SameSize(rect1, rect2). template <typename T> class RectT { public: // Most windows are xsize_max * ysize_max, except those on the borders where // begin + size_max > end.
constexpr RectT(T xbegin, T ybegin, size_t xsize_max, size_t ysize_max,
T xend, T yend)
: x0_(xbegin),
y0_(ybegin),
xsize_(ClampedSize(xbegin, xsize_max, xend)),
ysize_(ClampedSize(ybegin, ysize_max, yend)) {}
// Construct with origin and known size (typically from another Rect).
constexpr RectT(T xbegin, T ybegin, size_t xsize, size_t ysize)
: x0_(xbegin), y0_(ybegin), xsize_(xsize), ysize_(ysize) {}
// Construct a rect that covers a whole image/plane/ImageBundle etc. template <typename ImageT> explicit RectT(const ImageT& image)
: RectT(0, 0, image.xsize(), image.ysize()) {}
// Construct a subrect that resides in an image/plane/ImageBundle etc. template <typename ImageT>
RectT Crop(const ImageT& image) const { return Intersection(RectT(image));
}
// Construct a subrect that resides in the [0, ysize) x [0, xsize) region of // the current rect.
RectT Crop(size_t area_xsize, size_t area_ysize) const { return Intersection(RectT(0, 0, area_xsize, area_ysize));
}
// Returns true if this Rect fully resides in the given image. ImageT could be // Plane<T> or Image3<T>; however if ImageT is Rect, results are nonsensical. template <class ImageT> bool IsInside(const ImageT& image) const { return IsInside(RectT(image));
}
private: // Returns size_max, or whatever is left in [begin, end). static constexpr size_t ClampedSize(T begin, size_t size_max, T end) { return (static_cast<T>(begin + size_max) <= end)
? size_max
: (end > begin ? end - begin : 0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.