Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoSFImage.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Gavin Bell (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2018 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_SF_IMAGE_
51#define _SO_SF_IMAGE_
52
53#include <Inventor/SbDataType.h>
54#include <Inventor/SbLinear.h>
55#include <Inventor/SbPList.h>
56#include <Inventor/fields/SoSubField.h>
57#include <Inventor/sys/SoGLType.h>
58#include <Inventor/devices/SoBufferObject.h>
59#include <Inventor/devices/SoCpuBufferObject.h>
60
61#ifdef _WIN32
62#pragma warning(push)
63#pragma warning(disable:4251)
64#endif
65
66class SbRasterImage;
67
69//
70// SoSFImage subclass of SoSField.
71//
73
126class SoSFImage : public SoSField {
127
128 // Uses only some of the standard field stuff
129 // (because there is no SbImage type):
130 SO_SFIELD_REQUIRED_HEADER(SoSFImage);
131 SO_SFIELD_CONSTRUCTOR_HEADER(SoSFImage);
132
133public:
134
139 SoSFImage( const SoSFImage& obj );
140
141#ifdef FLOAT
142#undef FLOAT
143#endif
163
164
193
194 // getValue returns the size, number of components and a constant
195 // pointer to the image.
196
206 const void* getValue(SbVec2s &size, int &nc, DataType &dataType) const;
211 const void* getValue(SbVec2i32 &size, int &nc, DataType &dataType) const;
212
220 const unsigned char *getValue(SbVec2s &size, int &nc) const;
225 const unsigned char *getValue(SbVec2i32 &size, int &nc) const;
226
227
228
229 // setValue copies the image given to it into internal storage.
230 // See startEditing() for a way of avoiding the copy if you are
231 // doing a getValue() followed immediately by a setValue(). Set
232 // 'copy' to NO_COPY or NO_COPY_AND_DELETE to pass directly the
233 // pointer on the images. Otherwise, the buffer 'bytes' will be
234 // copied. If copy is set to COPY or NO_COPY_AND_DELETE or
235 // NO_COPY_AND_FREE, this object will delete the buffer when
236 // required. If a NULL pointer is passed, a new bloc is allocated
237 // according to the size and the number of components.
238
252 void setValue(const SbVec2s &size, int nc,
253 DataType dataType,
254 const void* data,
255 CopyPolicy copy=COPY);
256
257 void setValue(const SbVec2s &size, int nc,
258 DataType dataType,
259 SoBufferObject* bufferObject,
260 CopyPolicy copy=COPY);
261
265 void setValue (const SbVec2i32 &size, int nc,
266 DataType dataType,
267 const void* data,
268 CopyPolicy copy=COPY);
269
270 void setValue (const SbVec2i32 &size, int nc,
271 DataType dataType,
272 SoBufferObject* bufferObject,
273 CopyPolicy copy=COPY);
274
280 void setValue(const SbVec2s &size, int nc,
281 const unsigned char *bytes,
282 CopyPolicy copy = COPY);
283
284 void setValue(const SbVec2i32 &size, int nc,
285 const unsigned char *bytes,
286 CopyPolicy copy = COPY);
287
288
300 void setSubValue(const SbVec2s &subSize,
301 const SbVec2s &offset,
302 void *data);
306 void setSubValue (const SbVec2i32 &subSize,
307 const SbVec2i32 &offset,
308 void *data);
309
310
317 void setSubValue(const SbVec2s &subSize,
318 const SbVec2s &offset,
319 unsigned char *bytes);
323 void setSubValue(const SbVec2i32 &subSize,
324 const SbVec2i32 &offset,
325 unsigned char *bytes);
326
327
339 void setSubValues(const SbVec2s *subSizes,
340 const SbVec2s *offsets,
341 int num, void **data);
345 void setSubValues (const SbVec2i32 *subSizes,
346 const SbVec2i32 *offsets,
347 int num, void **data);
348
349
356 void setSubValues(const SbVec2s *subSizes,
357 const SbVec2s *offsets,
358 int num, unsigned char **subBytes);
359
363 void setSubValues(const SbVec2i32 *subSizes,
364 const SbVec2i32 *offsets,
365 int num, unsigned char **subBytes);
366
367
371 int operator ==(const SoSFImage &f) const;
372
376 int operator !=(const SoSFImage &f) const
377 { return ! ((*this) == f); }
378
390 void* startEditing(SbVec2s &size, int &nc, DataType &dataType);
394 void* startEditing(SbVec2i32 &size, int &nc, DataType &dataType);
395
402 unsigned char *startEditing(SbVec2s &size, int &nc);
406 unsigned char *startEditing(SbVec2i32 &size, int &nc);
407
408
417
426 void* getSubTexture(int index, SbVec2s &size, SbVec2s &offset, DataType &dataType);
427
432 void* getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset, DataType &dataType);
433
441 unsigned char *getSubTexture(int index, SbVec2s &size, SbVec2s &offset);
447 unsigned char *getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset);
448
455 SbBool hasSubTextures(int &numSubTextures);
456
464 void setNeverWrite(SbBool neverWrite);
465
470 { return m_neverWrite ; }
471
478
489 SbRasterImage* toRasterImage(bool downSample = true) const;
490
492 inline int getNumComponents() const
493 {
494 evaluate();
495 return m_numComponents;
496 }
497
498private:
499
500 static void initClass();
501 static void exitClass();
502 void resetSubTextures();
503 static GLenum getGLType(SoSFImage::DataType dataType);
504
505 SoBufferObject* getBufferObject() const;
506
507 enum HasTransparency
508 {
510 ON,
512 OFF,
514 AUTO
515 };
516
520 void setHasTransparency( HasTransparency status );
521
522 SbVec2i32 getSize() const
523 {return m_size;}
524
525private:
526
527 // Width and height of image
528 SbVec2i32 m_size;
529
530 // Number of components per pixel
531 int m_numComponents;
532
536 unsigned char* m_buffer;
537
538 // The SoBufferObject which contains the actual data.
539 SoRef<SoBufferObject> m_bufferObject;
540
544 SoRef<SoCpuBufferObject> m_cpuBufferObject;
545
546 CopyPolicy m_copyPolicy;
547
548 // list of [subSize, offset, bytes]
549 SbPList m_subTexList;
550 SbBool m_neverWrite;
551
552 // -1 = don't know yet, 0 = no transp, 1 = has transp
553 int m_hasTransparency;
554
555 HasTransparency m_hasTransparencyState;
556
557 DataType m_dataType;
558
559 unsigned int getImageValueSize() const;
560
561 // Reading and writing
562 virtual SbBool readValue(SoInput *in);
563 virtual void writeValue(SoOutput *out) const;
564 void deleteBytesArray();
565 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
566 const void* data, CopyPolicy copy);
567
568 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
569 SoBufferObject* bufferObject, CopyPolicy copy);
570
571 const void* getValue(int32_t &w, int32_t &h , int &nc, DataType &dataType) const;
572 void* startEditing(int32_t &w, int32_t &h, int &nc, DataType &dataType);
573
574
575};
576
577inline SoBufferObject*
578SoSFImage::getBufferObject() const
579{
580 return m_bufferObject.ptr();
581}
582
583#ifdef _WIN32
584#pragma warning(pop)
585#endif
586
587#endif /* _SO_SF_IMAGE_ */
588
@ FLOAT
float
Definition SbDataType.h:78
@ SIGNED_BYTE
signed byte
Definition SbDataType.h:72
@ UNSIGNED_INT32
unsigned int (32bits)
Definition SbDataType.h:70
@ UNSIGNED_BYTE
unsigned byte
Definition SbDataType.h:66
@ SIGNED_SHORT
signed short
Definition SbDataType.h:74
@ UNSIGNED_SHORT
unsigned short
Definition SbDataType.h:68
@ SIGNED_INT32
signed int (32bits)
Definition SbDataType.h:76
List of generic (void *) pointers.
Definition SbPList.h:77
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Class encapsulat...
2D vector class.
Definition SbVec.h:517
2D vector class.
Definition SbVec.h:700
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
Used to read Open Inventor data files.
Definition SoInput.h:363
Used to write Open Inventor data files.
Definition SoOutput.h:186
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
T * ptr() const
Cast to C pointer.
Definition SoRef.h:167
Field containing a 2D image.
Definition SoSFImage.h:126
void setSubValues(const SbVec2s *subSizes, const SbVec2s *offsets, int num, void **data)
This method can be used for subtexturing.
SbRasterImage * toRasterImage(bool downSample=true) const
Returns an instance of SbRasterImage filled with the content of this field.
void * startEditing(SbVec2s &size, int &nc, DataType &dataType)
This method (along with finishEditing()) can be used to efficiently edit the values in an image field...
void setValue(const SbVec2i32 &size, int nc, DataType dataType, const void *data, CopyPolicy copy=COPY)
void setValue(const SbVec2i32 &size, int nc, const unsigned char *bytes, CopyPolicy copy=COPY)
unsigned char * getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset)
const unsigned char * getValue(SbVec2s &size, int &nc) const
Same as above.
int getNumComponents() const
Returns image's number of components.
Definition SoSFImage.h:492
const void * getValue(SbVec2i32 &size, int &nc, DataType &dataType) const
SoSFImage(const SoSFImage &obj)
Copy constructor.
void setValue(const SbVec2i32 &size, int nc, DataType dataType, SoBufferObject *bufferObject, CopyPolicy copy=COPY)
void * getSubTexture(int index, SbVec2s &size, SbVec2s &offset, DataType &dataType)
Returns a buffer of a given subTexture set by setSubValue(), setSubValues() or a startEditing()/finis...
unsigned char * startEditing(SbVec2s &size, int &nc)
Same as above.
void finishEditing()
This method (along with startEditing())can be used to efficiently edit the values in an image field.
void setValue(const SbVec2s &size, int nc, DataType dataType, SoBufferObject *bufferObject, CopyPolicy copy=COPY)
int operator!=(const SoSFImage &f) const
Inequality test.
Definition SoSFImage.h:376
void * startEditing(SbVec2i32 &size, int &nc, DataType &dataType)
void setValue(const SbVec2s &size, int nc, const unsigned char *bytes, CopyPolicy copy=COPY)
Same as above.
void setSubValue(const SbVec2i32 &subSize, const SbVec2i32 &offset, void *data)
SbBool isNeverWrite()
Queries the "neverWrite" flag.
Definition SoSFImage.h:469
CopyPolicy
SoSFImage may be manipulating some large amounts of memory.
Definition SoSFImage.h:173
@ NO_COPY
Passed buffer used , user will delete.
Definition SoSFImage.h:181
@ COPY
Open Inventor will make a copy of the data (default)
Definition SoSFImage.h:177
@ NO_COPY_AND_DELETE
Passed buffer used, SoSFImage will delete.
Definition SoSFImage.h:186
@ NO_COPY_AND_FREE
Passed buffer used, SoSFImage will free.
Definition SoSFImage.h:191
DataType
Encoding data type.
Definition SoSFImage.h:147
@ SIGNED_SHORT
SIGNED_SHORT.
Definition SoSFImage.h:157
@ UNSIGNED_SHORT
UNSIGNED_SHORT.
Definition SoSFImage.h:151
@ FLOAT
FLOAT.
Definition SoSFImage.h:161
@ UNSIGNED_INT32
UNSIGNED_INT32.
Definition SoSFImage.h:153
@ SIGNED_INT32
SIGNED_INT32.
Definition SoSFImage.h:159
@ SIGNED_BYTE
SIGNED_BYTE.
Definition SoSFImage.h:155
@ UNSIGNED_BYTE
UNSIGNED_BYTE.
Definition SoSFImage.h:149
const unsigned char * getValue(SbVec2i32 &size, int &nc) const
const void * getValue(SbVec2s &size, int &nc, DataType &dataType) const
Returns the pixels in the image as an array of values of type <dataType>.
void setValue(const SbVec2s &size, int nc, DataType dataType, const void *data, CopyPolicy copy=COPY)
Sets the value of this field to be an image of the given size, with the given number of components,...
SbBool hasTransparency() const
Returns TRUE if the image contains any transparent pixels.
unsigned char * getSubTexture(int index, SbVec2s &size, SbVec2s &offset)
Same as above.
void setSubValues(const SbVec2i32 *subSizes, const SbVec2i32 *offsets, int num, unsigned char **subBytes)
void setSubValue(const SbVec2s &subSize, const SbVec2s &offset, unsigned char *bytes)
Same as above.
void setNeverWrite(SbBool neverWrite)
Sets the "neverWrite" flag.
int operator==(const SoSFImage &f) const
Equality test.
void * getSubTexture(int index, SbVec2i32 &size, SbVec2i32 &offset, DataType &dataType)
void setSubValue(const SbVec2i32 &subSize, const SbVec2i32 &offset, unsigned char *bytes)
SbBool hasSubTextures(int &numSubTextures)
Returns TRUE if subTextures have been defined or FALSE if none have been defined.
unsigned char * startEditing(SbVec2i32 &size, int &nc)
void setSubValues(const SbVec2s *subSizes, const SbVec2s *offsets, int num, unsigned char **subBytes)
Same as above.
void setSubValues(const SbVec2i32 *subSizes, const SbVec2i32 *offsets, int num, void **data)
void setSubValue(const SbVec2s &subSize, const SbVec2s &offset, void *data)
This method can be used for subtexturing.
Abstract base class for all single-value fields.
Definition SoSField.h:93
int SbBool
Boolean type.
Definition SbBase.h:87