HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_DeepRaster.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: TIL_DeepRaster.h ( TIL Library, C++)
7  *
8  * COMMENTS: A data structure containing multiple planes of TIL_Raster data.
9  * This class will ensure that all rasters have data allocated.
10  */
11 
12 #ifndef __TIL_DeepRaster__
13 #define __TIL_DeepRaster__
14 
15 #include "TIL_API.h"
16 
17 #include "TIL_AdaptiveImage.h"
18 #include "TIL_Raster.h"
19 #include "TIL_Sequence.h"
20 #include <UT/UT_Rect.h>
21 #include <UT/UT_StringHolder.h>
22 #include <UT/UT_UniquePtr.h>
23 #include <SYS/SYS_Types.h>
24 
26 {
27 public:
30  virtual ~TIL_DeepRaster();
31 
32  virtual int64 getMemoryUsage(bool inclusive) const;
33 
34  /// Copies info and data over from src, and replaces the existing one.
35  /// 'scope' allows a selective copy of planes from src (ie, "C A Pz")
36  /// and 'invert_scope' will interpret the list as planes not to copy if true
37  void copy(const TIL_DeepRaster &src,
38  const char *scope = NULL,
39  bool invert_scope = false);
40 
41  /// Appends the info and data from src to the existing data.
42  void append( const TIL_DeepRaster &src);
43 
44  /// Allocate a TIL_Raster for each plane defined by the sequence. Each
45  /// raster will be allocated with interleaved packing. If the plane
46  /// can't be allocated using a TIL_Raster (i.e. vector size of 7, array
47  /// size of 2), then the raster is un-initialized.
48  ///
49  /// When a vector size of 2 is detected as a plane type, we have the
50  /// option of bumping the vector size to 3. This is so that the
51  /// TIL_Raster can be displayed by the OGL code. This is turned on by
52  /// default. Just be aware of this case when dealing with the rasters.
53  void create(const TIL_Sequence &sequence,
54  bool change_vector2_to_vector3=true,
55  bool allocate_raster_storage=true);
56 
57  int getRasterCount() const
58  { return mySequence.getNumPlanes(); }
59  TIL_Sequence &getSequence() { return mySequence; }
60  const TIL_Sequence &getSequence() const { return mySequence; }
61  TIL_Raster &getRaster(int i) { return myRasters[i]; }
62  const TIL_Raster &getRaster(int i) const { return myRasters[i]; }
63 
64  /// Write a tile of interleaved data into the plane specified.
65  bool writeTile(int plane_index,
66  int x0, int x1, int y0, int y1,
67  const void *data);
68 
69  /// Write the given sample data into the image.
70  bool writeSamples(
71  int nsamples,
72  int floats_per_sample,
74  const float *data);
75 
76  /// Clear the raster outside the bounding box specified. If the plane
77  /// index is -1, all planes will be cleared to the color. This does not
78  /// affect the "written" bounding box. To clear the whole raster,
79  /// simply pass in: y0=0, y1=-1 (or y0=yres, y1=0)
80  bool clearOutside(int plane_index,
81  int x0, int x1, int y0, int y1,
82  fpreal value=0);
83 
84  /// Clear all pixels to the given value.
85  void clearPixels(
86  fpreal value = 0,
87  bool stash_samples = false);
88 
89  /// Clear all samples in myAdaptiveImage, without changing
90  /// the rasters.
91  void clearSamples(
92  bool stash_samples = false);
93 
94  // Set/Get attributes of the deep raster
95  const UT_StringHolder &getName() { return myName; }
96  void setName(const UT_StringHolder &name);
97  void setCropWindow(const UT_DimRect &rect)
98  { myCropWindow = rect; }
99  bool hasCropWindow() const
100  { return !myCropWindow.isEmpty(); }
101  const UT_DimRect & getCropWindow() const
102  { return myCropWindow; }
104  { return myCropWindow; }
105  bool hasDataWritten() const
106  { return !myWriteBox.isEmpty(); }
108  { return myWriteBox; }
109  const UT_DimRect & getWrittenWindow() const
110  { return myWriteBox; }
111 
112  // Set attributes of individual planes
113  void setEdgeStreak(int plane,
114  int ex0, int ex1, int ey0, int ey1);
115  bool getEdgeStreak(int plane,
116  int &ex0, int &ex1, int &ey0, int &ey1);
117  void clearEdgeStreak(int plane);
118 
119  void setBlackPoint(int plane, fpreal bpoint);
120  void setWhitePoint(int plane, fpreal wpoint);
121 
122  bool swapOut() { return writeToDisk(); }
123  bool swapIn()
124  {
125  return mySwapped ? readFromDisk() : true;
126  }
128  {
129  if (mySwapped)
130  {
131  swapIn();
132  removeDiskFile();
133  }
134  }
135 
137  {
138  return myAdaptiveImage.get();
139  }
140 
141  int numPlaneSourceComponents(int planei) const;
142  int numPlaneDestComponents(int planei) const;
143 
144  int planeSourceStartComponent(int planei) const;
145 
146 private:
147 
148  void copyArrays( TIL_Raster *tmp_Rasters, int *tmp_BPP,
149  bool *tmp_2Bit, bool *tmp_EdgeStreakFlag,
150  int *tmp_EdgeStreak, const TIL_DeepRaster &src);
151  void clear();
152  void initialize();
153 
154  bool writeToDisk();
155  bool readFromDisk();
156  void removeDiskFile();
157 
158  TIL_Sequence mySequence;
159  UT_UniquePtr<TIL_Raster[]> myRasters;
160  UT_UniquePtr<TIL_AdaptiveImage> myAdaptiveImage;
161  UT_UniquePtr<int[]> myBPP;
162  UT_UniquePtr<bool[]> my2Bit;
163  UT_UniquePtr<bool[]> myEdgeStreakFlag;
164  UT_UniquePtr<int[]> myEdgeStreak;
165  char *mySwapFile;
166 
167  // Global attributes
168  UT_StringHolder myName; // Name of raster
169  UT_DimRect myCropWindow; // Crop window (data window)
170  UT_DimRect myWriteBox; // Box of written pixels
171  bool mySwapped;
172 };
173 
174 #endif
int getRasterCount() const
const UT_DimRect & getWrittenWindow() const
const TIL_AdaptiveImage * getAdaptiveImage() const
void writeSamples(short *data, int size)
const UT_StringHolder & getName()
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
bool hasDataWritten() const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
bool hasCropWindow() const
GLdouble y1
Definition: glad.h:2349
TIL_Raster & getRaster(int i)
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
UT_DimRect & getWrittenWindow()
GLsizei samples
Definition: glcorearb.h:1298
const UT_DimRect & getCropWindow() const
const TIL_Raster & getRaster(int i) const
fpreal64 fpreal
Definition: SYS_Types.h:277
const TIL_Sequence & getSequence() const
Definition: core.h:1131
UT_DimRect & getCropWindow()
#define TIL_API
Definition: TIL_API.h:10
TIL_Sequence & getSequence()
Definition: format.h:895
GLenum src
Definition: glcorearb.h:1793
void setCropWindow(const UT_DimRect &rect)