Open Inventor Release 2025.2.0
 
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-2025 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
493 {
494 return m_dataType;
495 }
496
498 inline int getNumComponents() const
499 {
500 evaluate();
501 return m_numComponents;
502 }
503
504private:
505
506 static void initClass();
507 static void exitClass();
508 void resetSubTextures();
509 static GLenum getGLType(SoSFImage::DataType dataType);
510
511 SoBufferObject* getBufferObject() const;
512
513 enum HasTransparency
514 {
516 ON,
518 OFF,
520 AUTO
521 };
522
526 void setHasTransparency( HasTransparency status );
527
528 const SbVec2i32& getSize() const
529 {
530 return m_size;
531 }
532
533private:
534
535 // Width and height of image
536 SbVec2i32 m_size;
537
538 // Number of components per pixel
539 int m_numComponents;
540
544 unsigned char* m_buffer;
545
546 // The SoBufferObject which contains the actual data.
547 SoRef<SoBufferObject> m_bufferObject;
548
552 SoRef<SoCpuBufferObject> m_cpuBufferObject;
553
554 CopyPolicy m_copyPolicy;
555
556 // list of [subSize, offset, bytes]
557 SbPList m_subTexList;
558 SbBool m_neverWrite;
559
560 // -1 = don't know yet, 0 = no transp, 1 = has transp
561 int m_hasTransparency;
562
563 HasTransparency m_hasTransparencyState;
564
565 DataType m_dataType;
566
567 unsigned int getImageValueSize() const;
568
569 // Reading and writing
570 virtual SbBool readValue(SoInput *in);
571 virtual void writeValue(SoOutput *out) const;
572 void deleteBytesArray();
573 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
574 const void* data, CopyPolicy copy);
575
576 void setValue (int32_t w, int32_t h, int nc, DataType dataType,
577 SoBufferObject* bufferObject, CopyPolicy copy);
578
579 const void* getValue(int32_t &w, int32_t &h , int &nc, DataType &dataType) const;
580 void* startEditing(int32_t &w, int32_t &h, int &nc, DataType &dataType);
581
582
583};
584
585inline SoBufferObject*
586SoSFImage::getBufferObject() const
587{
588 return m_bufferObject.ptr();
589}
590
591#ifdef _WIN32
592#pragma warning(pop)
593#endif
594
595#endif /* _SO_SF_IMAGE_ */
596
@ 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
<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...
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)
DataType getDataType() const
Returns image's data type.
Definition SoSFImage.h:492
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:498
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...
SoSFImage()
Default constructor.
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.
int SbBool
Boolean type.
Definition SbBase.h:87
unsigned int GLenum