11 #ifndef __BRAY_Raster__
12 #define __BRAY_Raster__
42 const void *
raster =
nullptr)
43 : myRaster(reinterpret_cast<const char *>(
raster))
45 setRes(xres, yres, pack, fmt);
56 void setupReference(
PXL_Raster &rp,
bool for_write)
const;
58 static int64 memoryUsed();
59 static int64 peakMemoryUsed();
66 if (myXres == xres && myYres == yres
67 && myPacking == pack && myDataFormat == fmt)
72 setRes(xres, yres, pack, fmt);
84 myNChannels = rp.myNChannels;
85 myBPChan = rp.myBPChan;
86 myBPPixel = rp.myBPPixel;
87 myBPScan = rp.myBPScan;
88 myDataFormat = rp.myDataFormat;
89 myPacking = rp.myPacking;
96 || (myBuffer && imageBytes() == rp.
imageBytes()));
103 UT_ASSERT(myBuffer.get() || !imageBytes());
106 memset(myBuffer.get(), 0, imageBytes());
117 #define CLEAR_TO_FLOAT(FORMAT_T) \
119 using T = PXL_TypeResolver< FORMAT_T >::T; \
120 T* buffer = writeRasterAs<T>(); \
124 buffer + (myXres * myYres * myNChannels), \
138 #undef CLEAR_TO_FLOAT
142 const void *
raster()
const {
return myRaster; }
144 template <
typename T>
148 return reinterpret_cast<const T *
>(myRaster);
154 return myBuffer.get();
157 template <
typename T>
162 return reinterpret_cast<T *
>(myBuffer.get());
170 {
return myRaster + byteOffset(x, y); }
172 template <
typename T>
176 return reinterpret_cast<const T *
>(pixel(x, y));
183 return myBuffer.get() + byteOffset(x, y);
186 template <
typename T>
190 return reinterpret_cast<T *
>(writePixel(x, y));
193 #define VECTOR_ACCESS(VEC, NAME) \
194 const VEC *rasterAs##NAME() const { \
195 UT_ASSERT_P(VEC::tuple_size == nchannels()); \
196 UT_ASSERT_P(PXL_DataFormatResolver<VEC::value_type>::format == myDataFormat); \
197 return reinterpret_cast<const VEC *>(myRaster); \
199 VEC *writeRasterAs##NAME() const { \
200 UT_ASSERT_P(VEC::tuple_size == nchannels()); \
201 UT_ASSERT_P(PXL_DataFormatResolver<VEC::value_type>::format == myDataFormat); \
202 UT_ASSERT(myBuffer.get()); \
203 return reinterpret_cast<VEC *>(myBuffer.get()); \
205 const VEC *pixelAs##NAME(exint x, exint y) const { \
206 UT_ASSERT_P(VEC::tuple_size == nchannels()); \
207 UT_ASSERT_P(PXL_DataFormatResolver<VEC::value_type>::format == myDataFormat); \
208 return reinterpret_cast<const VEC *>(pixel(x, y)); \
210 VEC *writePixelAs##NAME(exint x, exint y) const { \
211 UT_ASSERT_P(VEC::tuple_size == nchannels()); \
212 UT_ASSERT_P(PXL_DataFormatResolver<VEC::value_type>::format == myDataFormat); \
213 UT_ASSERT(myBuffer.get()); \
214 return reinterpret_cast<VEC *>(writePixel(x, y)); \
228 bool isValid()
const {
return myRaster && myXres > 0 && myYres > 0; }
229 bool isWritable()
const {
return myBuffer.get() !=
nullptr; }
230 void makeWriteable();
244 UT_ASSERT(!myRaster && myXres == 0 && myYres == 0);
245 setRes(myXres, myYres, pack, fmt);
259 return myYres*myBPScan;
262 bool save(
const char *
filename)
const;
272 return myBPPixel * (y*myXres +
x);
284 myBPPixel = myBPChan * myNChannels;
285 myBPScan = myBPPixel * myXres;
288 const char *myRaster;
BRAY_Raster(exint xres, exint yres, PXL_Packing pack, PXL_DataFormat fmt, const void *raster=nullptr)
void resize(exint xres, exint yres, PXL_Packing pack, PXL_DataFormat fmt)
int PXLpackingComponents(PXL_Packing p)
void copyDataFrom(const BRAY_Raster &rp)
GT_API const UT_StringHolder filename
T * writeRasterAs()
Write access to the raster as a given type.
void copyPropertiesFrom(const BRAY_Raster &rp)
void * writePixel(exint x, exint y) const
Write access to a given pixel.
int64 getMemoryUsage() const
#define CLEAR_TO_FLOAT(FORMAT_T)
const T * rasterAs() const
Read access to the raster as a given type.
PXL_DataFormat dataFormat() const
JSON reader class which handles parsing of JSON or bJSON files.
#define VECTOR_ACCESS(VEC, NAME)
Class which writes ASCII or binary JSON streams.
PXL_Packing packing() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
void createFrom(const BRAY_Raster &rp)
void * writeRaster()
Write access to the raster.
HUSD_API const char * raster()
SYS_DECLARE_LEGACY_TR(GU_Detail)
T * writePixelAs(exint x, exint y) const
Write access to a given pixel as a given type.
const T * pixelAs(exint x, exint y) const
Read access to a given pixel as a given type.
const void * raster() const
Read access to the raster.
ImageBuf OIIO_API resize(const ImageBuf &src, string_view filtername="", float filterwidth=0.0f, ROI roi={}, int nthreads=0)
Base Integer Rectangle class.
const void * pixel(exint x, exint y) const
Read access to a given pixel.
void clearToFloat(float val)
int PXLformatDepth(PXL_DataFormat d)
GLubyte GLubyte GLubyte GLubyte w
const void * scanline(exint y) const
Read access to a given scanline.
math::Vec2< float > Vec2f
void setStorage(PXL_Packing pack, PXL_DataFormat fmt)