| 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * Further, this software is distributed without any warranty that it is |
| 16 | * free of the rightful claim of any third person regarding infringement |
| 17 | * or the like. Any license provided herein, whether implied or |
| 18 | * otherwise, applies only to this software file. Patent licenses, if |
| 19 | * any, provided herein do not apply to combinations of this program with |
| 20 | * other software, or any other product whatsoever. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 27 | * Mountain View, CA 94043, or: |
| 28 | * |
| 29 | * http://www.sgi.com |
| 30 | * |
| 31 | * For further information regarding this notice, see: |
| 32 | * |
| 33 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /* |
| 38 | * Copyright (C) 1990,91 Silicon Graphics, Inc. |
| 39 | * |
| 40 | _______________________________________________________________________ |
| 41 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 42 | | |
| 43 | | $Revision: 1.1.1.1 $ |
| 44 | | |
| 45 | | Classes: |
| 46 | | SoSFImage |
| 47 | | |
| 48 | | Author(s) : Gavin Bell |
| 49 | | |
| 50 | ______________ S I L I C O N G R A P H I C S I N C . ____________ |
| 51 | _______________________________________________________________________ |
| 52 | */ |
| 53 | |
| 54 | #include <Inventor/fields/SoSFImage.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoSFImage.h`/ |
| 55 | |
| 56 | ////////////////////////////////////////////////////////////////////////////// |
| 57 | // |
| 58 | // SoSFImage class |
| 59 | // |
| 60 | ////////////////////////////////////////////////////////////////////////////// |
| 61 | |
| 62 | // Use most of the standard stuff: |
| 63 | SO__FIELD_ID_SOURCEcxx . . $ `lib/database/include/Inventor/fields/SoSubField.h:182:9`!(SoSFImage); |
| 64 | SO__FIELD_EQ_SAME_SOURCEcxx . . $ `lib/database/include/Inventor/fields/SoSubField.h:197:9`!(SoSFImage); |
| 65 | |
| 66 | //////////////////////////////////////////////////////////////////////// |
| 67 | // |
| 68 | // Description: |
| 69 | // Constructor |
| 70 | // |
| 71 | // Use: public |
| 72 | |
| 73 | SoSFImagecxx . . $ SoSFImage#::SoSFImagecxx . . $ SoSFImage#SoSFImage(49f6e7a06ebc5aa8).() |
| 74 | // |
| 75 | //////////////////////////////////////////////////////////////////////// |
| 76 | { |
| 77 | sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).0] = sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).1] = 0; |
| 78 | numComponentscxx . . $ SoSFImage#numComponents. = 0; |
| 79 | bytescxx . . $ SoSFImage#bytes. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 80 | } |
| 81 | |
| 82 | //////////////////////////////////////////////////////////////////////// |
| 83 | // |
| 84 | // Description: |
| 85 | // Destructor. |
| 86 | // |
| 87 | // Use: public |
| 88 | |
| 89 | SoSFImagecxx . . $ SoSFImage#::~cxx . . $ SoSFImage#`~SoSFImage`(49f6e7a06ebc5aa8).SoSFImagecxx . . $ SoSFImage#() |
| 90 | // |
| 91 | //////////////////////////////////////////////////////////////////////// |
| 92 | { |
| 93 | if (bytescxx . . $ SoSFImage#bytes. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) delete[] bytescxx . . $ SoSFImage#bytes.; |
| 94 | } |
| 95 | |
| 96 | //////////////////////////////////////////////////////////////////////// |
| 97 | // |
| 98 | // Description: |
| 99 | // Sets value, given image dimensions and bytes... |
| 100 | // |
| 101 | // Use: public |
| 102 | |
| 103 | void |
| 104 | SoSFImagecxx . . $ SoSFImage#::setValuecxx . . $ SoSFImage#setValue(7f6180548582e173).(const SbVec2scxx . . $ SbVec2s# &s, int nc, const unsigned char *b) |
| 105 | // |
| 106 | //////////////////////////////////////////////////////////////////////// |
| 107 | { |
| 108 | if (bytescxx . . $ SoSFImage#bytes. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) { |
| 109 | delete[] bytescxx . . $ SoSFImage#bytes.; |
| 110 | bytescxx . . $ SoSFImage#bytes. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 111 | } |
| 112 | |
| 113 | sizecxx . . $ SoSFImage#size. =cxx . . $ SbVec2s#`operator=`(1ecf307161264657). s; |
| 114 | numComponentscxx . . $ SoSFImage#numComponents. = nc; |
| 115 | |
| 116 | int numBytes = sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).0]*sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).1]*numComponentscxx . . $ SoSFImage#numComponents.; |
| 117 | |
| 118 | if (numBytes != 0) { |
| 119 | bytescxx . . $ SoSFImage#bytes. = new unsigned char[numBytes]; |
| 120 | memcpy(bytescxx . . $ SoSFImage#bytes., b, numBytes); |
| 121 | } |
| 122 | else |
| 123 | bytescxx . . $ SoSFImage#bytes. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 124 | |
| 125 | valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).(); |
| 126 | } |
| 127 | |
| 128 | //////////////////////////////////////////////////////////////////////// |
| 129 | // |
| 130 | // Description: |
| 131 | // Gets value, which is the image's dimensions and bytes. |
| 132 | // |
| 133 | // Use: public |
| 134 | |
| 135 | const unsigned char * |
| 136 | SoSFImagecxx . . $ SoSFImage#::getValuecxx . . $ SoSFImage#getValue(5acc33cdd6af7846).(SbVec2scxx . . $ SbVec2s# &s, int &nc) const |
| 137 | // |
| 138 | //////////////////////////////////////////////////////////////////////// |
| 139 | { |
| 140 | evaluatecxx . . $ SoField#evaluate(83f5f38750778ac8).(); |
| 141 | |
| 142 | s =cxx . . $ SbVec2s#`operator=`(1ecf307161264657). sizecxx . . $ SoSFImage#size.; |
| 143 | nc = numComponentscxx . . $ SoSFImage#numComponents.; |
| 144 | |
| 145 | return bytescxx . . $ SoSFImage#bytes.; |
| 146 | } |
| 147 | |
| 148 | //////////////////////////////////////////////////////////////////////// |
| 149 | // |
| 150 | // Description: |
| 151 | // Copy image from another field. |
| 152 | // |
| 153 | // Use: public |
| 154 | |
| 155 | const SoSFImagecxx . . $ SoSFImage# & |
| 156 | SoSFImagecxx . . $ SoSFImage#::operatorcxx . . $ SoSFImage#`operator=`(f7d9504ed26f6671). =(const SoSFImagecxx . . $ SoSFImage# &f) |
| 157 | // |
| 158 | //////////////////////////////////////////////////////////////////////// |
| 159 | { |
| 160 | SbVec2scxx . . $ SbVec2s# scxx . . $ SbVec2s#SbVec2s(49f6e7a06ebc5aa8).; |
| 161 | int nc; |
| 162 | const unsigned char *b = f.getValuecxx . . $ SoSFImage#getValue(5acc33cdd6af7846).(s, nc); |
| 163 | setValuecxx . . $ SoSFImage#setValue(7f6180548582e173).(s, nc, b); |
| 164 | |
| 165 | return *this; |
| 166 | } |
| 167 | |
| 168 | //////////////////////////////////////////////////////////////////////// |
| 169 | // |
| 170 | // Description: |
| 171 | // Returns TRUE if field has same value as given field. |
| 172 | // |
| 173 | // Use: public |
| 174 | |
| 175 | int |
| 176 | SoSFImagecxx . . $ SoSFImage#::operatorcxx . . $ SoSFImage#`operator==`(84bf67e79f78865c). ==(const SoSFImagecxx . . $ SoSFImage# &f) const |
| 177 | // |
| 178 | //////////////////////////////////////////////////////////////////////// |
| 179 | { |
| 180 | // Check easy stuff first |
| 181 | if (sizecxx . . $ SoSFImage#size. !=cxx . . $ `operator!=`(9d2dbb110f21f54d). f.sizecxx . . $ SoSFImage#size. || numComponentscxx . . $ SoSFImage#numComponents. != f.numComponentscxx . . $ SoSFImage#numComponents.) |
| 182 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 183 | |
| 184 | if (memcmp(bytescxx . . $ SoSFImage#bytes., f.bytescxx . . $ SoSFImage#bytes., sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).0] * sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).1] * numComponentscxx . . $ SoSFImage#numComponents.) != 0) |
| 185 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 186 | |
| 187 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 188 | } |
| 189 | |
| 190 | //////////////////////////////////////////////////////////////////////// |
| 191 | // |
| 192 | // Description: |
| 193 | // Edit the values of the image |
| 194 | // |
| 195 | // Use: public |
| 196 | |
| 197 | unsigned char * |
| 198 | SoSFImagecxx . . $ SoSFImage#::startEditingcxx . . $ SoSFImage#startEditing(650d940fbfafe2ed).(SbVec2scxx . . $ SbVec2s# &s, int &nc) |
| 199 | // |
| 200 | //////////////////////////////////////////////////////////////////////// |
| 201 | { |
| 202 | s =cxx . . $ SbVec2s#`operator=`(1ecf307161264657). sizecxx . . $ SoSFImage#size.; |
| 203 | nc = numComponentscxx . . $ SoSFImage#numComponents.; |
| 204 | return bytescxx . . $ SoSFImage#bytes.; |
| 205 | } |
| 206 | |
| 207 | //////////////////////////////////////////////////////////////////////// |
| 208 | // |
| 209 | // Description: |
| 210 | // Must be called sometime after editValue to let node notify. |
| 211 | // |
| 212 | // Use: public |
| 213 | |
| 214 | void |
| 215 | SoSFImagecxx . . $ SoSFImage#::finishEditingcxx . . $ SoSFImage#finishEditing(49f6e7a06ebc5aa8).() |
| 216 | // |
| 217 | //////////////////////////////////////////////////////////////////////// |
| 218 | { |
| 219 | valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).(); |
| 220 | } |
| 221 | |
| 222 | //////////////////////////////////////////////////////////////////////// |
| 223 | // |
| 224 | // Description: |
| 225 | // Reads value from file. Returns FALSE on error. |
| 226 | // |
| 227 | // Use: private |
| 228 | |
| 229 | SbBoolcxx . . $ SbBool# |
| 230 | SoSFImagecxx . . $ SoSFImage#::readValuecxx . . $ SoSFImage#readValue(cfb31f743f00c8ca).(SoInputcxx . . $ SoInput# *in) |
| 231 | // |
| 232 | //////////////////////////////////////////////////////////////////////// |
| 233 | { |
| 234 | if (!in->readcxx . . $ SoInput#read(8057bae4a2079318).(sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).0]) || |
| 235 | !in->readcxx . . $ SoInput#read(8057bae4a2079318).(sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).1]) || |
| 236 | !in->readcxx . . $ SoInput#read(795be11dee30bb15).(numComponentscxx . . $ SoSFImage#numComponents.)) |
| 237 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 238 | |
| 239 | if (bytescxx . . $ SoSFImage#bytes. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) delete[] bytescxx . . $ SoSFImage#bytes.; |
| 240 | bytescxx . . $ SoSFImage#bytes. = new unsigned char[sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).0]*sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).1]*numComponentscxx . . $ SoSFImage#numComponents.]; |
| 241 | |
| 242 | int byte = 0; |
| 243 | if (in->isBinarycxx . . $ SoInput#isBinary(b126dc7c1de90089).()) { |
| 244 | // Inventor version 2.1 and later binary file |
| 245 | if (in->getIVVersioncxx . . $ SoInput#getIVVersion(9b8c9e39889c762c).() > 2.0) { |
| 246 | int numBytes = sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).0]*sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).1]*numComponentscxx . . $ SoSFImage#numComponents.; |
| 247 | if (! in->readBinaryArraycxx . . $ SoInput#readBinaryArray(7405b416d0535413).(bytescxx . . $ SoSFImage#bytes., numBytes)) |
| 248 | return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 249 | } |
| 250 | |
| 251 | // Pre version 2.1 Inventor binary files |
| 252 | else { |
| 253 | for (int i = 0; i < sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).0]*sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).1]; i++) { |
| 254 | uint32_tcxx . . $ uint32_t# l; |
| 255 | |
| 256 | if (!in->readcxx . . $ SoInput#read(f2a559ae05e0fafd).(l)) return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 257 | for (int j = 0; j < numComponentscxx . . $ SoSFImage#numComponents.; j++) { |
| 258 | bytescxx . . $ SoSFImage#bytes.[byte++] = (unsigned char)( |
| 259 | (l >> (8*(numComponentscxx . . $ SoSFImage#numComponents.-j-1))) & 0xFF); |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | else { |
| 265 | for (int i = 0; i < sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).0]*sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(3a1bfc038f5ec6).1]; i++) { |
| 266 | uint32_tcxx . . $ uint32_t# l; |
| 267 | |
| 268 | if (!in->readHexcxx . . $ SoInput#readHex(f2a559ae05e0fafd).(l)) return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!; |
| 269 | for (int j = 0; j < numComponentscxx . . $ SoSFImage#numComponents.; j++) { |
| 270 | bytescxx . . $ SoSFImage#bytes.[byte++] = (unsigned char)( |
| 271 | (l >> (8*(numComponentscxx . . $ SoSFImage#numComponents.-j-1))) & 0xFF); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!; |
| 277 | } |
| 278 | |
| 279 | //////////////////////////////////////////////////////////////////////// |
| 280 | // |
| 281 | // Description: |
| 282 | // Writes value of field to file. |
| 283 | // |
| 284 | // Use: private |
| 285 | |
| 286 | void |
| 287 | SoSFImagecxx . . $ SoSFImage#::writeValuecxx . . $ SoSFImage#writeValue(58762e0f79576b7c).(SoOutputcxx . . $ SoOutput# *out) const |
| 288 | // |
| 289 | //////////////////////////////////////////////////////////////////////// |
| 290 | { |
| 291 | out->writecxx . . $ SoOutput#write(68e3ae50fe6578a9).(sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).0]); |
| 292 | |
| 293 | if (! out->isBinarycxx . . $ SoOutput#isBinary(455f465bc33b4cdf).()) |
| 294 | out->writecxx . . $ SoOutput#write(44b6ea1973a07080).(' '); |
| 295 | |
| 296 | out->writecxx . . $ SoOutput#write(68e3ae50fe6578a9).(sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).1]); |
| 297 | |
| 298 | if (! out->isBinarycxx . . $ SoOutput#isBinary(455f465bc33b4cdf).()) |
| 299 | out->writecxx . . $ SoOutput#write(44b6ea1973a07080).(' '); |
| 300 | |
| 301 | out->writecxx . . $ SoOutput#write(d4f767463ce0a6b3).(numComponentscxx . . $ SoSFImage#numComponents.); |
| 302 | |
| 303 | if (out->isBinarycxx . . $ SoOutput#isBinary(455f465bc33b4cdf).()) { |
| 304 | int numBytes = sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).0] * sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).1] * numComponentscxx . . $ SoSFImage#numComponents.; |
| 305 | out->writeBinaryArraycxx . . $ SoOutput#writeBinaryArray(fc0f0e1646c32816).(bytescxx . . $ SoSFImage#bytes., numBytes); |
| 306 | } |
| 307 | else { |
| 308 | int byte = 0; |
| 309 | for (int i = 0; i < sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).0]*sizecxx . . $ SoSFImage#size.[cxx . . $ SbVec2s#`operator[]`(1e601d28ecbc4f85).1]; i++) { |
| 310 | uint32_tcxx . . $ uint32_t# l = 0; |
| 311 | for (int j = 0; j < numComponentscxx . . $ SoSFImage#numComponents.; j++) { |
| 312 | l = (l<<8) | bytescxx . . $ SoSFImage#bytes.[byte++]; |
| 313 | } |
| 314 | out->writecxx . . $ SoOutput#write(44b6ea1973a07080).(' '); |
| 315 | out->writecxx . . $ SoOutput#write(cb2f890c2fdad230).(l); |
| 316 | } |
| 317 | } |
| 318 | } |