Go to the documentation of this file.
31 return (b && (a > UINT_MAX / b));
34 return (b && (a > UINT64_MAX / b));
51 template<
typename T> T
clip(int64_t val) {
52 if(val < (std::numeric_limits<T>::min)())
53 val = (std::numeric_limits<T>::min)();
54 else if (val > (std::numeric_limits<T>::max)())
55 val = (std::numeric_limits<T>::max)();
59 template<
typename T> T
sat_add(int64_t lhs, int64_t rhs) {
60 return clip<T>(lhs + rhs);
63 template<
typename T> T
sat_add(T lhs, T rhs) {
64 return clip<T>((int64_t)lhs + rhs);
67 template<
typename T> T
sat_sub(T lhs, T rhs) {
68 return clip<T>((int64_t)lhs - rhs);
71 template<
typename T> T
sat_sub(int64_t lhs, int64_t rhs) {
72 return clip<T>(lhs - rhs);
88 std::cout <<
"[" <<
x0 <<
"," <<
y0 <<
"," <<
x1 <<
"," <<
y1 <<
"]"
98 return pt.
x >=
x0 && pt.
y >=
y0 && pt.
x <
x1 && pt.
y <
y1;
145 std::max<T>(
y0,rhs->
y0),
146 std::min<T>(
x1,rhs->
x1),
147 std::min<T>(
y1,rhs->
y1));
152 std::min<T>(
y0,rhs->
y0),
153 std::max<T>(
x1,rhs->
x1),
154 std::max<T>(
y1,rhs->
y1));
160 return (uint64_t)(
x1 -
x0) * (
y1 -
y0);
171 sat_add<T>((int64_t)
y0, (int64_t)y),
172 sat_add<T>((int64_t)
x1, (int64_t)x),
173 sat_add<T>((int64_t)
y1, (int64_t)y));
176 return grow(boundary, boundary,(std::numeric_limits<T>::max)(),(std::numeric_limits<T>::max)());
179 return grow(boundaryx, boundaryy,(std::numeric_limits<T>::max)(),(std::numeric_limits<T>::max)());
182 return grow(boundary, boundary,maxX,maxY);
185 x0 = sat_sub<T>(
x0, boundaryx);
186 y0 = sat_sub<T>(
y0, boundaryy);
187 x1 = sat_add<T>(
x1, boundaryx);
188 y1 = sat_add<T>(
y1, boundaryx);
197 using grk_rect = grk_rectangle<int64_t>;
204 grk_buffer(T *buffer,
size_t off,
size_t length,
bool ownsData) :
buf(buffer),
238 GRK_WARN(
"grk_buf: attempt to increment buffer offset out of bounds");
246 if (
offset < (
size_t)(-off)) {
321 uint64_t data_size_needed = (uint64_t)
stride *
height() *
sizeof(T);
322 if (!data_size_needed)
326 grk::GRK_ERROR(
"Failed to allocate aligned memory buffer of dimensions %u x %u "
331 memset(
data, 0, data_size_needed);
355 void transfer(T** buffer,
bool* owns, uint32_t *strd){
368 if (!inter.non_empty())
371 T* dest =
data + (inter.y0 *
stride + inter.x0);
372 T* src = rhs.
data + ((inter.y0 - rhs.
y0) * rhs.
stride + inter.x0 - rhs.
x0);
373 uint32_t len = inter.width();
374 for (uint32_t j = inter.y0; j < inter.y1; ++j){
375 filter.copy(dest,src, len);
grk_buffer(T *buffer, size_t length, bool ownsData)
Definition: util.h:210
void transfer(T **buffer, bool *owns, uint32_t *strd)
Definition: util.h:355
virtual ~grk_buffer_2d()
Definition: util.h:305
void grk_aligned_free(void *ptr)
Definition: MemManager.cpp:123
grk_buffer(T *buffer, size_t off, size_t length, bool ownsData)
Definition: util.h:204
T height() const
Definition: util.h:165
bool mult_will_overflow(uint32_t a, uint32_t b)
Definition: util.h:30
virtual ~grk_buffer()
Definition: util.h:213
size_t offset
Definition: util.h:264
bool owns_data
Definition: util.h:382
bool isContainedIn(const grk_rectangle< T > rhs) const
Definition: util.h:140
void acquire(T *buffer, uint32_t strd)
Definition: util.h:347
grk_rectangle< T > & grow(T boundaryx, T boundaryy, T maxX, T maxY)
Definition: util.h:184
grk_rectangle(T x0, T y0, T x1, T y1)
Definition: util.h:78
grk_rectangle< T > & grow(T boundaryx, T boundaryy)
Definition: util.h:178
grk_rectangle< int64_t > grk_rect
Definition: util.h:47
grk_rectangle< T > pan(int64_t x, int64_t y) const
Definition: util.h:169
void GRK_WARN(const char *fmt,...)
Definition: logger.cpp:49
bool operator==(const grk_rectangle< T > &rhs)
Definition: util.h:111
grk_buffer_2d(uint32_t w, uint32_t h)
Definition: util.h:280
void attach(T *buffer, uint32_t strd)
Definition: util.h:339
bool alloc(bool clear)
Definition: util.h:318
T ceildivpow2(T a, uint32_t b)
Definition: grk_intmath.h:37
T x1
Definition: util.h:76
bool is_valid(void) const
Definition: util.h:91
grk_buffer_2d & operator=(const grk_buffer_2d &rhs)
Definition: util.h:290
size_t get_remaining_length(void)
Definition: util.h:226
grk_rectangle< T > ceildiv(uint32_t den) const
Definition: util.h:131
bool owns_data
Definition: util.h:266
grk_rectangle(const grk_rectangle &rhs)
Definition: util.h:81
T * curr_ptr()
Definition: util.h:256
grk_rectangle< T > rect_union(const grk_rectangle< T > *rhs) const
Definition: util.h:150
void dealloc()
Definition: util.h:217
uint32_t grk_make_aligned_width(uint32_t width)
Definition: MemManager.cpp:40
grk_point(T _x, T _y)
Definition: util.h:39
grk_rectangle< T > & grow(T boundary)
Definition: util.h:175
T sat_sub(T lhs, T rhs)
Definition: util.h:67
T * buf
Definition: util.h:263
void * grk_aligned_malloc(size_t size)
Allocate memory aligned to a 16 byte boundary.
Definition: MemManager.cpp:119
void copy(grk_buffer_2d &rhs, F filter)
Definition: util.h:366
grk_buffer_2d & operator=(const grk_buffer_2d *rhs)
Definition: util.h:294
grk_buffer_2d(void)
Definition: util.h:287
grk_point()
Definition: util.h:38
uint32_t stride
Definition: util.h:383
void print(void) const
Definition: util.h:87
T width() const
Definition: util.h:162
bool contains(grk_point< T > pt)
Definition: util.h:97
grk_rectangle< T > rect_union(const grk_rectangle< T > &rhs) const
Definition: util.h:156
grk_rectangle< T > intersection(const grk_rectangle< T > *rhs) const
Definition: util.h:143
Copyright (C) 2016-2020 Grok Image Compression Inc.
Definition: BitIO.cpp:23
size_t len
Definition: util.h:265
uint64_t area(void) const
Definition: util.h:159
T sat_add(int64_t lhs, int64_t rhs)
Definition: util.h:59
grk_rectangle< uint32_t > grk_rect_u32
Definition: util.h:48
void copy_rect(grk_rect_u32 b)
Definition: util.h:311
grk_rectangle< T > intersection(const grk_rectangle< T > rhs) const
Definition: util.h:137
void incr_offset(ptrdiff_t off)
Definition: util.h:230
grk_buffer_2d(uint32_t w, uint32_t strd, uint32_t h)
Definition: util.h:278
grk_rectangle< T > & grow(T boundary, T maxX, T maxY)
Definition: util.h:181
grk_buffer()
Definition: util.h:201
grk_rectangle< T > rectceildivpow2(uint32_t power) const
Definition: util.h:125
void set_rect(grk_rectangle< T > *rhs)
Definition: util.h:118
void set_rect(grk_rectangle< T > rhs)
Definition: util.h:122
T * data
Definition: util.h:381
grk_rectangle< T > & operator=(const grk_rectangle< T > &rhs)
Definition: util.h:100
T x0
Definition: util.h:76
T y1
Definition: util.h:76
T clip(int64_t val)
Definition: util.h:51
bool mult64_will_overflow(uint64_t a, uint64_t b)
Definition: util.h:33
grk_buffer_2d(T *buffer, bool ownsData, uint32_t w, uint32_t strd, uint32_t h)
Definition: util.h:273
grk_buffer_2d(grk_rect_u32 b)
Definition: util.h:282
const size_t default_align
Definition: MemManager.h:28
T y0
Definition: util.h:76
#define SIZE_MAX
Definition: MemManager.cpp:33
void GRK_ERROR(const char *fmt,...)
Definition: logger.cpp:57
bool non_empty(void) const
Definition: util.h:94
grk_rectangle(void)
Definition: util.h:84