00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef _SO_SF_IMAGE_
00051 #define _SO_SF_IMAGE_
00052
00053 #include <Inventor/SbDataType.h>
00054 #include <Inventor/SbLinear.h>
00055 #include <Inventor/SbPList.h>
00056 #include <Inventor/fields/SoSubField.h>
00057 #include <Inventor/sys/SoGLType.h>
00058 #include <Inventor/devices/SoBufferObject.h>
00059 #include <Inventor/devices/SoCpuBufferObject.h>
00060
00061 #ifdef _WIN32
00062 #pragma warning(push)
00063 #pragma warning(disable:4251)
00064 #endif
00065
00066 class SbRasterImage;
00067
00069
00070
00071
00073
00126 class SoSFImage : public SoSField {
00127
00128
00129
00130 SO_SFIELD_REQUIRED_HEADER(SoSFImage);
00131 SO_SFIELD_CONSTRUCTOR_HEADER(SoSFImage);
00132
00133 public:
00134
00139 SoSFImage( const SoSFImage& obj );
00140
00141 #ifdef FLOAT
00142 #undef FLOAT
00143 #endif
00144
00147 enum DataType {
00149 UNSIGNED_BYTE = SbDataType::UNSIGNED_BYTE,
00151 UNSIGNED_SHORT = SbDataType::UNSIGNED_SHORT,
00153 UNSIGNED_INT32 = SbDataType::UNSIGNED_INT32,
00155 SIGNED_BYTE = SbDataType::SIGNED_BYTE,
00157 SIGNED_SHORT = SbDataType::SIGNED_SHORT,
00159 SIGNED_INT32 = SbDataType::SIGNED_INT32,
00161 FLOAT = SbDataType::FLOAT
00162 };
00163
00164
00173 enum CopyPolicy {
00177 COPY = 0,
00181 NO_COPY = 1,
00186 NO_COPY_AND_DELETE = 2,
00191 NO_COPY_AND_FREE = 3
00192 };
00193
00194
00195
00196
00206 const void* getValue(SbVec2s &size, int &nc, DataType &dataType) const;
00211 const void* getValue(SbVec2i32 &size, int &nc, DataType &dataType) const;
00212
00220 const unsigned char *getValue(SbVec2s &size, int &nc) const;
00225 const unsigned char *getValue(SbVec2i32 &size, int &nc) const;
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00252 void setValue(const SbVec2s &size, int nc,
00253 DataType dataType,
00254 const void* data,
00255 CopyPolicy copy=COPY);
00256
00257 void setValue(const SbVec2s &size, int nc,
00258 DataType dataType,
00259 SoBufferObject* bufferObject,
00260 CopyPolicy copy=COPY);
00261
00265 void setValue (const SbVec2i32 &size, int nc,
00266 DataType dataType,
00267 const void* data,
00268 CopyPolicy copy=COPY);
00269
00270 void setValue (const SbVec2i32 &size, int nc,
00271 DataType dataType,
00272 SoBufferObject* bufferObject,
00273 CopyPolicy copy=COPY);
00274
00280 void setValue(const SbVec2s &size, int nc,
00281 const unsigned char *bytes,
00282 CopyPolicy copy = COPY);
00283
00284 void setValue(const SbVec2i32 &size, int nc,
00285 const unsigned char *bytes,
00286 CopyPolicy copy = COPY);
00287
00288
00300 void setSubValue(const SbVec2s &subSize,
00301 const SbVec2s &offset,
00302 void *data);
00306 void setSubValue (const SbVec2i32 &subSize,
00307 const SbVec2i32 &offset,
00308 void *data);
00309
00310
00317 void setSubValue(const SbVec2s &subSize,
00318 const SbVec2s &offset,
00319 unsigned char *bytes);
00323 void setSubValue(const SbVec2i32 &subSize,
00324 const SbVec2i32 &offset,
00325 unsigned char *bytes);
00326
00327
00339 void setSubValues(const SbVec2s *subSizes,
00340 const SbVec2s *offsets,
00341 int num, void **data);
00345 void setSubValues (const SbVec2i32 *subSizes,
00346 const SbVec2i32 *offsets,
00347 int num, void **data);
00348
00349
00356 void setSubValues(const SbVec2s *subSizes,
00357 const SbVec2s *offsets,
00358 int num, unsigned char **subBytes);
00359
00363 void setSubValues(const SbVec2i32 *subSizes,
00364 const SbVec2i32 *offsets,
00365 int num, unsigned char **subBytes);
00366
00367
00371 int operator ==(const SoSFImage &f) const;
00372
00376 int operator !=(const SoSFImage &f) const
00377 { return ! ((*this) == f); }
00378
00390 void* startEditing(SbVec2s &size, int &nc, DataType &dataType);
00394 void* startEditing(SbVec2i32 &size, int &nc, DataType &dataType);
00395
00402 unsigned char *startEditing(SbVec2s &size, int &nc);
00406 unsigned char *startEditing(SbVec2i32 &size, int &nc);
00407
00408
00416 void finishEditing();
00417
00426 void* getSubTexture(int index, SbVec2s &size, SbVec2s &offset, DataType &dataType);
00427
00432 void* getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset, DataType &dataType);
00433
00441 unsigned char *getSubTexture(int index, SbVec2s &size, SbVec2s &offset);
00447 unsigned char *getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset);
00448
00455 SbBool hasSubTextures(int &numSubTextures);
00456
00464 void setNeverWrite(SbBool neverWrite);
00465
00469 SbBool isNeverWrite()
00470 { return m_neverWrite ; }
00471
00477 SbBool hasTransparency() const;
00478
00489 SbRasterImage* toRasterImage(bool downSample = true) const;
00490
00492 inline int getNumComponents() const
00493 {
00494 evaluate();
00495 return m_numComponents;
00496 }
00497
00498 private:
00499
00500 static void initClass();
00501 static void exitClass();
00502 void resetSubTextures();
00503 static GLenum getGLType(SoSFImage::DataType dataType);
00504
00505 SoBufferObject* getBufferObject() const;
00506
00507 enum HasTransparency
00508 {
00510 ON,
00512 OFF,
00514 AUTO
00515 };
00516
00520 void setHasTransparency( HasTransparency status );
00521
00522 SbVec2i32 getSize() const
00523 {return m_size;}
00524
00525 private:
00526
00527
00528 SbVec2i32 m_size;
00529
00530
00531 int m_numComponents;
00532
00536 unsigned char* m_buffer;
00537
00538
00539 SoRef<SoBufferObject> m_bufferObject;
00540
00544 SoRef<SoCpuBufferObject> m_cpuBufferObject;
00545
00546 CopyPolicy m_copyPolicy;
00547
00548
00549 SbPList m_subTexList;
00550 SbBool m_neverWrite;
00551
00552
00553 int m_hasTransparency;
00554
00555 HasTransparency m_hasTransparencyState;
00556
00557 DataType m_dataType;
00558
00559 unsigned int getImageValueSize() const;
00560
00561
00562 virtual SbBool readValue(SoInput *in);
00563 virtual void writeValue(SoOutput *out) const;
00564 void deleteBytesArray();
00565 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
00566 const void* data, CopyPolicy copy);
00567
00568 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
00569 SoBufferObject* bufferObject, CopyPolicy copy);
00570
00571 const void* getValue(int32_t &w, int32_t &h , int &nc, DataType &dataType) const;
00572 void* startEditing(int32_t &w, int32_t &h, int &nc, DataType &dataType);
00573
00574
00575 };
00576
00577 inline SoBufferObject*
00578 SoSFImage::getBufferObject() const
00579 {
00580 return m_bufferObject.ptr();
00581 }
00582
00583 #ifdef _WIN32
00584 #pragma warning(pop)
00585 #endif
00586
00587 #endif
00588
00589