63 static_assert(
sizeof(T) <= 4);
64 if(val < (std::numeric_limits<T>::min)())
65 val = (std::numeric_limits<T>::min)();
66 else if(val > (std::numeric_limits<T>::max)())
67 val = (std::numeric_limits<T>::max)();
74 return clip<T>(lhs + rhs);
80 return clip<T>((int64_t)lhs + rhs);
86 return clip<T>((int64_t)lhs - rhs);
92 return clip<T>(lhs - rhs);
117 std::ostringstream os;
118 os <<
"[" <<
x0 <<
"," <<
y0 <<
"," <<
x1 <<
"," <<
y1 <<
"]";
131 return pt.
x >=
x0 && pt.
y >=
y0 && pt.
x <
x1 && pt.
y <
y1;
140 if(rhs && (
this != rhs))
173 return grk_rect<T>((T)(
x0 / denx), (T)(
y0 / deny), (T)ceildiv<uint64_t>(
x1, denx),
174 (T)ceildiv<uint64_t>(
y1, deny));
178 return grk_rect<T>((T)(
x0 >> powx), (T)(
y0 >> powy), (T)ceildivpow2<uint64_t>(
x1, powx),
179 (T)ceildivpow2<uint64_t>(
y1, powy));
187 return grk_rect<T>(ceildiv<uint64_t>(
x0, denx), ceildiv<uint64_t>(
y0, deny),
188 ceildiv<uint64_t>(
x1, denx), ceildiv<uint64_t>(
y1, deny));
197 return grk_rect<T>(ceildivpow2<uint64_t>(
x0, powx), ceildivpow2<uint64_t>(
y0, powy),
198 ceildivpow2<uint64_t>(
x1, powx), ceildivpow2<uint64_t>(
y1, powy));
211 std::min<T>(
x1, rhs->
x1), std::min<T>(
y1, rhs->
y1));
221 std::min<T>(
x1, rhs->
x1), std::min<T>(
y1, rhs->
y1));
226 std::min<T>(
x1, rhs->
x1), std::min<T>(
y1, rhs->
y1));
230 return std::max<T>(
x0, rhs->
x0) < std::min<T>(
x1, rhs->
x1) &&
231 std::max<T>(
y0, rhs->
y0) < std::min<T>(
y1, rhs->
y1);
236 std::max<T>(
x1, rhs->
x1), std::max<T>(
y1, rhs->
y1));
244 return (uint64_t)(
x1 -
x0) * (
y1 -
y0);
264 return grk_rect<T>(satAdd<T>((int64_t)
x0, (int64_t)x), satAdd<T>((int64_t)
y0, (int64_t)y),
265 satAdd<T>((int64_t)
x1, (int64_t)x), satAdd<T>((int64_t)
y1, (int64_t)y));
270 return growIPL(boundary, boundary, (std::numeric_limits<T>::max)(),
271 (std::numeric_limits<T>::max)());
275 return growIPL(boundaryx, boundaryy, (std::numeric_limits<T>::max)(),
276 (std::numeric_limits<T>::max)());
280 return growIPL(boundary, boundary, maxX, maxY);
288 return growIPL(boundary, boundary, bounds);
292 x0 = std::max<T>(satSub<T>(
x0, boundaryx), bounds.
x0);
293 y0 = std::max<T>(satSub<T>(
y0, boundaryy), bounds.
y0);
294 x1 = std::min<T>(satAdd<T>(
x1, boundaryx), bounds.
x1);
295 y1 = std::min<T>(satAdd<T>(
y1, boundaryy), bounds.
y1);
Copyright (C) 2016-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
T satAdd(int64_t lhs, int64_t rhs)
Definition: util.h:72
void GRK_INFO(const char *fmt,...)
Definition: logger.cpp:40
uint32_t ceildiv(T a, T b)
Divide an integer by another integer and round upwards.
Definition: grk_intmath.h:33
T satSub(T lhs, T rhs)
Definition: util.h:84
void clip(grk_image_comp *component, uint8_t precision)
Definition: GrkImage_Conversion.cpp:215
grk_rect< uint32_t > grk_rect32
Definition: util.h:57
T ceildivpow2(T a, uint32_t b)
Definition: grk_intmath.h:40
T x0
Definition: util.h:44
grk_line(T _x0, T _x1)
Definition: util.h:43
grk_line()
Definition: util.h:42
T x1
Definition: util.h:45
T length() const
Definition: util.h:47
grk_pt(T _x, T _y)
Definition: util.h:33
grk_pt()
Definition: util.h:32
uint64_t area(void) const
Definition: util.h:242
T width() const
Definition: util.h:246
void clipIPL(const grk_rect< T > *rhs)
Definition: util.h:218
grk_rect< T > rectUnion(const grk_rect< T > &rhs) const
Definition: util.h:238
T y1
Definition: util.h:109
grk_rect< T > scaleDownCeilPow2(uint32_t powx, uint32_t powy) const
Definition: util.h:195
T x0
Definition: util.h:109
bool operator==(const grk_rect< T > &rhs) const
Definition: util.h:149
grk_rect< T > & growIPL(T boundaryx, T boundaryy, grk_rect< T > bounds)
Definition: util.h:290
T x1
Definition: util.h:109
grk_rect< T > scaleDownPow2(uint32_t powx, uint32_t powy) const
Definition: util.h:176
void set(grk_rect< T > *rhs)
Definition: util.h:155
grk_rect< T > & operator=(const grk_rect< T > &rhs)
Definition: util.h:133
grk_rect< T > & growIPL(T boundaryx, T boundaryy, T maxX, T maxY)
Definition: util.h:282
T height() const
Definition: util.h:250
grk_rect< T > & growIPL(T boundaryx, T boundaryy)
Definition: util.h:273
bool valid(void) const
Definition: util.h:121
T parityY(void) const
Definition: util.h:303
grk_rect< T > clip(const grk_rect< T > *rhs) const
Definition: util.h:208
grk_rect< T > scaleDownCeilPow2(uint32_t power) const
Definition: util.h:190
grk_rect< T > scaleDown(uint64_t denx, uint64_t deny) const
Definition: util.h:171
grk_rect< T > pan(int64_t x, int64_t y) const
Definition: util.h:262
grk_rect< T > scale(uint32_t scalex, uint32_t scaley) const
Definition: util.h:167
bool nonEmptyIntersection(const grk_rect< T > *rhs) const
Definition: util.h:228
grk_rect< T > clip(const grk_rect< T > &rhs) const
Definition: util.h:213
T parityX(void) const
Definition: util.h:299
grk_rect< T > scaleDownPow2(grk_pt< T > pow) const
Definition: util.h:181
virtual ~grk_rect()=default
grk_rect< T > scaleDownCeil(uint64_t denx, uint64_t deny) const
Definition: util.h:185
grk_rect< T > scaleDownCeil(uint32_t den) const
Definition: util.h:163
grk_rect< T > rectUnion(const grk_rect< T > *rhs) const
Definition: util.h:233
grk_rect< T > intersection(const grk_rect< T > rhs) const
Definition: util.h:200
bool contains(grk_pt< T > pt)
Definition: util.h:129
grk_rect< T > & growIPL(T boundary)
Definition: util.h:268
bool empty(void) const
Definition: util.h:125
grk_rect< T > intersection(const grk_rect< T > *rhs) const
Definition: util.h:223
grk_rect(T x0, T y0, T x1, T y1)
Definition: util.h:98
grk_rect(const grk_rect *rhs)
Definition: util.h:100
void set(grk_rect< T > rhs)
Definition: util.h:159
grk_line< T > dimY() const
Definition: util.h:258
virtual void print(void) const
Definition: util.h:111
grk_rect< T > & growIPL(T boundary, T maxX, T maxY)
Definition: util.h:278
grk_line< T > dimX() const
Definition: util.h:254
grk_rect(void)
Definition: util.h:107
grk_rect< T > & growIPL(T boundary, grk_rect< T > bounds)
Definition: util.h:286
bool isContainedIn(const grk_rect< T > rhs) const
Definition: util.h:204
grk_rect(const grk_rect &rhs)
Definition: util.h:99
std::string boundsString() const
Definition: util.h:115
grk_rect< T > & operator=(const grk_rect< T > *rhs)
Definition: util.h:137
T y0
Definition: util.h:109