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
00060 #ifdef _WIN32
00061 #pragma warning(push)
00062 #pragma warning(disable:4251)
00063 #endif
00064
00065 class SoCpuBufferObject;
00066 class SbRasterImage;
00067
00069
00070
00071
00073
00127 class SoSFImage : public SoSField {
00128
00129
00130
00131 SO_SFIELD_REQUIRED_HEADER(SoSFImage);
00132 SO_SFIELD_CONSTRUCTOR_HEADER(SoSFImage);
00133
00134 public:
00135
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
00387 void* startEditing(SbVec2s &size, int &nc, DataType &dataType);
00391 void* startEditing(SbVec2i32 &size, int &nc, DataType &dataType);
00392
00399 unsigned char *startEditing(SbVec2s &size, int &nc);
00403 unsigned char *startEditing(SbVec2i32 &size, int &nc);
00404
00405
00410 void finishEditing();
00411
00420 void* getSubTexture(int index, SbVec2s &size, SbVec2s &offset, DataType &dataType);
00421
00426 void* getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset, DataType &dataType);
00427
00435 unsigned char *getSubTexture(int index, SbVec2s &size, SbVec2s &offset);
00441 unsigned char *getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset);
00442
00449 SbBool hasSubTextures(int &numSubTextures);
00450
00458 void setNeverWrite(SbBool neverWrite);
00459
00463 SbBool isNeverWrite()
00464 { return m_neverWrite ; }
00465
00471 SbBool hasTransparency() const;
00472
00483 SbRasterImage* toRasterImage(bool downSample = true) const;
00484
00485 private:
00486
00487 static void initClass();
00488 static void exitClass();
00489 void resetSubTextures();
00490 static GLenum getGLType(SoSFImage::DataType dataType);
00491
00492 SoBufferObject* getBufferObject() const;
00493
00494 enum HasTransparency
00495 {
00497 ON,
00499 OFF,
00501 AUTO
00502 };
00503
00507 void setHasTransparency( HasTransparency status );
00508
00509 SbVec2i32 getSize() const
00510 {return m_size;}
00511
00512 private:
00513
00514
00515 SbVec2i32 m_size;
00516
00517
00518 int m_numComponents;
00519
00523 unsigned char* m_buffer;
00524
00525
00526 SoRef<SoBufferObject> m_bufferObject;
00527
00531 SoRef<SoCpuBufferObject> m_cpuBufferObject;
00532
00533 CopyPolicy m_copyPolicy;
00534
00535
00536 SbPList m_subTexList;
00537 SbBool m_neverWrite;
00538
00539
00540 int m_hasTransparency;
00541
00542 HasTransparency m_hasTransparencyState;
00543
00544 DataType m_dataType;
00545
00546 unsigned int getImageValueSize() const;
00547
00548
00549 virtual SbBool readValue(SoInput *in);
00550 virtual void writeValue(SoOutput *out) const;
00551 void deleteBytesArray();
00552 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
00553 const void* data, CopyPolicy copy);
00554
00555 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
00556 SoBufferObject* bufferObject, CopyPolicy copy);
00557
00558 const void* getValue(int32_t &w, int32_t &h , int &nc, DataType &dataType) const;
00559 void* startEditing(int32_t &w, int32_t &h, int &nc, DataType &dataType);
00560
00561
00562 };
00563
00564 inline SoBufferObject*
00565 SoSFImage::getBufferObject() const
00566 {
00567 return m_bufferObject.ptr();
00568 }
00569
00570 #ifdef _WIN32
00571 #pragma warning(pop)
00572 #endif
00573
00574 #endif
00575
00576