PageRenderTime 71ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/Source/System/Image/ES/OSGImage.cpp

https://github.com/msteners/OpenSGDevMaster_Toolbox
C++ | 4050 lines | 3342 code | 471 blank | 237 comment | 463 complexity | 965cbb2329f2e89da24bf671cb61cfe6 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause
  1. /*---------------------------------------------------------------------------*\
  2. * OpenSG *
  3. * *
  4. * *
  5. * Copyright (C) 2000-2002 by the OpenSG Forum *
  6. * *
  7. * www.opensg.org *
  8. * *
  9. * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
  10. * *
  11. \*---------------------------------------------------------------------------*/
  12. /*---------------------------------------------------------------------------*\
  13. * License *
  14. * *
  15. * This library is free software; you can redistribute it and/or modify it *
  16. * under the terms of the GNU Library General Public License as published *
  17. * by the Free Software Foundation, version 2. *
  18. * *
  19. * This library is distributed in the hope that it will be useful, but *
  20. * WITHOUT ANY WARRANTY; without even the implied warranty of *
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
  22. * Library General Public License for more details. *
  23. * *
  24. * You should have received a copy of the GNU Library General Public *
  25. * License along with this library; if not, write to the Free Software *
  26. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
  27. * *
  28. \*---------------------------------------------------------------------------*/
  29. /*---------------------------------------------------------------------------*\
  30. * Changes *
  31. * *
  32. * *
  33. * *
  34. * *
  35. * *
  36. * *
  37. \*---------------------------------------------------------------------------*/
  38. //---------------------------------------------------------------------------
  39. // Includes
  40. //---------------------------------------------------------------------------
  41. #define OSG_COMPILEIMAGE
  42. #include <cstdlib>
  43. #include <cstdio>
  44. #include <algorithm>
  45. #include "OSGConfig.h"
  46. #include "OSGLog.h"
  47. #include "OSGImageGenericAtt.h"
  48. #include "OSGFieldContainerFields.h"
  49. #include "OSGFileSystem.h"
  50. //#include "OSGImageFileHandler.h"
  51. /*
  52. #include "OSGPathHandler.h"
  53. #include "OSGSceneFileHandler.h"
  54. */
  55. #include "OSGImage.h"
  56. OSG_USING_NAMESPACE
  57. // Documentation for this class is emited in the
  58. // OSGImageBase.cpp file.
  59. // To modify it, please change the .fcd file (OSGImage.fcd) and
  60. // regenerate the base file.
  61. /*------------------------------------------------------------------------*/
  62. /* static member */
  63. /*! Static dictionary to map pixelData values to the bytes per pixel
  64. (bpp) value.
  65. Internaly used in the createData() method.
  66. */
  67. Int32 Image::_formatDic[][2] =
  68. {
  69. { OSG_A_PF, 1 },
  70. #if !defined(OSG_EMBEDDED) || OSG_GL_ES_VERSION > 100
  71. { OSG_I_PF, 1 },
  72. #endif
  73. { OSG_L_PF, 1 },
  74. { OSG_LA_PF, 2 },
  75. { OSG_RGB_PF, 3 },
  76. { OSG_RGBA_PF, 4 },
  77. { OSG_BGR_PF, 3 },
  78. { OSG_BGRA_PF, 4 },
  79. { OSG_RGB_DXT1, 3 },
  80. { OSG_RGBA_DXT1, 4 },
  81. { OSG_RGBA_DXT3, 4 },
  82. { OSG_RGBA_DXT5, 4 }
  83. };
  84. Int32 Image::_typeDic[][2] =
  85. {
  86. { OSG_INVALID_IMAGEDATATYPE, 0 },
  87. { OSG_UINT8_IMAGEDATA, 1 },
  88. #if defined(GL_UNSIGNED_SHORT)
  89. { OSG_UINT16_IMAGEDATA, 2 },
  90. #endif
  91. #if !defined(OSG_EMBEDDED)
  92. { OSG_UINT32_IMAGEDATA, 4 },
  93. { OSG_FLOAT16_IMAGEDATA, 2 },
  94. #endif
  95. { OSG_FLOAT32_IMAGEDATA, 4 }
  96. };
  97. /*----------------------------- class specific ----------------------------*/
  98. void Image::initMethod(InitPhase ePhase)
  99. {
  100. }
  101. /*! Inform parents, when image was changed
  102. */
  103. void Image::changed(ConstFieldMaskArg whichField,
  104. UInt32 origin,
  105. BitVector details)
  106. {
  107. MFParentFieldContainerPtr::iterator parentsIt = _mfParents.begin();
  108. MFParentFieldContainerPtr::iterator parentsEnd = _mfParents.end();
  109. while(parentsIt != parentsEnd)
  110. {
  111. (*parentsIt)->changed(
  112. TypeTraits<BitVector>::One << parentsIt->getParentFieldPos(),
  113. ChangedOrigin::Child,
  114. whichField);
  115. ++parentsIt;
  116. }
  117. if(0x0000 != (whichField & DataTypeFieldMask))
  118. {
  119. // Update internals
  120. Int32 mapSizeType = sizeof(_typeDic) / sizeof(UInt32[2]);
  121. UInt32 typeFormat = 0;
  122. Int32 i;
  123. for(i = 0; i < mapSizeType; i++)
  124. {
  125. if(_typeDic[i][0] == _sfDataType.getValue())
  126. {
  127. typeFormat = _typeDic[i][1];
  128. }
  129. }
  130. setComponentSize( typeFormat );
  131. }
  132. if(0x0000 != (whichField & (MipMapCountFieldMask |
  133. WidthFieldMask |
  134. HeightFieldMask |
  135. DepthFieldMask |
  136. PixelFormatFieldMask )))
  137. {
  138. setSideSize(calcMipmapSumSize(_sfMipMapCount.getValue()));
  139. }
  140. if(0x0000 != (whichField & (SideSizeFieldMask | SideCountFieldMask)))
  141. {
  142. setFrameSize(_sfSideSize.getValue() * _sfSideCount.getValue());
  143. }
  144. Inherited::changed(whichField, origin, details);
  145. }
  146. /*----------------------------- output ------------------------------------*/
  147. void Image::dump( UInt32 ,
  148. const BitVector ) const
  149. {
  150. const Char8 *pfStr = "UNDEF_PIXEL_FORMAT";
  151. const Char8 *typeStr = "INVALID_IMAGEDATA_TYPE";
  152. switch(getPixelFormat())
  153. {
  154. case OSG_A_PF:
  155. pfStr = "ALPHA";
  156. break;
  157. #if !defined(OSG_EMBEDDED)
  158. case OSG_I_PF:
  159. pfStr = "INTENSITY";
  160. break;
  161. #endif
  162. case OSG_L_PF:
  163. pfStr = "LUMINANCE";
  164. break;
  165. case OSG_LA_PF:
  166. pfStr = "LUMINANCE_ALPHA";
  167. break;
  168. #if !defined(OSG_EMBEDDED)
  169. case OSG_BGR_PF:
  170. pfStr = "BGR";
  171. break;
  172. case OSG_BGRA_PF:
  173. pfStr = "BGRA";
  174. break;
  175. #endif
  176. case OSG_RGB_PF:
  177. pfStr = "RGB";
  178. break;
  179. case OSG_RGBA_PF:
  180. pfStr = "RGBA";
  181. break;
  182. #if !defined(OSG_EMBEDDED)
  183. case OSG_RGB_DXT1:
  184. pfStr = "RGB_DXT1";
  185. break;
  186. case OSG_RGBA_DXT1:
  187. pfStr = "RGBA_DXT1";
  188. break;
  189. case OSG_RGBA_DXT3:
  190. pfStr = "RGBA_DXT3";
  191. break;
  192. case OSG_RGBA_DXT5:
  193. pfStr = "RGBA_DXT5";
  194. break;
  195. #endif
  196. default:
  197. pfStr = "UNKNOWN_PIXEL_FORMAT";
  198. break;
  199. };
  200. switch (getDataType())
  201. {
  202. case OSG_UINT8_IMAGEDATA:
  203. typeStr = "IMAGEDATA_TYPE UCHAR8";
  204. break;
  205. #if defined(GL_UNSIGNED_SHORT)
  206. case OSG_UINT16_IMAGEDATA:
  207. typeStr = "IMAGEDATA_TYPE UCHAR16";
  208. break;
  209. #endif
  210. #if !defined(OSG_EMBEDDED)
  211. case OSG_UINT32_IMAGEDATA:
  212. typeStr = "IMAGEDATA_TYPE UCHAR32";
  213. break;
  214. case OSG_FLOAT16_IMAGEDATA:
  215. typeStr = "IMAGEDATA_TYPE FLOAT16";
  216. break;
  217. #endif
  218. case OSG_FLOAT32_IMAGEDATA:
  219. typeStr = "IMAGEDATA_TYPE FLOAT32";
  220. break;
  221. default:
  222. typeStr = "UNKNOWN_IMAGEDATA_TYPE";
  223. break;
  224. };
  225. FLOG (("ImageDump: %s; %d/%d/%d; #mm: %d, side %d, #frame: %d, "
  226. "frameDelay %g, dataType %s, size: %d\n",
  227. pfStr,
  228. getWidth(),
  229. getHeight(),
  230. getDepth(),
  231. getMipMapCount(),
  232. getSideCount(),
  233. getFrameCount(),
  234. getFrameDelay(),
  235. typeStr,
  236. getSize()));
  237. }
  238. // Return the number of components per pixel.
  239. UInt8 Image::getComponents(void) const
  240. {
  241. Int32 mapSizeFormat = sizeof(_formatDic) / sizeof(UInt32[2]);
  242. for(UInt16 i = 0; i < mapSizeFormat; i++)
  243. {
  244. if(_formatDic[i][0] == getPixelFormat())
  245. return _formatDic[i][1];
  246. }
  247. FWARNING(("Image::getComponents: image %p has unknown pixel format 0x%x!",
  248. this, getPixelFormat()));
  249. return 0;
  250. }
  251. /*------------------------------ set object data --------------------------*/
  252. /*! method to set the image data. Use the doCopy parameter to specify, whether
  253. the method should copy or link the pixel data.
  254. */
  255. bool Image::set( UInt32 pF,
  256. Int32 w,
  257. Int32 h,
  258. Int32 d,
  259. Int32 mmS,
  260. Int32 fS,
  261. Time fD,
  262. const UChar8 *da,
  263. Int32 t,
  264. bool allocMem,
  265. Int32 sS)
  266. {
  267. setPixelFormat(pF );
  268. setWidth (osgMax ( 1, w ));
  269. setHeight (osgMax ( 1, h ));
  270. setDepth (osgMax ( 1, d ));
  271. setMipMapCount(osgMax ( 1, mmS));
  272. setSideCount (osgMax ( 1, sS ));
  273. setFrameCount (osgMax ( 1, fS ));
  274. setFrameDelay (fD);
  275. setDataType (t );
  276. return createData(da, allocMem);
  277. }
  278. /*! method to set the image from another image object.
  279. Use the doCopy parameter to specify, whether
  280. the method should copy or link the pixel data.
  281. */
  282. bool Image::set(ImagePtr image)
  283. {
  284. this->set(image->getPixelFormat(),
  285. image->getWidth (),
  286. image->getHeight (),
  287. image->getDepth (),
  288. image->getMipMapCount(),
  289. image->getFrameCount (),
  290. image->getFrameDelay (),
  291. image->getData (),
  292. image->getDataType (),
  293. true,
  294. image->getSideCount ());
  295. return true;
  296. }
  297. /*! method to set only the image pixel data, all parameter (e. pixelFormat
  298. width,height and depth) stay the same
  299. */
  300. bool Image::setData(const UChar8 *da)
  301. {
  302. if(da)
  303. {
  304. createData(da);
  305. }
  306. else
  307. {
  308. FWARNING(("Image::setData(Null) call\n"));
  309. }
  310. return (da ? true : false);
  311. }
  312. void Image::clearData(void)
  313. {
  314. editPixel().clear();
  315. }
  316. /*! method to update just a subregion of the image data
  317. all paramter (e. pixelFormat,width,height,depth) stay the same
  318. */
  319. bool Image::setSubData( Int32 offX,
  320. Int32 offY,
  321. Int32 offZ,
  322. Int32 srcW,
  323. Int32 srcH,
  324. Int32 srcD,
  325. const UInt8 *src )
  326. {
  327. UChar8 *dest = editData();
  328. UInt64 lineSize;
  329. FDEBUG(( "Image::setSubData (%d %d %d) - (%d %d %d) - src %p\n",
  330. offX, offY, offZ, srcW, srcH, srcD, src ));
  331. if (hasCompressedData())
  332. {
  333. FFATAL (("Invalid Image::setSubData for compressed image\n"));
  334. return false;
  335. }
  336. if(!src || !dest)
  337. {
  338. FFATAL(("Invalid data pointer in Image::setSubData\n"));
  339. return false;
  340. }
  341. // determine the area to actually copy
  342. UInt32 xMin = osgMax(0, offX);
  343. UInt32 yMin = osgMax(0, offY);
  344. UInt32 zMin = osgMax(0, offZ);
  345. UInt32 xMax = osgMin(getWidth (), offX + srcW);
  346. UInt32 yMax = osgMin(getHeight(), offY + srcH);
  347. UInt32 zMax = osgMin(getDepth (), offZ + srcD);
  348. // fill the destination buffer with the subdata
  349. UInt32 destIdx, srcIdx = 0;
  350. for(UInt32 z = zMin; z < zMax; z++)
  351. {
  352. for(UInt32 y = yMin; y < yMax; y++)
  353. {
  354. lineSize = (xMax - xMin) * getBpp();
  355. destIdx = ((z * getHeight() + y) * getWidth() + xMin) * getBpp();
  356. memcpy (&dest[destIdx], &src[srcIdx], size_t(lineSize));
  357. srcIdx += Int32((srcW - (xMax - xMin)) * getBpp() + lineSize);
  358. }
  359. srcIdx += (srcH - (yMax - yMin)) * srcW * getBpp();
  360. }
  361. return true;
  362. }
  363. /*! The Image is not just a 2D container. The class can hold 3D (volume)
  364. and movie data. If we have 3D/singleFrame or 2D/multiFrame data without
  365. mipmaps we can flip between this two formats by just swapping the
  366. getFrameCount() and getDepth() values.
  367. */
  368. bool Image::flipDepthFrameData(void)
  369. {
  370. bool retCode = false;
  371. Int32 value;
  372. if((getMipMapCount() == 1) &&
  373. ((getFrameCount() == 1) || (getDepth() == 1)))
  374. {
  375. value = getFrameCount();
  376. setFrameCount(getDepth());
  377. setDepth (value );
  378. retCode = true;
  379. }
  380. else
  381. {
  382. FWARNING (("Cant flipDepthFrameData(); invalid data layout\n"));
  383. }
  384. return retCode;
  385. }
  386. /*! This method is used by the parser to fill the image with
  387. string pixel data. It expects the data in VRML PixelTexture Format.
  388. */
  389. bool Image::addValue(const char *value)
  390. {
  391. static Image *currentImage = 0;
  392. static UChar8 *currentData = 0;
  393. Int64 j;
  394. Int64 v;
  395. bool isHead = strchr(value, ' ') ? true : false;
  396. if (hasCompressedData())
  397. {
  398. FFATAL (("Invalid Image::addValue for compressed image\n"));
  399. return false;
  400. }
  401. // make sure we only read one image at a time
  402. if(currentImage == this)
  403. {
  404. if(isHead)
  405. {
  406. FDEBUG(("Start new read cycle in image::addValue()\n"));
  407. }
  408. }
  409. else
  410. {
  411. if(!isHead)
  412. {
  413. FFATAL(("Additional image date for different image\n"));
  414. }
  415. }
  416. currentImage = this;
  417. if(isHead == true)
  418. {
  419. Int32 width;
  420. Int32 height;
  421. Int32 pixelDepth;
  422. PixelFormat pf = Image::OSG_INVALID_PF;
  423. // read the head
  424. sscanf(value, "%d %d %d", &width, &height, &pixelDepth);
  425. FDEBUG(("Image::addValue() set: w/h/bpp: %d/%d/%d\n",
  426. width, height, pixelDepth));
  427. switch(getDataType())
  428. {
  429. case OSG_UINT8_IMAGEDATA:
  430. switch(pixelDepth)
  431. {
  432. case 1:
  433. pf = OSG::Image::OSG_L_PF;
  434. break;
  435. case 2:
  436. pf = OSG::Image::OSG_LA_PF;
  437. break;
  438. case 3:
  439. pf = OSG::Image::OSG_RGB_PF;
  440. break;
  441. case 4:
  442. pf = OSG::Image::OSG_RGBA_PF;
  443. break;
  444. default:
  445. pf = OSG::Image::OSG_INVALID_PF;
  446. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  447. break;
  448. }
  449. break;
  450. #if !defined(OSG_EMBEDDED)
  451. case OSG_UINT16_IMAGEDATA:
  452. switch(pixelDepth)
  453. {
  454. case 2:
  455. pf = OSG::Image::OSG_L_PF;
  456. break;
  457. case 4:
  458. pf = OSG::Image::OSG_LA_PF;
  459. break;
  460. case 6:
  461. pf = OSG::Image::OSG_RGB_PF;
  462. break;
  463. case 8:
  464. pf = OSG::Image::OSG_RGBA_PF;
  465. break;
  466. default:
  467. pf = OSG::Image::OSG_INVALID_PF;
  468. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  469. break;
  470. }
  471. break;
  472. case OSG_UINT32_IMAGEDATA:
  473. switch(pixelDepth)
  474. {
  475. case 4:
  476. pf = OSG::Image::OSG_L_PF;
  477. break;
  478. case 8:
  479. pf = OSG::Image::OSG_LA_PF;
  480. break;
  481. case 12:
  482. pf = OSG::Image::OSG_RGB_PF;
  483. break;
  484. case 16:
  485. pf = OSG::Image::OSG_RGBA_PF;
  486. break;
  487. default:
  488. pf = OSG::Image::OSG_INVALID_PF;
  489. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  490. break;
  491. }
  492. break;
  493. #endif
  494. case OSG_FLOAT32_IMAGEDATA:
  495. switch(pixelDepth)
  496. {
  497. case 4:
  498. pf = OSG::Image::OSG_L_PF;
  499. break;
  500. case 8:
  501. pf = OSG::Image::OSG_LA_PF;
  502. break;
  503. case 12:
  504. pf = OSG::Image::OSG_RGB_PF;
  505. break;
  506. case 16:
  507. pf = OSG::Image::OSG_RGBA_PF;
  508. break;
  509. default:
  510. pf = OSG::Image::OSG_INVALID_PF;
  511. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  512. break;
  513. }
  514. break;
  515. #if !defined(OSG_EMBEDDED)
  516. case OSG_FLOAT16_IMAGEDATA:
  517. switch(pixelDepth)
  518. {
  519. case 2:
  520. pf = OSG::Image::OSG_L_PF;
  521. break;
  522. case 4:
  523. pf = OSG::Image::OSG_LA_PF;
  524. break;
  525. case 6:
  526. pf = OSG::Image::OSG_RGB_PF;
  527. break;
  528. case 8:
  529. pf = OSG::Image::OSG_RGBA_PF;
  530. break;
  531. default:
  532. pf = OSG::Image::OSG_INVALID_PF;
  533. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  534. break;
  535. }
  536. break;
  537. #endif
  538. default:
  539. setDataType(OSG_INVALID_IMAGEDATATYPE);
  540. FFATAL(("Invalid type of image data: %d\n", getDataType()));
  541. }
  542. if(pf != 0 && (width > 0) && (height > 0))
  543. {
  544. set(pf, width, height);
  545. currentData = editData();
  546. }
  547. else
  548. {
  549. currentData = NULL;
  550. }
  551. }
  552. else
  553. {
  554. if(currentData != NULL)
  555. {
  556. // add data
  557. // TODO; should we check the bounds, should be done by the parser
  558. v = strtoul(value, 0, strchr(value, 'x') ? 16 : 10);
  559. for(j = getBpp(); j--;)
  560. {
  561. *currentData++ = UChar8( (v >> (8 * j)) & 255 );
  562. }
  563. }
  564. }
  565. return currentData ? true : false;
  566. }
  567. /*! It is a simple method to reformat the image pixelFormat (not the size).
  568. So you can for example convert a RGBA to RGB or RGB to Grey image.
  569. */
  570. bool Image::reformat(const Image::PixelFormat pixelFormat,
  571. ImagePtr destination)
  572. {
  573. UChar8 *data = NULL;
  574. const UChar8 *sourceData = NULL;
  575. UInt32 srcI, destI, destSize = 0;
  576. UInt32 sum;
  577. Real64 sumReal;
  578. ImagePtr dest = destination;
  579. if (hasCompressedData())
  580. {
  581. FFATAL (("Invalid Image::reformat for compressed image\n"));
  582. return false;
  583. }
  584. if(destination == NullFC)
  585. {
  586. dest = Image::create();
  587. addRef(dest);
  588. }
  589. FINFO(("Try to reformat image from pixelDepth %d to %d\n",
  590. getPixelFormat(),
  591. pixelFormat ));
  592. // TODO !!! code all the cases !!!
  593. if(getSize() &&
  594. pixelFormat &&
  595. (destination != NullFC || (pixelFormat != getPixelFormat())))
  596. {
  597. dest->set(pixelFormat, getWidth(), getHeight(), getDepth() );
  598. sourceData = getData();
  599. data = dest->editData();
  600. destSize = dest->getSize();
  601. const UInt16 *sourceDataUC16 = (const UInt16 *) sourceData;
  602. UInt16 *destDataUC16 = ( UInt16 *) data;
  603. const UInt32 *sourceDataUC32 = (const UInt32 *) sourceData;
  604. UInt32 *destDataUC32 = ( UInt32 *) data;
  605. const Real32 *sourceDataF32 = (const Real32 *) sourceData;
  606. Real32 *destDataF32 = ( Real32 *) data;
  607. const Real16 *sourceDataH16 = (const Real16 *) sourceData;
  608. Real16 *destDataH16 = ( Real16 *) data;
  609. if(data)
  610. {
  611. switch (getPixelFormat())
  612. {
  613. //-----------------------------------------------------
  614. case OSG_A_PF:
  615. switch (pixelFormat) {
  616. case OSG_A_PF:
  617. #if !defined(OSG_EMBEDDED)
  618. case OSG_I_PF:
  619. #endif
  620. switch (getDataType())
  621. {
  622. case OSG_UINT8_IMAGEDATA:
  623. memcpy (data, getData(), destSize);
  624. break;
  625. #if !defined(OSG_EMBEDDED)
  626. case OSG_UINT16_IMAGEDATA:
  627. memcpy (data, getData(), destSize);
  628. break;
  629. case OSG_UINT32_IMAGEDATA:
  630. memcpy (data, getData(), destSize);
  631. break;
  632. #endif
  633. case OSG_FLOAT32_IMAGEDATA:
  634. memcpy (data, getData(), destSize);
  635. break;
  636. #if !defined(OSG_EMBEDDED)
  637. case OSG_FLOAT16_IMAGEDATA:
  638. memcpy (data, getData(), destSize);
  639. break;
  640. #endif
  641. default:
  642. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  643. break;
  644. }
  645. break;
  646. case OSG_L_PF:
  647. switch (getDataType())
  648. {
  649. case OSG_UINT8_IMAGEDATA:
  650. memcpy (data, getData(), destSize);
  651. break;
  652. #if !defined(OSG_EMBEDDED)
  653. case OSG_UINT16_IMAGEDATA:
  654. memcpy (data, getData(), destSize);
  655. break;
  656. case OSG_UINT32_IMAGEDATA:
  657. memcpy (data, getData(), destSize);
  658. break;
  659. #endif
  660. case OSG_FLOAT32_IMAGEDATA:
  661. memcpy (data, getData(), destSize);
  662. break;
  663. #if !defined(OSG_EMBEDDED)
  664. case OSG_FLOAT16_IMAGEDATA:
  665. memcpy (data, getData(), destSize);
  666. break;
  667. #endif
  668. default:
  669. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  670. break;
  671. }
  672. break;
  673. case OSG_LA_PF:
  674. switch (getDataType())
  675. {
  676. case OSG_UINT8_IMAGEDATA:
  677. for (srcI = destI = 0; destI < destSize;)
  678. {
  679. data[destI++] = sourceData[srcI];
  680. data[destI++] = sourceData[srcI++];
  681. }
  682. break;
  683. #if !defined(OSG_EMBEDDED)
  684. case OSG_UINT16_IMAGEDATA:
  685. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  686. {
  687. destDataUC16[destI++] = sourceDataUC16[srcI];
  688. destDataUC16[destI++] = sourceDataUC16[srcI++];
  689. }
  690. break;
  691. case OSG_UINT32_IMAGEDATA:
  692. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  693. {
  694. destDataUC32[destI++] = sourceDataUC32[srcI];
  695. destDataUC32[destI++] = sourceDataUC32[srcI++];
  696. }
  697. break;
  698. #endif
  699. case OSG_FLOAT32_IMAGEDATA:
  700. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  701. {
  702. destDataF32[destI++] = sourceDataF32[srcI];
  703. destDataF32[destI++] = sourceDataF32[srcI++];
  704. }
  705. break;
  706. #if !defined(OSG_EMBEDDED)
  707. case OSG_FLOAT16_IMAGEDATA:
  708. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  709. {
  710. destDataH16[destI++] = sourceDataH16[srcI];
  711. destDataH16[destI++] = sourceDataH16[srcI++];
  712. }
  713. break;
  714. #endif
  715. default:
  716. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  717. break;
  718. }
  719. break;
  720. case OSG_RGB_PF:
  721. switch (getDataType())
  722. {
  723. case OSG_UINT8_IMAGEDATA:
  724. for (srcI = destI = 0; destI < destSize;)
  725. {
  726. data[destI++] = sourceData[srcI];
  727. data[destI++] = sourceData[srcI];
  728. data[destI++] = sourceData[srcI++];
  729. }
  730. break;
  731. #if !defined(OSG_EMBEDDED)
  732. case OSG_UINT16_IMAGEDATA:
  733. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  734. {
  735. destDataUC16[destI++] = sourceDataUC16[srcI];
  736. destDataUC16[destI++] = sourceDataUC16[srcI];
  737. destDataUC16[destI++] = sourceDataUC16[srcI++];
  738. }
  739. break;
  740. case OSG_UINT32_IMAGEDATA:
  741. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  742. {
  743. destDataUC32[destI++] = sourceDataUC32[srcI];
  744. destDataUC32[destI++] = sourceDataUC32[srcI];
  745. destDataUC32[destI++] = sourceDataUC32[srcI++];
  746. }
  747. break;
  748. #endif
  749. case OSG_FLOAT32_IMAGEDATA:
  750. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  751. {
  752. destDataF32[destI++] = sourceDataF32[srcI];
  753. destDataF32[destI++] = sourceDataF32[srcI];
  754. destDataF32[destI++] = sourceDataF32[srcI++];
  755. }
  756. break;
  757. #if !defined(OSG_EMBEDDED)
  758. case OSG_FLOAT16_IMAGEDATA:
  759. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  760. {
  761. destDataH16[destI++] = sourceDataH16[srcI];
  762. destDataH16[destI++] = sourceDataH16[srcI];
  763. destDataH16[destI++] = sourceDataH16[srcI++];
  764. }
  765. break;
  766. #endif
  767. default:
  768. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  769. break;
  770. }
  771. break;
  772. case OSG_RGBA_PF:
  773. switch (getDataType())
  774. {
  775. case OSG_UINT8_IMAGEDATA:
  776. for (srcI = destI = 0; destI < destSize;)
  777. {
  778. data[destI++] = sourceData[srcI];
  779. data[destI++] = sourceData[srcI];
  780. data[destI++] = sourceData[srcI];
  781. data[destI++] = sourceData[srcI++];
  782. }
  783. break;
  784. #if !defined(OSG_EMBEDDED)
  785. case OSG_UINT16_IMAGEDATA:
  786. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  787. {
  788. destDataUC16[destI++] = sourceDataUC16[srcI];
  789. destDataUC16[destI++] = sourceDataUC16[srcI];
  790. destDataUC16[destI++] = sourceDataUC16[srcI];
  791. destDataUC16[destI++] = sourceDataUC16[srcI++];
  792. }
  793. break;
  794. case OSG_UINT32_IMAGEDATA:
  795. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  796. {
  797. destDataUC32[destI++] = sourceDataUC32[srcI];
  798. destDataUC32[destI++] = sourceDataUC32[srcI];
  799. destDataUC32[destI++] = sourceDataUC32[srcI];
  800. destDataUC32[destI++] = sourceDataUC32[srcI++];
  801. }
  802. break;
  803. #endif
  804. case OSG_FLOAT32_IMAGEDATA:
  805. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  806. {
  807. destDataF32[destI++] = sourceDataF32[srcI];
  808. destDataF32[destI++] = sourceDataF32[srcI];
  809. destDataF32[destI++] = sourceDataF32[srcI];
  810. destDataF32[destI++] = sourceDataF32[srcI++];
  811. }
  812. break;
  813. #if !defined(OSG_EMBEDDED)
  814. case OSG_FLOAT16_IMAGEDATA:
  815. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  816. {
  817. destDataH16[destI++] = sourceDataH16[srcI];
  818. destDataH16[destI++] = sourceDataH16[srcI];
  819. destDataH16[destI++] = sourceDataH16[srcI];
  820. destDataH16[destI++] = sourceDataH16[srcI++];
  821. }
  822. break;
  823. #endif
  824. default:
  825. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  826. break;
  827. }
  828. break;
  829. default:
  830. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  831. break;
  832. }
  833. break;
  834. //-----------------------------------------------------
  835. #if !defined(OSG_EMBEDDED)
  836. case OSG_I_PF:
  837. switch (pixelFormat) {
  838. case OSG_A_PF:
  839. case OSG_I_PF:
  840. case OSG_L_PF:
  841. switch (getDataType())
  842. {
  843. case OSG_UINT8_IMAGEDATA:
  844. memcpy (data, getData(), destSize);
  845. break;
  846. case OSG_UINT16_IMAGEDATA:
  847. memcpy (data, getData(), destSize);
  848. break;
  849. case OSG_UINT32_IMAGEDATA:
  850. memcpy (data, getData(), destSize);
  851. break;
  852. case OSG_FLOAT32_IMAGEDATA:
  853. memcpy (data, getData(), destSize);
  854. break;
  855. case OSG_FLOAT16_IMAGEDATA:
  856. memcpy (data, getData(), destSize);
  857. break;
  858. default:
  859. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  860. break;
  861. }
  862. break;
  863. case OSG_LA_PF:
  864. switch (getDataType())
  865. {
  866. case OSG_UINT8_IMAGEDATA:
  867. for (srcI = destI = 0; destI < destSize;)
  868. {
  869. data[destI++] = sourceData[srcI];
  870. data[destI++] = sourceData[srcI++];
  871. }
  872. break;
  873. case OSG_UINT16_IMAGEDATA:
  874. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  875. {
  876. destDataUC16[destI++] = sourceDataUC16[srcI];
  877. destDataUC16[destI++] = sourceDataUC16[srcI++];
  878. }
  879. break;
  880. case OSG_UINT32_IMAGEDATA:
  881. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  882. {
  883. destDataUC32[destI++] = sourceDataUC32[srcI];
  884. destDataUC32[destI++] = sourceDataUC32[srcI++];
  885. }
  886. break;
  887. case OSG_FLOAT32_IMAGEDATA:
  888. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  889. {
  890. destDataF32[destI++] = sourceDataF32[srcI];
  891. destDataF32[destI++] = sourceDataF32[srcI++];
  892. }
  893. break;
  894. case OSG_FLOAT16_IMAGEDATA:
  895. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  896. {
  897. destDataH16[destI++] = sourceDataH16[srcI];
  898. destDataH16[destI++] = sourceDataH16[srcI++];
  899. }
  900. break;
  901. default:
  902. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  903. break;
  904. }
  905. break;
  906. case OSG_RGB_PF:
  907. switch (getDataType())
  908. {
  909. case OSG_UINT8_IMAGEDATA:
  910. for (srcI = destI = 0; destI < destSize;)
  911. {
  912. data[destI++] = sourceData[srcI];
  913. data[destI++] = sourceData[srcI];
  914. data[destI++] = sourceData[srcI++];
  915. }
  916. break;
  917. case OSG_UINT16_IMAGEDATA:
  918. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  919. {
  920. destDataUC16[destI++] = sourceDataUC16[srcI];
  921. destDataUC16[destI++] = sourceDataUC16[srcI];
  922. destDataUC16[destI++] = sourceDataUC16[srcI++];
  923. }
  924. break;
  925. case OSG_UINT32_IMAGEDATA:
  926. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  927. {
  928. destDataUC32[destI++] = sourceDataUC32[srcI];
  929. destDataUC32[destI++] = sourceDataUC32[srcI];
  930. destDataUC32[destI++] = sourceDataUC32[srcI++];
  931. }
  932. break;
  933. case OSG_FLOAT32_IMAGEDATA:
  934. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  935. {
  936. destDataF32[destI++] = sourceDataF32[srcI];
  937. destDataF32[destI++] = sourceDataF32[srcI];
  938. destDataF32[destI++] = sourceDataF32[srcI++];
  939. }
  940. break;
  941. case OSG_FLOAT16_IMAGEDATA:
  942. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  943. {
  944. destDataH16[destI++] = sourceDataH16[srcI];
  945. destDataH16[destI++] = sourceDataH16[srcI];
  946. destDataH16[destI++] = sourceDataH16[srcI++];
  947. }
  948. break;
  949. default:
  950. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  951. break;
  952. }
  953. break;
  954. case OSG_RGBA_PF:
  955. switch (getDataType())
  956. {
  957. case OSG_UINT8_IMAGEDATA:
  958. for (srcI = destI = 0; destI < destSize;)
  959. {
  960. data[destI++] = sourceData[srcI];
  961. data[destI++] = sourceData[srcI];
  962. data[destI++] = sourceData[srcI];
  963. data[destI++] = sourceData[srcI++];
  964. }
  965. break;
  966. case OSG_UINT16_IMAGEDATA:
  967. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  968. {
  969. destDataUC16[destI++] = sourceDataUC16[srcI];
  970. destDataUC16[destI++] = sourceDataUC16[srcI];
  971. destDataUC16[destI++] = sourceDataUC16[srcI];
  972. destDataUC16[destI++] = sourceDataUC16[srcI++];
  973. }
  974. break;
  975. case OSG_UINT32_IMAGEDATA:
  976. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  977. {
  978. destDataUC32[destI++] = sourceDataUC32[srcI];
  979. destDataUC32[destI++] = sourceDataUC32[srcI];
  980. destDataUC32[destI++] = sourceDataUC32[srcI];
  981. destDataUC32[destI++] = sourceDataUC32[srcI++];
  982. }
  983. break;
  984. case OSG_FLOAT32_IMAGEDATA:
  985. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  986. {
  987. destDataF32[destI++] = sourceDataF32[srcI];
  988. destDataF32[destI++] = sourceDataF32[srcI];
  989. destDataF32[destI++] = sourceDataF32[srcI];
  990. destDataF32[destI++] = sourceDataF32[srcI++];
  991. }
  992. break;
  993. case OSG_FLOAT16_IMAGEDATA:
  994. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  995. {
  996. destDataH16[destI++] = sourceDataH16[srcI];
  997. destDataH16[destI++] = sourceDataH16[srcI];
  998. destDataH16[destI++] = sourceDataH16[srcI];
  999. destDataH16[destI++] = sourceDataH16[srcI++];
  1000. }
  1001. break;
  1002. default:
  1003. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1004. break;
  1005. }
  1006. break;
  1007. default:
  1008. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1009. break;
  1010. }
  1011. break;
  1012. #endif
  1013. //-----------------------------------------------------
  1014. case OSG_L_PF:
  1015. switch (pixelFormat) {
  1016. case OSG_A_PF:
  1017. #if !defined(OSG_EMBEDDED)
  1018. case OSG_I_PF:
  1019. #endif
  1020. case OSG_L_PF:
  1021. switch (getDataType())
  1022. {
  1023. case OSG_UINT8_IMAGEDATA:
  1024. memcpy (data, getData(), destSize);
  1025. break;
  1026. #if !defined(OSG_EMBEDDED)
  1027. case OSG_UINT16_IMAGEDATA:
  1028. memcpy (data, getData(), destSize);
  1029. break;
  1030. case OSG_UINT32_IMAGEDATA:
  1031. memcpy (data, getData(), destSize);
  1032. break;
  1033. #endif
  1034. case OSG_FLOAT32_IMAGEDATA:
  1035. memcpy (data, getData(), destSize);
  1036. break;
  1037. #if !defined(OSG_EMBEDDED)
  1038. case OSG_FLOAT16_IMAGEDATA:
  1039. memcpy (data, getData(), destSize);
  1040. break;
  1041. #endif
  1042. default:
  1043. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1044. break;
  1045. }
  1046. break;
  1047. case OSG_LA_PF:
  1048. switch (getDataType())
  1049. {
  1050. case OSG_UINT8_IMAGEDATA:
  1051. for (srcI = destI = 0; destI < destSize;)
  1052. {
  1053. data[destI++] = sourceData[srcI];
  1054. data[destI++] = sourceData[srcI++];
  1055. }
  1056. break;
  1057. #if !defined(OSG_EMBEDDED)
  1058. case OSG_UINT16_IMAGEDATA:
  1059. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1060. {
  1061. destDataUC16[destI++] = sourceDataUC16[srcI];
  1062. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1063. }
  1064. break;
  1065. case OSG_UINT32_IMAGEDATA:
  1066. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1067. {
  1068. destDataUC32[destI++] = sourceDataUC32[srcI];
  1069. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1070. }
  1071. break;
  1072. #endif
  1073. case OSG_FLOAT32_IMAGEDATA:
  1074. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1075. {
  1076. destDataF32[destI++] = sourceDataF32[srcI];
  1077. destDataF32[destI++] = sourceDataF32[srcI++];
  1078. }
  1079. break;
  1080. #if !defined(OSG_EMBEDDED)
  1081. case OSG_FLOAT16_IMAGEDATA:
  1082. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1083. {
  1084. destDataH16[destI++] = sourceDataH16[srcI];
  1085. destDataH16[destI++] = sourceDataH16[srcI++];
  1086. }
  1087. break;
  1088. #endif
  1089. default:
  1090. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1091. break;
  1092. }
  1093. break;
  1094. case OSG_RGB_PF:
  1095. switch (getDataType())
  1096. {
  1097. case OSG_UINT8_IMAGEDATA:
  1098. for (srcI = destI = 0; destI < destSize;)
  1099. {
  1100. data[destI++] = sourceData[srcI];
  1101. data[destI++] = sourceData[srcI];
  1102. data[destI++] = sourceData[srcI++];
  1103. }
  1104. break;
  1105. #if !defined(OSG_EMBEDDED)
  1106. case OSG_UINT16_IMAGEDATA:
  1107. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1108. {
  1109. destDataUC16[destI++] = sourceDataUC16[srcI];
  1110. destDataUC16[destI++] = sourceDataUC16[srcI];
  1111. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1112. }
  1113. break;
  1114. case OSG_UINT32_IMAGEDATA:
  1115. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1116. {
  1117. destDataUC32[destI++] = sourceDataUC32[srcI];
  1118. destDataUC32[destI++] = sourceDataUC32[srcI];
  1119. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1120. }
  1121. break;
  1122. #endif
  1123. case OSG_FLOAT32_IMAGEDATA:
  1124. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1125. {
  1126. destDataF32[destI++] = sourceDataF32[srcI];
  1127. destDataF32[destI++] = sourceDataF32[srcI];
  1128. destDataF32[destI++] = sourceDataF32[srcI++];
  1129. }
  1130. break;
  1131. #if !defined(OSG_EMBEDDED)
  1132. case OSG_FLOAT16_IMAGEDATA:
  1133. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1134. {
  1135. destDataH16[destI++] = sourceDataH16[srcI];
  1136. destDataH16[destI++] = sourceDataH16[srcI];
  1137. destDataH16[destI++] = sourceDataH16[srcI++];
  1138. }
  1139. break;
  1140. #endif
  1141. default:
  1142. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1143. break;
  1144. }
  1145. break;
  1146. case OSG_RGBA_PF:
  1147. switch (getDataType())
  1148. {
  1149. case OSG_UINT8_IMAGEDATA:
  1150. for (srcI = destI = 0; destI < destSize;)
  1151. {
  1152. data[destI++] = sourceData[srcI];
  1153. data[destI++] = sourceData[srcI];
  1154. data[destI++] = sourceData[srcI];
  1155. data[destI++] = sourceData[srcI++];
  1156. }
  1157. break;
  1158. #if !defined(OSG_EMBEDDED)
  1159. case OSG_UINT16_IMAGEDATA:
  1160. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1161. {
  1162. destDataUC16[destI++] = sourceDataUC16[srcI];
  1163. destDataUC16[destI++] = sourceDataUC16[srcI];
  1164. destDataUC16[destI++] = sourceDataUC16[srcI];
  1165. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1166. }
  1167. break;
  1168. case OSG_UINT32_IMAGEDATA:
  1169. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1170. {
  1171. destDataUC32[destI++] = sourceDataUC32[srcI];
  1172. destDataUC32[destI++] = sourceDataUC32[srcI];
  1173. destDataUC32[destI++] = sourceDataUC32[srcI];
  1174. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1175. }
  1176. break;
  1177. #endif
  1178. case OSG_FLOAT32_IMAGEDATA:
  1179. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1180. {
  1181. destDataF32[destI++] = sourceDataF32[srcI];
  1182. destDataF32[destI++] = sourceDataF32[srcI];
  1183. destDataF32[destI++] = sourceDataF32[srcI];
  1184. destDataF32[destI++] = sourceDataF32[srcI++];
  1185. }
  1186. break;
  1187. #if !defined(OSG_EMBEDDED)
  1188. case OSG_FLOAT16_IMAGEDATA:
  1189. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1190. {
  1191. destDataH16[destI++] = sourceDataH16[srcI];
  1192. destDataH16[destI++] = sourceDataH16[srcI];
  1193. destDataH16[destI++] = sourceDataH16[srcI];
  1194. destDataH16[destI++] = sourceDataH16[srcI++];
  1195. }
  1196. break;
  1197. #endif
  1198. default:
  1199. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1200. break;
  1201. }
  1202. break;
  1203. default:
  1204. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1205. break;
  1206. }
  1207. break;
  1208. //-----------------------------------------------------
  1209. case OSG_LA_PF:
  1210. switch (pixelFormat) {
  1211. case OSG_A_PF:
  1212. switch (getDataType())
  1213. {
  1214. case OSG_UINT8_IMAGEDATA:
  1215. for (srcI = destI = 0; destI < destSize;)
  1216. {
  1217. srcI++;
  1218. data[destI++] = sourceData[srcI++];
  1219. }
  1220. break;
  1221. #if !defined(OSG_EMBEDDED)
  1222. case OSG_UINT16_IMAGEDATA:
  1223. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1224. {
  1225. srcI++;
  1226. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1227. }
  1228. break;
  1229. case OSG_UINT32_IMAGEDATA:
  1230. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1231. {
  1232. srcI++;
  1233. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1234. }
  1235. break;
  1236. #endif
  1237. case OSG_FLOAT32_IMAGEDATA:
  1238. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1239. {
  1240. srcI++;
  1241. destDataF32[destI++] = sourceDataF32[srcI++];
  1242. }
  1243. break;
  1244. #if !defined(OSG_EMBEDDED)
  1245. case OSG_FLOAT16_IMAGEDATA:
  1246. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1247. {
  1248. srcI++;
  1249. destDataH16[destI++] = sourceDataH16[srcI++];
  1250. }
  1251. break;
  1252. #endif
  1253. default:
  1254. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1255. break;
  1256. }
  1257. break;
  1258. #if !defined(OSG_EMBEDDED)
  1259. case OSG_I_PF:
  1260. #endif
  1261. case OSG_L_PF:
  1262. switch (getDataType())
  1263. {
  1264. case OSG_UINT8_IMAGEDATA:
  1265. for (srcI = destI = 0; destI < destSize;)
  1266. {
  1267. data[destI++] = sourceData[srcI++];
  1268. srcI++;
  1269. }
  1270. break;
  1271. #if !defined(OSG_EMBEDDED)
  1272. case OSG_UINT16_IMAGEDATA:
  1273. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1274. {
  1275. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1276. srcI++;
  1277. }
  1278. break;
  1279. case OSG_UINT32_IMAGEDATA:
  1280. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1281. {
  1282. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1283. srcI++;
  1284. }
  1285. break;
  1286. #endif
  1287. case OSG_FLOAT32_IMAGEDATA:
  1288. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1289. {
  1290. destDataF32[destI++] = sourceDataF32[srcI++];
  1291. srcI++;
  1292. }
  1293. break;
  1294. #if !defined(OSG_EMBEDDED)
  1295. case OSG_FLOAT16_IMAGEDATA:
  1296. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1297. {
  1298. destDataH16[destI++] = sourceDataH16[srcI++];
  1299. srcI++;
  1300. }
  1301. break;
  1302. #endif
  1303. default:
  1304. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1305. break;
  1306. }
  1307. break;
  1308. case OSG_LA_PF:
  1309. switch (getDataType())
  1310. {
  1311. case OSG_UINT8_IMAGEDATA:
  1312. memcpy (data, getData(), destSize);
  1313. break;
  1314. #if !defined(OSG_EMBEDDED)
  1315. case OSG_UINT16_IMAGEDATA:
  1316. memcpy (data, getData(), destSize);
  1317. break;
  1318. case OSG_UINT32_IMAGEDATA:
  1319. memcpy (data, getData(), destSize);
  1320. break;
  1321. #endif
  1322. case OSG_FLOAT32_IMAGEDATA:
  1323. memcpy (data, getData(), destSize);
  1324. break;
  1325. #if !defined(OSG_EMBEDDED)
  1326. case OSG_FLOAT16_IMAGEDATA:
  1327. memcpy (data, getData(), destSize);
  1328. break;
  1329. #endif
  1330. default:
  1331. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1332. break;
  1333. }
  1334. break;
  1335. case OSG_RGB_PF:
  1336. switch (getDataType())
  1337. {
  1338. case OSG_UINT8_IMAGEDATA:
  1339. for (srcI = destI = 0; destI < destSize;)
  1340. {
  1341. data[destI++] = sourceData[srcI];
  1342. data[destI++] = sourceData[srcI];
  1343. data[destI++] = sourceData[srcI++];
  1344. srcI++;
  1345. }
  1346. break;
  1347. #if !defined(OSG_EMBEDDED)
  1348. case OSG_UINT16_IMAGEDATA:
  1349. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1350. {
  1351. destDataUC16[destI++] = sourceDataUC16[srcI];
  1352. destDataUC16[destI++] = sourceDataUC16[srcI];
  1353. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1354. srcI++;
  1355. }
  1356. break;
  1357. case OSG_UINT32_IMAGEDATA:
  1358. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1359. {
  1360. destDataUC32[destI++] = sourceDataUC32[srcI];
  1361. destDataUC32[destI++] = sourceDataUC32[srcI];
  1362. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1363. srcI++;
  1364. }
  1365. break;
  1366. #endif
  1367. case OSG_FLOAT32_IMAGEDATA:
  1368. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1369. {
  1370. destDataF32[destI++] = sourceDataF32[srcI];
  1371. destDataF32[destI++] = sourceDataF32[srcI];
  1372. destDataF32[destI++] = sourceDataF32[srcI++];
  1373. srcI++;
  1374. }
  1375. break;
  1376. #if !defined(OSG_EMBEDDED)
  1377. case OSG_FLOAT16_IMAGEDATA:
  1378. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1379. {
  1380. destDataH16[destI++] = sourceDataH16[srcI];
  1381. destDataH16[destI++] = sourceDataH16[srcI];
  1382. destDataH16[destI++] = sourceDataH16[srcI++];
  1383. srcI++;
  1384. }
  1385. break;
  1386. #endif
  1387. default:
  1388. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1389. break;
  1390. }
  1391. break;
  1392. case OSG_RGBA_PF:
  1393. switch (getDataType())
  1394. {
  1395. case OSG_UINT8_IMAGEDATA:
  1396. for (srcI = destI = 0; destI < destSize;)
  1397. {
  1398. data[destI++] = sourceData[srcI];
  1399. data[destI++] = sourceData[srcI];
  1400. data[destI++] = sourceData[srcI++];
  1401. data[destI++] = sourceData[srcI++];
  1402. }
  1403. break;
  1404. #if !defined(OSG_EMBEDDED)
  1405. case OSG_UINT16_IMAGEDATA:
  1406. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1407. {
  1408. destDataUC16[destI++] = sourceDataUC16[srcI];
  1409. destDataUC16[destI++] = sourceDataUC16[srcI];
  1410. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1411. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1412. }
  1413. break;
  1414. case OSG_UINT32_IMAGEDATA:
  1415. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1416. {
  1417. destDataUC32[destI++] = sourceDataUC32[srcI];
  1418. destDataUC32[destI++] = sourceDataUC32[srcI];
  1419. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1420. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1421. }
  1422. break;
  1423. #endif
  1424. case OSG_FLOAT32_IMAGEDATA:
  1425. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1426. {
  1427. destDataF32[destI++] = sourceDataF32[srcI];
  1428. destDataF32[destI++] = sourceDataF32[srcI];
  1429. destDataF32[destI++] = sourceDataF32[srcI++];
  1430. destDataF32[destI++] = sourceDataF32[srcI++];
  1431. }
  1432. break;
  1433. #if !defined(OSG_EMBEDDED)
  1434. case OSG_FLOAT16_IMAGEDATA:
  1435. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1436. {
  1437. destDataH16[destI++] = sourceDataH16[srcI];
  1438. destDataH16[destI++] = sourceDataH16[srcI];
  1439. destDataH16[destI++] = sourceDataH16[srcI++];
  1440. destDataH16[destI++] = sourceDataH16[srcI++];
  1441. }
  1442. break;
  1443. #endif
  1444. default:
  1445. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1446. break;
  1447. }
  1448. break;
  1449. default:
  1450. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1451. break;
  1452. }
  1453. break;
  1454. //-----------------------------------------------------
  1455. case OSG_RGB_PF:
  1456. switch (pixelFormat) {
  1457. case OSG_A_PF:
  1458. #if !defined(OSG_EMBEDDED)
  1459. case OSG_I_PF:
  1460. #endif
  1461. case OSG_L_PF:
  1462. switch (getDataType())
  1463. {
  1464. case OSG_UINT8_IMAGEDATA:
  1465. for (srcI = destI = 0; destI < destSize;)
  1466. {
  1467. sum = 0;
  1468. sum += sourceData[srcI++];
  1469. sum += sourceData[srcI++];
  1470. sum += sourceData[srcI++];
  1471. data[destI++] = sum / 3;
  1472. }
  1473. break;
  1474. #if !defined(OSG_EMBEDDED)
  1475. case OSG_UINT16_IMAGEDATA:
  1476. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1477. {
  1478. sum = 0;
  1479. sum += sourceDataUC16[srcI++];
  1480. sum += sourceDataUC16[srcI++];
  1481. sum += sourceDataUC16[srcI++];
  1482. destDataUC16[destI++] = sum / 3;
  1483. }
  1484. break;
  1485. case OSG_UINT32_IMAGEDATA:
  1486. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1487. {
  1488. sum = 0;
  1489. sum += sourceDataUC32[srcI++];
  1490. sum += sourceDataUC32[srcI++];
  1491. sum += sourceDataUC32[srcI++];
  1492. destDataUC32[destI++] = sum / 3;
  1493. }
  1494. break;
  1495. #endif
  1496. case OSG_FLOAT32_IMAGEDATA:
  1497. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1498. {
  1499. sumReal = 0;
  1500. sumReal += sourceDataF32[srcI++];
  1501. sumReal += sourceDataF32[srcI++];
  1502. sumReal += sourceDataF32[srcI++];
  1503. destDataF32[destI++] = sumReal / 3.0;
  1504. }
  1505. break;
  1506. #if !defined(OSG_EMBEDDED)
  1507. case OSG_FLOAT16_IMAGEDATA:
  1508. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1509. {
  1510. sumReal = 0;
  1511. sumReal += sourceDataH16[srcI++];
  1512. sumReal += sourceDataH16[srcI++];
  1513. sumReal += sourceDataH16[srcI++];
  1514. destDataH16[destI++] = sumReal / 3.0;
  1515. }
  1516. break;
  1517. #endif
  1518. default:
  1519. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1520. break;
  1521. }
  1522. break;
  1523. case OSG_LA_PF:
  1524. switch (getDataType())
  1525. {
  1526. case OSG_UINT8_IMAGEDATA:
  1527. for (srcI = destI = 0; destI < destSize;)
  1528. {
  1529. sum = 0;
  1530. sum += sourceData[srcI++];
  1531. sum += sourceData[srcI++];
  1532. sum += sourceData[srcI++];
  1533. data[destI++] = sum / 3;
  1534. data[destI++] = sum / 3;
  1535. }
  1536. break;
  1537. #if !defined(OSG_EMBEDDED)
  1538. case OSG_UINT16_IMAGEDATA:
  1539. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1540. {
  1541. sum = 0;
  1542. sum += sourceDataUC16[srcI++];
  1543. sum += sourceDataUC16[srcI++];
  1544. sum += sourceDataUC16[srcI++];
  1545. destDataUC16[destI++] = sum / 3;
  1546. destDataUC16[destI++] = sum / 3;
  1547. }
  1548. break;
  1549. case OSG_UINT32_IMAGEDATA:
  1550. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1551. {
  1552. sum = 0;
  1553. sum += sourceDataUC32[srcI++];
  1554. sum += sourceDataUC32[srcI++];
  1555. sum += sourceDataUC32[srcI++];
  1556. destDataUC32[destI++] = sum / 3;
  1557. destDataUC32[destI++] = sum / 3;
  1558. }
  1559. break;
  1560. #endif
  1561. case OSG_FLOAT32_IMAGEDATA:
  1562. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1563. {
  1564. sumReal = 0;
  1565. sumReal += sourceDataF32[srcI++];
  1566. sumReal += sourceDataF32[srcI++];
  1567. sumReal += sourceDataF32[srcI++];
  1568. destDataF32[destI++] = sumReal / 3.0;
  1569. destDataF32[destI++] = sumReal / 3.0;
  1570. }
  1571. break;
  1572. #if !defined(OSG_EMBEDDED)
  1573. case OSG_FLOAT16_IMAGEDATA:
  1574. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1575. {
  1576. sumReal = 0;
  1577. sumReal += sourceDataH16[srcI++];
  1578. sumReal += sourceDataH16[srcI++];
  1579. sumReal += sourceDataH16[srcI++];
  1580. destDataH16[destI++] = sumReal / 3.0;
  1581. destDataH16[destI++] = sumReal / 3.0;
  1582. }
  1583. break;
  1584. #endif
  1585. default:
  1586. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1587. break;
  1588. }
  1589. break;
  1590. case OSG_RGB_PF:
  1591. switch (getDataType())
  1592. {
  1593. case OSG_UINT8_IMAGEDATA:
  1594. memcpy (data, getData(), destSize);
  1595. break;
  1596. #if !defined(OSG_EMBEDDED)
  1597. case OSG_UINT16_IMAGEDATA:
  1598. memcpy (data, getData(), destSize);
  1599. break;
  1600. case OSG_UINT32_IMAGEDATA:
  1601. memcpy (data, getData(), destSize);
  1602. break;
  1603. #endif
  1604. case OSG_FLOAT32_IMAGEDATA:
  1605. memcpy (data, getData(), destSize);
  1606. break;
  1607. #if !defined(OSG_EMBEDDED)
  1608. case OSG_FLOAT16_IMAGEDATA:
  1609. memcpy (data, getData(), destSize);
  1610. break;
  1611. #endif
  1612. default:
  1613. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1614. break;
  1615. }
  1616. break;
  1617. case OSG_RGBA_PF:
  1618. switch (getDataType())
  1619. {
  1620. case OSG_UINT8_IMAGEDATA:
  1621. for (srcI = destI = 0; destI < destSize;)
  1622. {
  1623. sum = 0;
  1624. sum += data[destI++] = sourceData[srcI++];
  1625. sum += data[destI++] = sourceData[srcI++];
  1626. sum += data[destI++] = sourceData[srcI++];
  1627. data[destI++] = sum / 3;
  1628. }
  1629. break;
  1630. #if !defined(OSG_EMBEDDED)
  1631. case OSG_UINT16_IMAGEDATA:
  1632. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1633. {
  1634. sum = 0;
  1635. sum += destDataUC16[destI++] = sourceDataUC16[srcI++];
  1636. sum += destDataUC16[destI++] = sourceDataUC16[srcI++];
  1637. sum += destDataUC16[destI++] = sourceDataUC16[srcI++];
  1638. destDataUC16[destI++] = sum / 3;
  1639. }
  1640. break;
  1641. case OSG_UINT32_IMAGEDATA:
  1642. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1643. {
  1644. sum = 0;
  1645. sum += destDataUC32[destI++] = sourceDataUC32[srcI++];
  1646. sum += destDataUC32[destI++] = sourceDataUC32[srcI++];
  1647. sum += destDataUC32[destI++] = sourceDataUC32[srcI++];
  1648. destDataUC32[destI++] = sum / 3;
  1649. }
  1650. break;
  1651. #endif
  1652. case OSG_FLOAT32_IMAGEDATA:
  1653. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1654. {
  1655. sumReal = 0;
  1656. sumReal += destDataF32[destI++] = sourceDataF32[srcI++];
  1657. sumReal += destDataF32[destI++] = sourceDataF32[srcI++];
  1658. sumReal += destDataF32[destI++] = sourceDataF32[srcI++];
  1659. destDataF32[destI++] = sumReal / 3.0;
  1660. }
  1661. break;
  1662. #if !defined(OSG_EMBEDDED)
  1663. case OSG_FLOAT16_IMAGEDATA:
  1664. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1665. {
  1666. sumReal = 0;
  1667. sumReal += destDataH16[destI++] = sourceDataH16[srcI++];
  1668. sumReal += destDataH16[destI++] = sourceDataH16[srcI++];
  1669. sumReal += destDataH16[destI++] = sourceDataH16[srcI++];
  1670. destDataH16[destI++] = sumReal / 3.0;
  1671. }
  1672. break;
  1673. #endif
  1674. default:
  1675. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1676. break;
  1677. }
  1678. break;
  1679. default:
  1680. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1681. break;
  1682. }
  1683. break;
  1684. //-----------------------------------------------------
  1685. case OSG_RGBA_PF:
  1686. switch (pixelFormat) {
  1687. case OSG_A_PF:
  1688. switch (getDataType())
  1689. {
  1690. case OSG_UINT8_IMAGEDATA:
  1691. for (srcI = destI = 0; destI < destSize;)
  1692. {
  1693. srcI += 3;
  1694. data[destI++] = sourceData[srcI++];;
  1695. }
  1696. break;
  1697. #if !defined(OSG_EMBEDDED)
  1698. case OSG_UINT16_IMAGEDATA:
  1699. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1700. {
  1701. srcI += 3;
  1702. destDataUC16[destI++] = sourceDataUC16[srcI++];;
  1703. }
  1704. break;
  1705. case OSG_UINT32_IMAGEDATA:
  1706. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1707. {
  1708. srcI += 3;
  1709. destDataUC32[destI++] = sourceDataUC32[srcI++];;
  1710. }
  1711. break;
  1712. #endif
  1713. case OSG_FLOAT32_IMAGEDATA:
  1714. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1715. {
  1716. srcI += 3;
  1717. destDataF32[destI++] = sourceDataF32[srcI++];
  1718. }
  1719. break;
  1720. #if !defined(OSG_EMBEDDED)
  1721. case OSG_FLOAT16_IMAGEDATA:
  1722. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1723. {
  1724. srcI += 3;
  1725. destDataH16[destI++] = sourceDataH16[srcI++];
  1726. }
  1727. break;
  1728. #endif
  1729. default:
  1730. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1731. break;
  1732. }
  1733. break;
  1734. #if !defined(OSG_EMBEDDED)
  1735. case OSG_I_PF:
  1736. #endif
  1737. case OSG_L_PF:
  1738. switch (getDataType())
  1739. {
  1740. case OSG_UINT8_IMAGEDATA:
  1741. for (srcI = destI = 0; destI < destSize;)
  1742. {
  1743. sum = 0;
  1744. sum += sourceData[srcI++];
  1745. sum += sourceData[srcI++];
  1746. sum += sourceData[srcI++];
  1747. data[destI++] = sum / 3;
  1748. srcI++;
  1749. }
  1750. break;
  1751. #if !defined(OSG_EMBEDDED)
  1752. case OSG_UINT16_IMAGEDATA:
  1753. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1754. {
  1755. sum = 0;
  1756. sum += sourceDataUC16[srcI++];
  1757. sum += sourceDataUC16[srcI++];
  1758. sum += sourceDataUC16[srcI++];
  1759. destDataUC16[destI++] = sum / 3;
  1760. srcI++;
  1761. }
  1762. break;
  1763. case OSG_UINT32_IMAGEDATA:
  1764. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1765. {
  1766. sum = 0;
  1767. sum += sourceDataUC32[srcI++];
  1768. sum += sourceDataUC32[srcI++];
  1769. sum += sourceDataUC32[srcI++];
  1770. destDataUC32[destI++] = sum / 3;
  1771. srcI++;
  1772. }
  1773. break;
  1774. #endif
  1775. case OSG_FLOAT32_IMAGEDATA:
  1776. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1777. {
  1778. sumReal = 0;
  1779. sumReal += sourceDataF32[srcI++];
  1780. sumReal += sourceDataF32[srcI++];
  1781. sumReal += sourceDataF32[srcI++];
  1782. destDataF32[destI++] = sumReal / 3.0;
  1783. srcI++;
  1784. }
  1785. break;
  1786. #if !defined(OSG_EMBEDDED)
  1787. case OSG_FLOAT16_IMAGEDATA:
  1788. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1789. {
  1790. sumReal = 0;
  1791. sumReal += sourceDataH16[srcI++];
  1792. sumReal += sourceDataH16[srcI++];
  1793. sumReal += sourceDataH16[srcI++];
  1794. destDataH16[destI++] = sumReal / 3.0;
  1795. srcI++;
  1796. }
  1797. break;
  1798. #endif
  1799. default:
  1800. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1801. break;
  1802. }
  1803. break;
  1804. case OSG_LA_PF:
  1805. switch (getDataType())
  1806. {
  1807. case OSG_UINT8_IMAGEDATA:
  1808. for (srcI = destI = 0; destI < destSize;)
  1809. {
  1810. sum = 0;
  1811. sum += sourceData[srcI++];
  1812. sum += sourceData[srcI++];
  1813. sum += sourceData[srcI++];
  1814. data[destI++] = sum / 3;
  1815. data[destI++] = sourceData[srcI++];;
  1816. }
  1817. break;
  1818. #if !defined(OSG_EMBEDDED)
  1819. case OSG_UINT16_IMAGEDATA:
  1820. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1821. {
  1822. sum = 0;
  1823. sum += sourceDataUC16[srcI++];
  1824. sum += sourceDataUC16[srcI++];
  1825. sum += sourceDataUC16[srcI++];
  1826. destDataUC16[destI++] = sum / 3;
  1827. destDataUC16[destI++] = sourceDataUC16[srcI++];;
  1828. }
  1829. break;
  1830. case OSG_UINT32_IMAGEDATA:
  1831. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1832. {
  1833. sum = 0;
  1834. sum += sourceDataUC32[srcI++];
  1835. sum += sourceDataUC32[srcI++];
  1836. sum += sourceDataUC32[srcI++];
  1837. destDataUC32[destI++] = sum / 3;
  1838. destDataUC32[destI++] = sourceDataUC32[srcI++];;
  1839. }
  1840. break;
  1841. #endif
  1842. case OSG_FLOAT32_IMAGEDATA:
  1843. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1844. {
  1845. sumReal = 0;
  1846. sumReal += sourceDataF32[srcI++];
  1847. sumReal += sourceDataF32[srcI++];
  1848. sumReal += sourceDataF32[srcI++];
  1849. destDataF32[destI++] = sumReal / 3.0;
  1850. destDataF32[destI++] = sourceDataF32[srcI++];
  1851. }
  1852. break;
  1853. #if !defined(OSG_EMBEDDED)
  1854. case OSG_FLOAT16_IMAGEDATA:
  1855. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1856. {
  1857. sumReal = 0;
  1858. sumReal += sourceDataH16[srcI++];
  1859. sumReal += sourceDataH16[srcI++];
  1860. sumReal += sourceDataH16[srcI++];
  1861. destDataH16[destI++] = sumReal / 3.0;
  1862. destDataH16[destI++] = sourceDataH16[srcI++];
  1863. }
  1864. break;
  1865. #endif
  1866. default:
  1867. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1868. break;
  1869. }
  1870. break;
  1871. case OSG_RGB_PF:
  1872. switch (getDataType())
  1873. {
  1874. case OSG_UINT8_IMAGEDATA:
  1875. for (srcI = destI = 0; destI < destSize;)
  1876. {
  1877. data[destI++] = sourceData[srcI++];
  1878. data[destI++] = sourceData[srcI++];
  1879. data[destI++] = sourceData[srcI++];
  1880. srcI++;
  1881. }
  1882. break;
  1883. #if !defined(OSG_EMBEDDED)
  1884. case OSG_UINT16_IMAGEDATA:
  1885. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1886. {
  1887. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1888. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1889. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1890. srcI++;
  1891. }
  1892. break;
  1893. case OSG_UINT32_IMAGEDATA:
  1894. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1895. {
  1896. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1897. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1898. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1899. srcI++;
  1900. }
  1901. break;
  1902. #endif
  1903. case OSG_FLOAT32_IMAGEDATA:
  1904. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1905. {
  1906. destDataF32[destI++] = sourceDataF32[srcI++];
  1907. destDataF32[destI++] = sourceDataF32[srcI++];
  1908. destDataF32[destI++] = sourceDataF32[srcI++];
  1909. srcI++;
  1910. }
  1911. break;
  1912. #if !defined(OSG_EMBEDDED)
  1913. case OSG_FLOAT16_IMAGEDATA:
  1914. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1915. {
  1916. destDataH16[destI++] = sourceDataH16[srcI++];
  1917. destDataH16[destI++] = sourceDataH16[srcI++];
  1918. destDataH16[destI++] = sourceDataH16[srcI++];
  1919. srcI++;
  1920. }
  1921. break;
  1922. #endif
  1923. default:
  1924. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1925. break;
  1926. }
  1927. break;
  1928. case OSG_RGBA_PF:
  1929. switch (getDataType())
  1930. {
  1931. case OSG_UINT8_IMAGEDATA:
  1932. memcpy (data, getData(), destSize);
  1933. break;
  1934. #if !defined(OSG_EMBEDDED)
  1935. case OSG_UINT16_IMAGEDATA:
  1936. memcpy (data, getData(), destSize);
  1937. break;
  1938. case OSG_UINT32_IMAGEDATA:
  1939. memcpy (data, getData(), destSize);
  1940. break;
  1941. #endif
  1942. case OSG_FLOAT32_IMAGEDATA:
  1943. memcpy (data, getData(), destSize);
  1944. break;
  1945. #if !defined(OSG_EMBEDDED)
  1946. case OSG_FLOAT16_IMAGEDATA:
  1947. memcpy (data, getData(), destSize);
  1948. break;
  1949. #endif
  1950. default:
  1951. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1952. break;
  1953. }
  1954. break;
  1955. default:
  1956. break;
  1957. }
  1958. break;
  1959. default:
  1960. FWARNING (( "Unvalid pixeldepth (%d) in reformat() !\n",
  1961. pixelFormat ));
  1962. }
  1963. }
  1964. if (data)
  1965. {
  1966. // rip the data from the local destImage if necessary
  1967. if(destination == NullFC)
  1968. {
  1969. this->set(dest);
  1970. subRef(dest);
  1971. }
  1972. }
  1973. }
  1974. return (data ? true : false);
  1975. }
  1976. void Image::swapDataEndian(void)
  1977. {
  1978. UChar8 *data = editData();
  1979. UInt32 size = getSize() / getComponentSize();
  1980. UInt16 *dataUC16 = (UInt16 *) data;
  1981. UInt32 *dataUC32 = (UInt32 *) data;
  1982. Real32 *dataF32 = (Real32 *) data;
  1983. switch (getDataType())
  1984. {
  1985. case OSG_UINT8_IMAGEDATA:
  1986. // do nothing
  1987. break;
  1988. #if !defined(OSG_EMBEDDED)
  1989. case OSG_UINT16_IMAGEDATA:
  1990. for(UInt32 i=0;i<size;++i)
  1991. {
  1992. UInt16 p = dataUC16[i];
  1993. dataUC16[i] = (((p >> 8)) | (p << 8));
  1994. }
  1995. break;
  1996. case OSG_UINT32_IMAGEDATA:
  1997. for(UInt32 i=0;i<size;++i)
  1998. {
  1999. UInt32 p = dataUC32[i];
  2000. dataUC32[i] =
  2001. (((p & 0x000000FF) << 24) | ((p & 0x0000FF00) << 8) |
  2002. ((p & 0x00FF0000) >> 8) | ((p & 0xFF000000) >> 24) );
  2003. }
  2004. break;
  2005. #endif
  2006. case OSG_FLOAT32_IMAGEDATA:
  2007. for(UInt32 i=0;i<size;++i)
  2008. {
  2009. Real32 p = dataF32[i];
  2010. UInt8 *b = (UInt8 *) &p;
  2011. std::swap(b[0], b[3]);
  2012. std::swap(b[1], b[2]);
  2013. dataF32[i] = p;
  2014. }
  2015. break;
  2016. default:
  2017. FWARNING (( "invalid source data type \n"));
  2018. break;
  2019. }
  2020. }
  2021. /*! It is a simple method to convert the image dataType. Does not change
  2022. the pixelFormat. So you can for example convert a image consisting of
  2023. UChar8 data to Float data.
  2024. */
  2025. bool Image::convertDataTypeTo(Int32 destDataType)
  2026. {
  2027. if (hasCompressedData())
  2028. {
  2029. FFATAL (("Invalid Image::convertDataTypeTo for compressed image\n"));
  2030. return false;
  2031. }
  2032. if(destDataType == getDataType())
  2033. {
  2034. FWARNING (( "source image and destination image have same data "
  2035. "types: no conversion possible"));
  2036. return true;
  2037. }
  2038. FINFO(("Try to convert image from dataType %d to %d\n",
  2039. getDataType(), destDataType));
  2040. ImagePtr dest;
  2041. dest = Image::create();
  2042. addRef(dest);
  2043. dest->set(getPixelFormat(),
  2044. getWidth (),
  2045. getHeight (),
  2046. getDepth (),
  2047. getMipMapCount(),
  2048. getFrameCount (),
  2049. 0.0,
  2050. 0,
  2051. destDataType,
  2052. true,
  2053. getSideCount() );
  2054. const UChar8 *sourceData = getData();
  2055. UChar8 *destData = dest->editData();
  2056. Int32 sourceSize = getSize() / getComponentSize();
  2057. Int32 destSize = dest->getSize() / dest->getComponentSize();
  2058. const UInt16 *sourceDataUC16 = (const UInt16 *) sourceData;
  2059. UInt16 *destDataUC16 = ( UInt16 *) destData;
  2060. const UInt32 *sourceDataUC32 = (const UInt32 *) sourceData;
  2061. UInt32 *destDataUC32 = ( UInt32 *) destData;
  2062. const Real32 *sourceDataF32 = (const Real32 *) sourceData;
  2063. Real32 *destDataF32 = ( Real32 *) destData;
  2064. const Real16 *sourceDataH16 = (const Real16 *) sourceData;
  2065. Real16 *destDataH16 = ( Real16 *) destData;
  2066. switch (getDataType())
  2067. {
  2068. case OSG_UINT8_IMAGEDATA:
  2069. switch (destDataType)
  2070. {
  2071. #if !defined(OSG_EMBEDDED)
  2072. case OSG_UINT16_IMAGEDATA:
  2073. for (int i = 0; i < sourceSize; i++)
  2074. {
  2075. destDataUC16[i] = (UInt16) (sourceData[i]<<8);
  2076. }
  2077. break;
  2078. case OSG_UINT32_IMAGEDATA:
  2079. for (int i = 0; i < sourceSize; i++)
  2080. {
  2081. destDataUC32[i] = (UInt32) (sourceData[i]<<24);
  2082. }
  2083. break;
  2084. #endif
  2085. case OSG_FLOAT32_IMAGEDATA:
  2086. for (int i = 0; i < sourceSize; i++)
  2087. {
  2088. destDataF32[i] = (Real32) (sourceData[i]/255.0);
  2089. }
  2090. break;
  2091. #if !defined(OSG_EMBEDDED)
  2092. case OSG_FLOAT16_IMAGEDATA:
  2093. for (int i = 0; i < sourceSize; i++)
  2094. {
  2095. destDataH16[i] = (Real16) (sourceData[i]/255.0);
  2096. }
  2097. break;
  2098. #endif
  2099. default:
  2100. FWARNING (( "invalid destination data type \n" ));
  2101. break;
  2102. }
  2103. break;
  2104. #if !defined(OSG_EMBEDDED)
  2105. case OSG_UINT16_IMAGEDATA:
  2106. switch (destDataType)
  2107. {
  2108. case OSG_UINT8_IMAGEDATA:
  2109. {
  2110. UInt16 nMin = (UInt16) 65535;
  2111. UInt16 nMax = (UInt16) 0;
  2112. for (UInt32 i = 0; i < sourceSize; ++i)
  2113. {
  2114. if(sourceDataUC16[i] > nMax)
  2115. nMax = sourceDataUC16[i];
  2116. if(sourceDataUC16[i] < nMin)
  2117. nMin = sourceDataUC16[i];
  2118. }
  2119. Real32 fRange = (Real32) nMax - nMin;
  2120. if (fRange <= 0.0)
  2121. {
  2122. for(UInt32 i = 0; i < sourceSize; ++i)
  2123. destData[i] = 0;
  2124. }
  2125. else
  2126. {
  2127. for(UInt32 i = 0; i < sourceSize; ++i)
  2128. {
  2129. destData[i] = (UInt8)
  2130. (255.0 *
  2131. ((Real32) (sourceDataUC16[i] - nMin)) /
  2132. fRange) ;
  2133. }
  2134. }
  2135. }
  2136. break;
  2137. #if !defined(OSG_EMBEDDED)
  2138. case OSG_UINT32_IMAGEDATA:
  2139. for (int i = 0; i < sourceSize; i++)
  2140. {
  2141. destDataUC32[i] = (UInt32) (sourceDataUC16[i]<<16);
  2142. }
  2143. break;
  2144. #endif
  2145. case OSG_FLOAT32_IMAGEDATA:
  2146. for (int i = 0; i < sourceSize; i++)
  2147. {
  2148. destDataF32[i] = (Real32) (sourceDataUC16[i]/65535.0);
  2149. }
  2150. break;
  2151. #if !defined(OSG_EMBEDDED)
  2152. case OSG_FLOAT16_IMAGEDATA:
  2153. for (int i = 0; i < sourceSize; i++)
  2154. {
  2155. destDataH16[i] = (Real16) (sourceDataUC16[i]/255.0);
  2156. }
  2157. break;
  2158. #endif
  2159. default:
  2160. FWARNING (( "invalid destination data type \n" ));
  2161. break;
  2162. }
  2163. break;
  2164. #endif
  2165. #if !defined(OSG_EMBEDDED)
  2166. case OSG_UINT32_IMAGEDATA:
  2167. switch (destDataType)
  2168. {
  2169. case OSG_UINT8_IMAGEDATA:
  2170. {
  2171. UInt32 nMin = (UInt32) 4294967295ul;
  2172. UInt32 nMax = (UInt32) 0;
  2173. for (UInt32 i = 0; i < sourceSize; ++i)
  2174. {
  2175. if(sourceDataUC32[i] > nMax)
  2176. nMax = sourceDataUC32[i];
  2177. if(sourceDataUC32[i] < nMin)
  2178. nMin = sourceDataUC32[i];
  2179. }
  2180. Real32 fRange = (Real32) nMax - nMin;
  2181. if (fRange <= 0.0)
  2182. {
  2183. for(UInt32 i = 0; i < sourceSize; ++i)
  2184. destData[i] = 0;
  2185. }
  2186. else
  2187. {
  2188. for(UInt32 i = 0; i < sourceSize; ++i)
  2189. {
  2190. destData[i] = (UInt8)
  2191. (255.0 *
  2192. ((Real32) (sourceDataUC32[i] - nMin)) /
  2193. fRange );
  2194. }
  2195. }
  2196. }
  2197. break;
  2198. case OSG_UINT16_IMAGEDATA:
  2199. {
  2200. UInt32 nMin = (UInt32) 4294967295ul;
  2201. UInt32 nMax = (UInt32) 0;
  2202. for(UInt32 i = 0; i < sourceSize; ++i)
  2203. {
  2204. if(sourceDataUC32[i] > nMax)
  2205. nMax = sourceDataUC32[i];
  2206. if(sourceDataUC32[i] < nMin)
  2207. nMin = sourceDataUC32[i];
  2208. }
  2209. Real32 fRange = (Real32) nMax - nMin;
  2210. if(fRange <= 0.0)
  2211. {
  2212. for(UInt32 i = 0; i < sourceSize; ++i)
  2213. destDataUC16[i] = 0;
  2214. }
  2215. else
  2216. {
  2217. for(UInt32 i = 0; i < sourceSize; ++i)
  2218. destDataUC16[i] = (UInt16)
  2219. (65535.0 *
  2220. ((Real32) (sourceDataUC32[i] - nMin)) /
  2221. fRange);
  2222. }
  2223. }
  2224. break;
  2225. case OSG_FLOAT32_IMAGEDATA:
  2226. for(int i = 0; i < sourceSize; i++)
  2227. {
  2228. destDataF32[i] =
  2229. ((Real32) sourceDataUC32[i]) / 4294967295.0;
  2230. }
  2231. break;
  2232. #if !defined(OSG_EMBEDDED)
  2233. case OSG_FLOAT16_IMAGEDATA:
  2234. for (int i = 0; i < sourceSize; i++)
  2235. {
  2236. destDataH16[i] =
  2237. ((Real16) sourceDataUC32[i]) / REAL16_MAX;
  2238. }
  2239. break;
  2240. #endif
  2241. default:
  2242. FWARNING(("invalid destination data type \n"));
  2243. break;
  2244. }
  2245. break;
  2246. #endif
  2247. case OSG_FLOAT32_IMAGEDATA:
  2248. switch(destDataType)
  2249. {
  2250. case OSG_UINT8_IMAGEDATA:
  2251. for(int i = 0; i < sourceSize; i++)
  2252. {
  2253. destData[i] = (UInt8) (sourceDataF32[i]*255.0);
  2254. }
  2255. break;
  2256. #if !defined(OSG_EMBEDDED)
  2257. case OSG_UINT16_IMAGEDATA:
  2258. for(int i = 0; i < sourceSize; i++)
  2259. {
  2260. destDataUC16[i] =
  2261. (UInt16) (sourceDataF32[i] * 65535.0);
  2262. }
  2263. break;
  2264. case OSG_UINT32_IMAGEDATA:
  2265. for(int i = 0; i < sourceSize; i++)
  2266. {
  2267. destDataUC32[i] =
  2268. (UInt32) (sourceDataF32[i] * 4294967295.0);
  2269. }
  2270. break;
  2271. #endif
  2272. #if !defined(OSG_EMBEDDED)
  2273. case OSG_FLOAT16_IMAGEDATA:
  2274. for (int i = 0; i < sourceSize; i++)
  2275. {
  2276. destDataH16[i] =
  2277. Real16 (sourceDataF32[i]); // half-constructor
  2278. }
  2279. break;
  2280. #endif
  2281. default:
  2282. FWARNING(("invalid destination data type \n"));
  2283. break;
  2284. }
  2285. break;
  2286. default:
  2287. FWARNING (( "invalid source data type \n"));
  2288. break;
  2289. }
  2290. if(dest->getData() != NULL)
  2291. {
  2292. this->set(dest);
  2293. subRef(dest);
  2294. }
  2295. return (getData() ? true : false);
  2296. }
  2297. /*! It just fills the hole image data with the given pixel value. It is
  2298. mainly used to initialize the image data.
  2299. */
  2300. void Image::clear(UChar8 pixelValue)
  2301. {
  2302. memset(editData(), pixelValue, getSize());
  2303. }
  2304. void Image::clearFloat(Real32 pixelValue)
  2305. {
  2306. unsigned long n = getSize()/getComponentSize();
  2307. Real32 *d = (Real32*) editData ();
  2308. if(n && d)
  2309. {
  2310. while(n--)
  2311. {
  2312. *d++ = pixelValue;
  2313. }
  2314. }
  2315. }
  2316. void Image::clearHalf(Real16 pixelValue)
  2317. {
  2318. unsigned long n = getSize()/getComponentSize();
  2319. Real16 *d = (Real16*) getData();
  2320. if(n && d)
  2321. while(n--)
  2322. *d++ = pixelValue;
  2323. }
  2324. /*-------------------------------------------------------------------------*/
  2325. /* attachment handling */
  2326. /*! returns true if the image has any attachments
  2327. */
  2328. bool Image::hasAttachment(void) const
  2329. {
  2330. Image *img=const_cast<Image*>(this);
  2331. ImageGenericAttPtr att = dynamic_cast<ImageGenericAttPtr>(
  2332. img->Inherited::findAttachment(
  2333. ImageGenericAtt::getClassType().getGroupId()));
  2334. if(att != NullFC && att->getType().getNumFieldDescs() > 1)
  2335. return true;
  2336. else
  2337. return false;
  2338. }
  2339. /*! returns the number of attachments
  2340. */
  2341. UInt32 Image::attachmentCount(void) const
  2342. {
  2343. Image *img=const_cast<Image*>(this);
  2344. ImageGenericAttPtr att = dynamic_cast<ImageGenericAttPtr>(
  2345. img->Inherited::findAttachment(
  2346. ImageGenericAtt::getClassType().getGroupId()));
  2347. if(att != NullFC)
  2348. {
  2349. return att->getType().getNumFieldDescs() -1;
  2350. }
  2351. else
  2352. {
  2353. return 0;
  2354. }
  2355. }
  2356. /*! set a single string attachment for the given key/data pair
  2357. */
  2358. void Image::setAttachmentField(const std::string &key,
  2359. const std::string &data)
  2360. {
  2361. ImageGenericAttPtr att = dynamic_cast<ImageGenericAttPtr>(
  2362. findAttachment(
  2363. ImageGenericAtt::getClassType().getGroupId()));
  2364. FieldContainerAttachmentPtr fooP = att;
  2365. if(att == NullFC)
  2366. {
  2367. att = ImageGenericAtt::create();
  2368. addAttachment(att);
  2369. }
  2370. if(att == NullFC)
  2371. {
  2372. FWARNING(("Image::setAttachmentField - can not create attachment\n"));
  2373. return;
  2374. }
  2375. EditFieldHandlePtr field = att->editDynamicFieldByName(key.c_str());
  2376. if(field == NULL)
  2377. {
  2378. FieldDescriptionBase *pDesc;
  2379. pDesc = new SFString::Description(
  2380. SFString::getClassType(),
  2381. key.c_str(),
  2382. "",
  2383. 0,
  2384. 0,
  2385. true,
  2386. Field::SFDefaultFlags,
  2387. reinterpret_cast<FieldEditMethodSig>(
  2388. &ImageGenericAtt::editDynamicField),
  2389. reinterpret_cast<FieldGetMethodSig >(
  2390. &ImageGenericAtt::getDynamicField ));
  2391. UInt32 fieldId = att->addField(*pDesc);
  2392. field = att->editDynamicField(fieldId);
  2393. }
  2394. SFString::EditHandlePtr strField =
  2395. boost::static_pointer_cast<SFString::EditHandle>(field);
  2396. if(strField != NULL && strField->isValid() == true)
  2397. (*strField)->setValue(data);
  2398. }
  2399. /*! returns the string attachment for the given key or Null
  2400. */
  2401. const std::string *Image::findAttachmentField(const std::string &key) const
  2402. {
  2403. Image *img=const_cast<Image*>(this);
  2404. ImageGenericAttPtr att = dynamic_cast<ImageGenericAttPtr>(
  2405. img->findAttachment(
  2406. ImageGenericAtt::getClassType().getGroupId()));
  2407. if(att != NullFC)
  2408. {
  2409. GetFieldHandlePtr field = att->getDynamicFieldByName(key.c_str());
  2410. if(field != NULL)
  2411. {
  2412. SFString::GetHandlePtr strField =
  2413. boost::static_pointer_cast<SFString::GetHandle>(field);
  2414. if(strField != NULL && strField->isValid() == true)
  2415. return &((*strField)->getValue());
  2416. }
  2417. }
  2418. return NULL;
  2419. }
  2420. /*! Method to scale the image. It just does a very simple but fast
  2421. 'nearest' scale. Should handle mipmap and frame data correct.
  2422. The method can operate on the object or stores the result in
  2423. the optional destination Image.
  2424. */
  2425. bool Image::scale(Int32 width,
  2426. Int32 height,
  2427. Int32 depth,
  2428. ImagePtr destination)
  2429. {
  2430. ImagePtr destImage;
  2431. UInt32 sw, sh, sd, dw, dh, dd;
  2432. Int32 frame, scale, side, mipmap;
  2433. UChar8 *src, *dest;
  2434. Int32 oldWidth =getWidth();
  2435. Int32 oldHeight=getHeight();
  2436. Int32 oldDepth =getDepth();
  2437. MFUInt8 srcPixel;
  2438. if (hasCompressedData())
  2439. {
  2440. FFATAL (("Invalid Image::scale for compressed image\n"));
  2441. return false;
  2442. }
  2443. if(destination != NullFC)
  2444. {
  2445. destImage = destination;
  2446. }
  2447. else
  2448. {
  2449. destImage = this;
  2450. }
  2451. // get pixel
  2452. srcPixel = getPixel();
  2453. // set image data
  2454. destImage->set((PixelFormat) getPixelFormat(),
  2455. width,
  2456. height,
  2457. depth,
  2458. getMipMapCount(),
  2459. getFrameCount (),
  2460. getFrameDelay (),
  2461. 0,
  2462. getDataType (),
  2463. true,
  2464. getSideCount ());
  2465. // copy every mipmap in every side in every frame
  2466. for(frame = 0; frame < getFrameCount(); frame++)
  2467. {
  2468. for (side = 0; side < getSideCount(); side++)
  2469. {
  2470. for(mipmap = 0; mipmap < getMipMapCount(); mipmap++)
  2471. {
  2472. // get the memory pointer
  2473. src = (&srcPixel[0]) +
  2474. (side * getSideSize ()) +
  2475. (frame * getFrameSize()) ;
  2476. if(mipmap)
  2477. {
  2478. src += calcMipmapSumSize (mipmap,
  2479. oldWidth,
  2480. oldHeight,
  2481. oldDepth);
  2482. }
  2483. dest = destImage->editData(mipmap, frame, side);
  2484. // calc the mipmap size
  2485. sw = oldWidth >> mipmap;
  2486. sh = oldHeight >> mipmap;
  2487. sd = oldDepth >> mipmap;
  2488. destImage->calcMipmapGeometry(mipmap, dw, dh, dd);
  2489. // copy and scale the data
  2490. scaleData(src, sw, sh, sd, dest, dw, dh, dd);
  2491. }
  2492. }
  2493. }
  2494. return true;
  2495. }
  2496. /*! Scale the image to the next power of 2 dimensions
  2497. The method can operate on the object or stores the result in
  2498. the optional destination Image.
  2499. */
  2500. bool Image::scaleNextPower2(ImagePtr destination)
  2501. {
  2502. return scale(osgNextPower2(getWidth ()),
  2503. osgNextPower2(getHeight()),
  2504. osgNextPower2(getDepth ()),
  2505. destination );
  2506. }
  2507. /*! Crop the image to the given bounding box.
  2508. The method can operate on the object or stores the result in
  2509. the optional destination Image.
  2510. */
  2511. bool Image::subImage(Int32 offX,
  2512. Int32 offY,
  2513. Int32 offZ,
  2514. Int32 destW,
  2515. Int32 destH,
  2516. Int32 destD,
  2517. ImagePtr destination)
  2518. {
  2519. ImagePtr destImage = destination;
  2520. bool retCode = true;
  2521. if (hasCompressedData())
  2522. {
  2523. FFATAL (("Invalid Image::subImage for compressed image\n"));
  2524. return false;
  2525. }
  2526. if(destination == NullFC)
  2527. {
  2528. destImage = Image::create();
  2529. addRef(destImage);
  2530. }
  2531. destImage->set((PixelFormat) getPixelFormat(),
  2532. destW,
  2533. destH,
  2534. destD,
  2535. 1,
  2536. 1,
  2537. 0.0,
  2538. 0,
  2539. getDataType());
  2540. const UChar8 *src = getData ();
  2541. UChar8 *dest = destImage->editData();
  2542. FDEBUG(("Image::subImage (%d %d %d) - (%d %d %d) - destPtr %p\n",
  2543. offX, offY, offZ, destW, destH, destD, dest));
  2544. // ensure destination data is zero
  2545. memset(dest, 0, destImage->getSize());
  2546. // determine the area to actually copy
  2547. UInt32 xMin = offX;
  2548. UInt32 yMin = offY;
  2549. UInt32 zMin = offZ;
  2550. UInt32 xMax = osgMin(getWidth (), offX + destW);
  2551. UInt32 yMax = osgMin(getHeight(), offY + destH);
  2552. UInt32 zMax = osgMin(getDepth (), offZ + destD);
  2553. // fill the destination buffer with the subdata
  2554. UInt32 destIdx = 0;
  2555. for(UInt32 z = zMin; z < zMax; z++)
  2556. {
  2557. for(UInt32 y = yMin; y < yMax; y++)
  2558. {
  2559. for(UInt32 x = xMin; x < xMax; x++)
  2560. {
  2561. for(UInt32 i = 0; i < getBpp(); i++)
  2562. {
  2563. dest[destIdx] = src[((z * getHeight() + y) *
  2564. getWidth() + x) * getBpp() + i];
  2565. destIdx++;
  2566. }
  2567. }
  2568. destIdx += (destW - (xMax - xMin)) * getBpp();
  2569. }
  2570. destIdx += (destH - (yMax - yMin)) * destW * getBpp();
  2571. }
  2572. // rip the data from the local destImage if necessary
  2573. if(destination == NullFC)
  2574. {
  2575. this->set(destImage);
  2576. subRef(destImage);
  2577. }
  2578. return retCode;
  2579. }
  2580. /*! Crop a slice.
  2581. The method can operate on the object or stores the result in
  2582. the optional destination Image.
  2583. */
  2584. bool Image::slice(Int32 offX,
  2585. Int32 offY,
  2586. Int32 offZ,
  2587. ImagePtr destination)
  2588. {
  2589. ImagePtr destImage = destination;
  2590. bool retCode = true;
  2591. UInt32 counter = 0;
  2592. if (hasCompressedData())
  2593. {
  2594. FFATAL (("Invalid Image::slice for compressed image\n"));
  2595. return false;
  2596. }
  2597. if(destination == NullFC)
  2598. {
  2599. destImage = Image::create();
  2600. addRef(destImage);
  2601. }
  2602. FDEBUG(("Image::slice (%d %d %d)\n",
  2603. offX, offY, offZ));
  2604. if(offX >= 0)
  2605. counter++;
  2606. if(offY >= 0)
  2607. counter++;
  2608. if(offZ >= 0)
  2609. counter++;
  2610. if(counter != 1)
  2611. {
  2612. FWARNING(("Image::slice - more/less than one non negative value\n"));
  2613. return false;
  2614. }
  2615. if(offZ >= 0)
  2616. {
  2617. // XY slice
  2618. retCode = subImage(0,
  2619. 0,
  2620. offZ,
  2621. getWidth (),
  2622. getHeight(),
  2623. 1,
  2624. destImage );
  2625. }
  2626. if(offY >= 0)
  2627. {
  2628. // XZ slice
  2629. destImage->set((PixelFormat) getPixelFormat(),
  2630. getWidth(),
  2631. getDepth(),
  2632. 1,
  2633. 1,
  2634. 1,
  2635. 0.0,
  2636. 0,
  2637. getDataType());
  2638. const UChar8 *src = getData ();
  2639. UChar8 *dest = destImage->editData();
  2640. // ensure destination data is zero
  2641. memset(dest, 0, destImage->getSize());
  2642. for(UInt32 z = 0; z < getDepth(); z++)
  2643. {
  2644. for(UInt32 x = 0; x < getWidth(); x++)
  2645. {
  2646. for(UInt32 i = 0; i < getBpp(); i++)
  2647. {
  2648. dest[(z * getWidth() + x) * getBpp() + i] =
  2649. src[((z * getHeight() + offY) * getWidth() + x) *
  2650. getBpp() + i];
  2651. }
  2652. }
  2653. }
  2654. }
  2655. if(offX >= 0)
  2656. {
  2657. // YZ slice
  2658. destImage->set((PixelFormat)getPixelFormat(),
  2659. getWidth(),
  2660. getDepth(),
  2661. 1,
  2662. 1,
  2663. 1,
  2664. 0.0,
  2665. 0,
  2666. getDataType());
  2667. const UChar8 *src = getData ();
  2668. UChar8 *dest = destImage->editData();
  2669. // ensure destination data is zero
  2670. memset(dest, 0, destImage->getSize());
  2671. for(UInt32 z = 0; z < getDepth(); z++)
  2672. {
  2673. for(UInt32 y = 0; y < getHeight(); y++)
  2674. {
  2675. for(UInt32 i = 0; i < getBpp(); i++)
  2676. {
  2677. dest[(z * getHeight() + y) * getBpp() + i] =
  2678. src[((z * getHeight() + y) * getWidth() + offX) *
  2679. getBpp() + i];
  2680. }
  2681. }
  2682. }
  2683. }
  2684. // rip the data from the local destImage if necessary
  2685. if(destination == NullFC)
  2686. {
  2687. this->set(destImage);
  2688. subRef(destImage);
  2689. }
  2690. return retCode;
  2691. }
  2692. /*! Create mipmaps data, level defines the number of level
  2693. The method can operate on the object or stores the result in
  2694. the optional destination Image.
  2695. */
  2696. bool Image::createMipmap(Int32 level, ImagePtr destination)
  2697. {
  2698. struct Offset
  2699. {
  2700. Int32 d;
  2701. Int32 h;
  2702. Int32 w;
  2703. };
  2704. Offset offset[][8] =
  2705. {
  2706. { // 000
  2707. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
  2708. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
  2709. },
  2710. { // 100
  2711. { 0, 0, 0 }, { 1, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
  2712. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
  2713. },
  2714. { // 010
  2715. { 0, 0, 0 }, { 0, 1, 0 }, { 0, 0, 0 }, { 0, 0, 0 },
  2716. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
  2717. },
  2718. { // 110
  2719. { 0, 0, 0 }, { 0, 1, 0 }, { 1, 0, 0 }, { 1, 1, 0 },
  2720. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
  2721. },
  2722. { // 001
  2723. { 0, 0, 0 }, { 0, 0, 1 }, { 0, 0, 0 }, { 0, 0, 0 },
  2724. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
  2725. },
  2726. { // 101
  2727. { 0, 0, 0 }, { 1, 0, 0 }, { 0, 0, 1 }, { 1, 0, 1 },
  2728. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
  2729. },
  2730. { // 011
  2731. { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 0 }, { 0, 1, 1 },
  2732. { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }
  2733. },
  2734. { // 111
  2735. { 0, 0, 0 }, { 1, 0, 0 }, { 0, 1, 0 }, { 1, 1, 0 },
  2736. { 0, 0, 1 }, { 1, 0, 1 }, { 0, 1, 1 }, { 1, 1, 1 }
  2737. }
  2738. };
  2739. Int32 offsetSize[] = { 0, 2, 2, 4, 2, 4, 4, 8 };
  2740. ImagePtr destImage = destination;
  2741. Int32 w = getWidth(), h = getHeight(), d = getDepth();
  2742. Int32 wm, hm, dm, wi, hi, di;
  2743. const UChar8 *src;
  2744. UChar8 *dest;
  2745. const UInt16 *sourceDataUC16;
  2746. UInt16 *destDataUC16;
  2747. const UInt32 *sourceDataUC32;
  2748. UInt32 *destDataUC32;
  2749. const Real32 *sourceDataF32;
  2750. Real32 *destDataF32;
  2751. const Real16 *sourceDataH16;
  2752. Real16 *destDataH16;
  2753. if (hasCompressedData())
  2754. {
  2755. FFATAL (("Invalid Image::createMipmap for compressed image\n"));
  2756. return false;
  2757. }
  2758. if(destImage == NullFC)
  2759. {
  2760. destImage = Image::create();
  2761. addRef(destImage);
  2762. }
  2763. Real32 valueFloat;
  2764. Int32 value, i, elem, dim, side, frame, size, mipmap;
  2765. Int32 channel, lineSize, sliceSize;
  2766. // calc the level count
  2767. if(level < 0)
  2768. {
  2769. level = calcMipmapLevelCount() - 1;
  2770. }
  2771. // create destination image
  2772. destImage->set(getPixelFormat(),
  2773. getWidth(),
  2774. getHeight(),
  2775. getDepth(),
  2776. level,
  2777. getFrameCount(),
  2778. getFrameDelay(),
  2779. 0,
  2780. getDataType(),
  2781. true,
  2782. getSideCount());
  2783. // copy the data;
  2784. switch (getDataType())
  2785. {
  2786. case OSG_UINT8_IMAGEDATA:
  2787. for(frame = 0; frame < getFrameCount(); frame++)
  2788. {
  2789. for(side = 0; side < getSideCount(); side++)
  2790. {
  2791. src = this ->getData (0, frame, side);
  2792. dest = destImage->editData(0, frame, side);
  2793. size = getWidth() * getHeight() * getDepth() * getBpp();
  2794. memcpy(dest, src, size);
  2795. src = dest;
  2796. dest = dest + size;
  2797. w = getWidth ();
  2798. h = getHeight();
  2799. d = getDepth ();
  2800. for(mipmap = 1; mipmap < level; mipmap++)
  2801. {
  2802. lineSize = w * getBpp();
  2803. sliceSize = w * h * getBpp();
  2804. wm = (w == 1) ? w : (w >> 1);
  2805. hm = (h == 1) ? h : (h >> 1);
  2806. dm = (d == 1) ? d : (d >> 1);
  2807. dim = (d > dm) * 1 + (h > hm) * 2 + (w > wm) * 4;
  2808. elem = offsetSize[dim];
  2809. for(di = 0; di < dm; di++)
  2810. {
  2811. for(hi = 0; hi < hm; hi++)
  2812. {
  2813. for(wi = 0; wi < wm; wi++)
  2814. {
  2815. for(channel = 0; channel < getBpp(); channel++)
  2816. {
  2817. value = 0;
  2818. for(i = 0; i < elem; i++)
  2819. {
  2820. value += src[
  2821. ((wi * 2) + offset[dim][i].w) * getBpp() +
  2822. ((hi * 2) + offset[dim][i].h) * lineSize +
  2823. ((di * 2) + offset[dim][i].d) * sliceSize +
  2824. channel];
  2825. }
  2826. *dest++ = (Int8) (value / elem);
  2827. }
  2828. }
  2829. }
  2830. }
  2831. src += sliceSize;
  2832. w = wm;
  2833. h = hm;
  2834. d = dm;
  2835. }
  2836. }
  2837. }
  2838. break;
  2839. #if !defined(OSG_EMBEDDED)
  2840. case OSG_UINT16_IMAGEDATA:
  2841. for(frame = 0; frame < getFrameCount(); frame++)
  2842. {
  2843. for(side = 0; side < getSideCount(); side++)
  2844. {
  2845. src = this ->getData (0, frame, side);
  2846. dest = destImage->editData(0, frame, side);
  2847. size = getWidth() * getHeight() * getDepth() * getBpp();
  2848. memcpy(dest, src, size);
  2849. src = dest;
  2850. dest = dest + size;
  2851. w = getWidth ();
  2852. h = getHeight();
  2853. d = getDepth ();
  2854. sourceDataUC16 = (const UInt16 *) src;
  2855. destDataUC16 = ( UInt16 *) dest;
  2856. for(mipmap = 1; mipmap < level; mipmap++)
  2857. {
  2858. lineSize = w * (getBpp() / getComponentSize());
  2859. sliceSize = w * h * (getBpp() / getComponentSize());
  2860. wm = (w == 1) ? w : (w >> 1);
  2861. hm = (h == 1) ? h : (h >> 1);
  2862. dm = (d == 1) ? d : (d >> 1);
  2863. dim = (d > dm) * 1 + (h > hm) * 2 + (w > wm) * 4;
  2864. elem = offsetSize[dim];
  2865. for(di = 0; di < dm; di++)
  2866. {
  2867. for(hi = 0; hi < hm; hi++)
  2868. {
  2869. for(wi = 0; wi < wm; wi++)
  2870. {
  2871. for(channel = 0;
  2872. channel < (getBpp() / getComponentSize());
  2873. channel++)
  2874. {
  2875. value = 0;
  2876. for(i = 0; i < elem; i++)
  2877. {
  2878. value += sourceDataUC16[
  2879. ((wi * 2) + offset[dim][i].w) * (getBpp() / getComponentSize()) +
  2880. ((hi * 2) + offset[dim][i].h) * lineSize +
  2881. ((di * 2) + offset[dim][i].d) * sliceSize +
  2882. channel];
  2883. }
  2884. *destDataUC16++ = (UInt16) (value / elem);
  2885. }
  2886. }
  2887. }
  2888. }
  2889. sourceDataUC16 += sliceSize;
  2890. w = wm;
  2891. h = hm;
  2892. d = dm;
  2893. }
  2894. }
  2895. }
  2896. break;
  2897. case OSG_UINT32_IMAGEDATA:
  2898. for(frame = 0; frame < getFrameCount(); frame++)
  2899. {
  2900. for(side = 0; side < getSideCount(); side++)
  2901. {
  2902. src = this ->getData (0, frame,side);
  2903. dest = destImage->editData(0, frame,side);
  2904. size = getWidth() * getHeight() * getDepth() * getBpp();
  2905. memcpy(dest, src, size);
  2906. src = dest;
  2907. dest = dest + size;
  2908. w = getWidth ();
  2909. h = getHeight();
  2910. d = getDepth ();
  2911. sourceDataUC32 = (const UInt32 *) src;
  2912. destDataUC32 = ( UInt32 *) dest;
  2913. for(mipmap = 1; mipmap < level; mipmap++)
  2914. {
  2915. lineSize = w * (getBpp() / getComponentSize());
  2916. sliceSize = w * h * (getBpp() / getComponentSize());
  2917. wm = (w == 1) ? w : (w >> 1);
  2918. hm = (h == 1) ? h : (h >> 1);
  2919. dm = (d == 1) ? d : (d >> 1);
  2920. dim = (d > dm) * 1 + (h > hm) * 2 + (w > wm) * 4;
  2921. elem = offsetSize[dim];
  2922. for(di = 0; di < dm; di++)
  2923. {
  2924. for(hi = 0; hi < hm; hi++)
  2925. {
  2926. for(wi = 0; wi < wm; wi++)
  2927. {
  2928. for(channel = 0;
  2929. channel < (getBpp()/getComponentSize());
  2930. channel++)
  2931. {
  2932. value = 0;
  2933. for(i = 0; i < elem; i++)
  2934. {
  2935. value += (sourceDataUC32[
  2936. ((wi * 2) + offset[dim][i].w) * (getBpp() / getComponentSize()) +
  2937. ((hi * 2) + offset[dim][i].h) * lineSize +
  2938. ((di * 2) + offset[dim][i].d) * sliceSize +
  2939. channel]/elem);
  2940. }
  2941. *destDataUC32++ = (UInt32) value;
  2942. }
  2943. }
  2944. }
  2945. }
  2946. sourceDataUC32 += sliceSize;
  2947. w = wm;
  2948. h = hm;
  2949. d = dm;
  2950. }
  2951. }
  2952. }
  2953. break;
  2954. #endif
  2955. case OSG_FLOAT32_IMAGEDATA:
  2956. for(frame = 0; frame < getFrameCount(); frame++)
  2957. {
  2958. for(side = 0; side < getSideCount(); side++)
  2959. {
  2960. src = this ->getData (0, frame,side);
  2961. dest = destImage->editData(0, frame,side);
  2962. size = getWidth() * getHeight() * getDepth() * getBpp();
  2963. memcpy(dest, src, size);
  2964. src = dest;
  2965. dest = dest + size;
  2966. w = getWidth ();
  2967. h = getHeight();
  2968. d = getDepth ();
  2969. sourceDataF32 = (const Real32 *) src;
  2970. destDataF32 = ( Real32 *) dest;
  2971. for(mipmap = 1; mipmap < level; mipmap++)
  2972. {
  2973. lineSize = w * (getBpp() / getComponentSize());
  2974. sliceSize = w * h * (getBpp() / getComponentSize());
  2975. wm = (w == 1) ? w : (w >> 1);
  2976. hm = (h == 1) ? h : (h >> 1);
  2977. dm = (d == 1) ? d : (d >> 1);
  2978. dim = (d > dm) * 1 + (h > hm) * 2 + (w > wm) * 4;
  2979. elem = offsetSize[dim];
  2980. for(di = 0; di < dm; di++)
  2981. {
  2982. for(hi = 0; hi < hm; hi++)
  2983. {
  2984. for(wi = 0; wi < wm; wi++)
  2985. {
  2986. for(channel = 0;
  2987. channel < (getBpp() / getComponentSize());
  2988. channel++)
  2989. {
  2990. valueFloat = 0;
  2991. for(i = 0; i < elem; i++)
  2992. {
  2993. valueFloat += sourceDataF32[
  2994. ((wi * 2) + offset[dim][i].w) * (getBpp() / getComponentSize()) +
  2995. ((hi * 2) + offset[dim][i].h) * lineSize +
  2996. ((di * 2) + offset[dim][i].d) * sliceSize +
  2997. channel];
  2998. }
  2999. *destDataF32++ = (Real32) (valueFloat / elem);
  3000. }
  3001. }
  3002. }
  3003. }
  3004. sourceDataF32 += sliceSize;
  3005. w = wm;
  3006. h = hm;
  3007. d = dm;
  3008. }
  3009. }
  3010. }
  3011. break;
  3012. #if !defined(OSG_EMBEDDED)
  3013. case OSG_FLOAT16_IMAGEDATA:
  3014. for(frame = 0; frame < getFrameCount(); frame++)
  3015. {
  3016. for(side = 0; side < getSideCount(); side++)
  3017. {
  3018. src = this->getData(0, frame,side);
  3019. dest = destImage->editData(0, frame,side);
  3020. size = getWidth() * getHeight() * getDepth() * getBpp();
  3021. memcpy(dest,src, size);
  3022. src = dest;
  3023. dest = dest + size;
  3024. w = getWidth();
  3025. h = getHeight();
  3026. d = getDepth();
  3027. sourceDataH16 = (Real16*) src;
  3028. destDataH16 = (Real16*) dest;
  3029. for(mipmap = 1; mipmap < level; mipmap++)
  3030. {
  3031. lineSize = w * (getBpp() / getComponentSize());
  3032. sliceSize = w * h * (getBpp() / getComponentSize());
  3033. wm = (w == 1) ? w : (w >> 1);
  3034. hm = (h == 1) ? h : (h >> 1);
  3035. dm = (d == 1) ? d : (d >> 1);
  3036. dim = (d > dm) * 1 + (h > hm) * 2 + (w > wm) * 4;
  3037. elem = offsetSize[dim];
  3038. for(di = 0; di < dm; di++)
  3039. {
  3040. for(hi = 0; hi < hm; hi++)
  3041. {
  3042. for(wi = 0; wi < wm; wi++)
  3043. {
  3044. for(channel = 0; channel < (getBpp()/getComponentSize()); channel++)
  3045. {
  3046. valueFloat = 0;
  3047. for(i = 0; i < elem; i++)
  3048. {
  3049. valueFloat += sourceDataH16[
  3050. ((wi * 2) + offset[dim][i].w) * (getBpp() / getComponentSize()) +
  3051. ((hi * 2) + offset[dim][i].h) * lineSize +
  3052. ((di * 2) + offset[dim][i].d) * sliceSize +
  3053. channel];
  3054. }
  3055. *destDataH16++ = (Real16) (valueFloat / elem);
  3056. }
  3057. }
  3058. }
  3059. }
  3060. sourceDataH16 += sliceSize;
  3061. w = wm;
  3062. h = hm;
  3063. d = dm;
  3064. }
  3065. }
  3066. }
  3067. break;
  3068. #endif
  3069. default:
  3070. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  3071. break;
  3072. }
  3073. // rip the data from the local destImage if necessary
  3074. if(destination == NullFC)
  3075. {
  3076. this->set(destImage);
  3077. subRef(destImage);
  3078. }
  3079. return true;
  3080. }
  3081. /*! Write the image to the a file. The mimetype will be set automatically
  3082. from the fileName suffix. Returns true on success.
  3083. */
  3084. bool Image::write(const Char8 *fileName)
  3085. {
  3086. #if !defined(OSG_EMBEDDED)
  3087. return ImageFileHandler::the()->write(this, fileName);
  3088. #else
  3089. return false;
  3090. #endif
  3091. }
  3092. /*! Read the image data from a file. Returns true on success.
  3093. */
  3094. bool Image::read(const Char8 *fileName)
  3095. {
  3096. #if !defined(OSG_EMBEDDED)
  3097. return ImageFileHandler::the()->read(this, fileName);
  3098. #else
  3099. return false;
  3100. #endif
  3101. }
  3102. /*! Store the image to the given mem block as 'mimeType'.
  3103. mimeType can be 0, in which case the method will store the
  3104. object as uncompressed mtd data.
  3105. Returns the number of bytes used.
  3106. */
  3107. UInt64 Image::store(const Char8 *mimeType, UChar8 *mem, Int32 memSize)
  3108. {
  3109. #if !defined(OSG_EMBEDDED)
  3110. return ImageFileHandler::the()->store(this,
  3111. mimeType,
  3112. mem,
  3113. memSize);
  3114. #else
  3115. return false;
  3116. #endif
  3117. }
  3118. /*! Restore the image from the given mem block. Returns the
  3119. number of bytes used.
  3120. */
  3121. UInt64 Image::restore(const UChar8 *mem, Int32 memSize)
  3122. {
  3123. #if !defined(OSG_EMBEDDED)
  3124. return ImageFileHandler::the()->restore(this, mem, memSize);;
  3125. #else
  3126. return false;
  3127. #endif
  3128. }
  3129. /*-------------------------------------------------------------------------*/
  3130. /* Constructor / Destructor */
  3131. /*! Default Constructor. Creates a invalid Image of the size 0x0x0
  3132. */
  3133. Image::Image(void) :
  3134. Inherited()
  3135. {
  3136. }
  3137. /*! Copy Constructor. Creates a copy of the given image
  3138. */
  3139. Image::Image(const Image &obj) :
  3140. Inherited(obj)
  3141. {
  3142. }
  3143. /*! Destructor.
  3144. */
  3145. Image::~Image(void)
  3146. {
  3147. }
  3148. /*! Method to check, whether the object data defines a alpha channel or not
  3149. */
  3150. bool Image::hasAlphaChannel(void)
  3151. {
  3152. return
  3153. (getForceAlphaChannel() == true ) ||
  3154. (getPixelFormat () == OSG_RGBA_PF ) ||
  3155. (getPixelFormat () == OSG_BGRA_PF ) ||
  3156. (getPixelFormat () == OSG_RGBA_DXT1) ||
  3157. (getPixelFormat () == OSG_RGBA_DXT3) ||
  3158. (getPixelFormat () == OSG_RGBA_DXT5) ||
  3159. (getPixelFormat () == OSG_A_PF ) ||
  3160. #if !defined(OSG_EMBEDDED)
  3161. (getPixelFormat () == OSG_I_PF ) ||
  3162. #endif
  3163. (getPixelFormat () == OSG_LA_PF );
  3164. }
  3165. /*! Method to check, whether the alpha channel is just fully transparent/
  3166. fully opaque
  3167. */
  3168. bool Image::isAlphaBinary(void)
  3169. {
  3170. return
  3171. (getForceAlphaBinary() == true ) ||
  3172. (getPixelFormat () == OSG_RGBA_DXT1);
  3173. }
  3174. /*! Method to check, whether the data is compressed
  3175. */
  3176. bool Image::hasCompressedData(void)
  3177. {
  3178. return
  3179. (getForceCompressedData() == true ) ||
  3180. (getPixelFormat () == OSG_RGB_DXT1 ) ||
  3181. (getPixelFormat () == OSG_RGBA_DXT1) ||
  3182. (getPixelFormat () == OSG_RGBA_DXT3) ||
  3183. (getPixelFormat () == OSG_RGBA_DXT5);
  3184. }
  3185. /*! Method to check, whether the object data defines a color channel or not
  3186. */
  3187. bool Image::hasColorChannel(void)
  3188. {
  3189. return
  3190. ( !( getPixelFormat() == OSG_A_PF ||
  3191. #if !defined(OSG_EMBEDDED)
  3192. getPixelFormat() == OSG_I_PF ||
  3193. #endif
  3194. getPixelFormat() == OSG_L_PF ||
  3195. getPixelFormat() == OSG_LA_PF )) ||
  3196. getForceColorChannel();
  3197. }
  3198. /*! Method returns the right frame data for the given time.
  3199. */
  3200. const UInt8 *Image::getDataByTime(Time time, UInt32) const
  3201. {
  3202. UInt32 frameNum = calcFrameNum(time, true);
  3203. return getData(0, frameNum);
  3204. }
  3205. UInt8 *Image::editDataByTime(Time time, UInt32)
  3206. {
  3207. UInt32 frameNum = calcFrameNum(time, true);
  3208. return editData(0, frameNum);
  3209. }
  3210. /*! Check all the alpha values to see if they're 0 or 1, return true if they
  3211. are, false if no alpha or intermediate values. No Alpha channel is considered
  3212. 0.
  3213. */
  3214. bool Image::calcIsAlphaBinary(void)
  3215. {
  3216. if(!hasAlphaChannel() || getPixelFormat() == OSG_RGBA_DXT1)
  3217. return true;
  3218. if(getPixelFormat() == OSG_RGBA_DXT3 || getPixelFormat() == OSG_RGBA_DXT5)
  3219. {
  3220. FWARNING(("Image::calcIsAlphaBinary: not implemenetd for DXT3 "
  3221. "and DXT5 yet, assuming false.\n"));
  3222. return false;
  3223. }
  3224. UInt32 npix = getWidth() * getHeight() * getDepth() * getFrameCount();
  3225. UInt8 pixelsize = getBpp();
  3226. const UInt8 *data = getData();
  3227. switch(getPixelFormat())
  3228. {
  3229. case OSG_LA_PF:
  3230. data += getComponentSize(); break;
  3231. case OSG_BGRA_PF:
  3232. case OSG_RGBA_PF:
  3233. data += getComponentSize() * 3; break;
  3234. default:
  3235. FWARNING(("Image::calcIsAlphaBinary: found unknown "
  3236. "image format %x, assumning false.\n",
  3237. getPixelFormat()));
  3238. return false;
  3239. }
  3240. switch(getDataType())
  3241. {
  3242. case OSG_UINT8_IMAGEDATA:
  3243. for(; npix > 0; --npix, data += pixelsize)
  3244. {
  3245. if(*data != 0 && *data != 0xffU)
  3246. break;
  3247. }
  3248. break;
  3249. #if !defined(OSG_EMBEDDED)
  3250. case OSG_UINT16_IMAGEDATA:
  3251. for(; npix > 0; --npix, data += pixelsize)
  3252. {
  3253. const UInt16 *d = reinterpret_cast<const UInt16*>(data);
  3254. if(*d != 0 && *d != 0xffffU)
  3255. break;
  3256. }
  3257. break;
  3258. case OSG_UINT32_IMAGEDATA:
  3259. for(; npix > 0; --npix, data += pixelsize)
  3260. {
  3261. const UInt32 *d = reinterpret_cast<const UInt32*>(data);
  3262. if(*d != 0 && *d != 0xffffffffU)
  3263. break;
  3264. }
  3265. break;
  3266. case OSG_FLOAT16_IMAGEDATA:
  3267. for(; npix > 0; --npix, data += pixelsize)
  3268. {
  3269. const Real16 *d = reinterpret_cast<const Real16*>(data);
  3270. if(*d != 0 && *d != 1)
  3271. break;
  3272. }
  3273. break;
  3274. #endif
  3275. case OSG_FLOAT32_IMAGEDATA:
  3276. for(; npix > 0; --npix, data += pixelsize)
  3277. {
  3278. const Real32 *d = reinterpret_cast<const Real32*>(data);
  3279. if(*d != 0 && *d != 1)
  3280. break;
  3281. }
  3282. break;
  3283. default:
  3284. FWARNING(("Image::calcIsAlphaBinary: found unknown "
  3285. "data type %d, assumning false.\n",
  3286. getDataType()));
  3287. return false;
  3288. }
  3289. return npix == 0;
  3290. }
  3291. /*! Method which returns the frame number for the given time
  3292. */
  3293. UInt32 Image::calcFrameNum(Time time, bool OSG_CHECK_ARG(loop)) const
  3294. {
  3295. UInt64 frameNum = ((getFrameDelay() > 0) && (getFrameCount() > 0)) ?
  3296. (UInt64(time / getFrameDelay()) % getFrameCount()) : 0;
  3297. return ((frameNum > 0) ? UInt32(frameNum) : 0);
  3298. }
  3299. /*! Internal used method to calculate the next mipmap geo for the given level
  3300. */
  3301. void Image::calcMipmapGeometry(UInt32 mipmapNum,
  3302. UInt32 &width,
  3303. UInt32 &height,
  3304. UInt32 &depth ) const
  3305. {
  3306. width = getWidth() ? osgMax(getWidth () >> mipmapNum, 1) : 0 ;
  3307. height = getHeight() ? osgMax(getHeight() >> mipmapNum, 1) : 0 ;
  3308. depth = getDepth() ? osgMax(getDepth () >> mipmapNum, 1) : 0 ;
  3309. }
  3310. #ifdef __sgi
  3311. #pragma set woff 1209
  3312. #endif
  3313. /*! Internal used method to calculate the number of mipmaps levels
  3314. */
  3315. UInt32 Image::calcMipmapLevelCount(void) const
  3316. {
  3317. UInt32 w = getWidth(), h = getHeight(), d = getDepth();
  3318. UInt32 level;
  3319. for (level = 1; true; level++)
  3320. {
  3321. if ((w == 1) && (h == 1) && (d == 1))
  3322. {
  3323. break;
  3324. }
  3325. else
  3326. {
  3327. w = (w >>= 1) ? w : 1;
  3328. h = (h >>= 1) ? h : 1;
  3329. d = (d >>= 1) ? d : 1;
  3330. }
  3331. }
  3332. return level;
  3333. }
  3334. #ifdef __sgi
  3335. #pragma reset woff 1209
  3336. #endif
  3337. /*-------------------------------------------------------------------------*/
  3338. /* Calculate Mipmap Size */
  3339. /*! Method to calculate the mem sum of a mipmap level in byte
  3340. */
  3341. UInt32 Image::calcMipmapLevelSize ( UInt32 mipmapNum,
  3342. UInt32 w, UInt32 h, UInt32 d) const
  3343. {
  3344. Int32 sum;
  3345. switch (getPixelFormat())
  3346. {
  3347. #if !defined(OSG_EMBEDDED)
  3348. case OSG_RGB_DXT1:
  3349. case OSG_RGBA_DXT1:
  3350. sum = (((w?w:1)+3)/4) * (((h?h:1)+3)/4) * 8;
  3351. break;
  3352. case OSG_RGBA_DXT3:
  3353. case OSG_RGBA_DXT5:
  3354. sum = (((w?w:1)+3)/4) * (((h?h:1)+3)/4) * 16;
  3355. break;
  3356. #endif
  3357. default:
  3358. sum = (w?w:1) * (h?h:1) * getBpp();
  3359. break;
  3360. }
  3361. sum *= (d?d:1);
  3362. return sum;
  3363. }
  3364. /*! Internal used method to calculate the size in bpp of a single mipmap
  3365. level for the current image settings
  3366. */
  3367. UInt32 Image::calcMipmapLevelSize(UInt32 mipmapNum) const
  3368. {
  3369. UInt32 w, h, d;
  3370. calcMipmapGeometry(mipmapNum, w, h, d);
  3371. return calcMipmapLevelSize(mipmapNum, w, h, d);
  3372. }
  3373. /*! Internal used method to calculate the mem sum of all mipmap levels in bpp
  3374. */
  3375. UInt32 Image::calcMipmapSumSize(UInt32 mipmapNum,
  3376. UInt32 w,
  3377. UInt32 h,
  3378. UInt32 d) const
  3379. {
  3380. Int32 levelSum, sum = 0;
  3381. if (w && h && d)
  3382. {
  3383. while (mipmapNum--)
  3384. {
  3385. sum += calcMipmapLevelSize(mipmapNum,w,h,d);
  3386. w >>= 1;
  3387. h >>= 1;
  3388. d >>= 1;
  3389. }
  3390. }
  3391. return sum;
  3392. }
  3393. /*! Method to calculate the mem sum of all mipmap levels in byte
  3394. for the current Image paramter
  3395. */
  3396. UInt32 Image::calcMipmapSumSize (UInt32 mipmapNum) const
  3397. {
  3398. return calcMipmapSumSize(mipmapNum, getWidth(), getHeight(), getDepth());
  3399. }
  3400. /*-------------------------------------------------------------------------*/
  3401. /* Image data */
  3402. /*! Internal method to set the data and update related properties.
  3403. */
  3404. bool Image::createData(const UInt8 *data, bool allocMem)
  3405. {
  3406. Int32 i;
  3407. Int32 mapSizeFormat = sizeof(_formatDic) / sizeof(UInt32[2]);
  3408. Int32 mapSizeType = sizeof(_typeDic ) / sizeof(UInt32[2]);
  3409. UInt32 byteCount = 0;
  3410. // set bpp
  3411. UInt32 pixelFormat = 0;
  3412. UInt32 typeFormat = 0;
  3413. for(i = 0; i < mapSizeFormat; i++)
  3414. {
  3415. if(_formatDic[i][0] == getPixelFormat())
  3416. pixelFormat = _formatDic[i][1];
  3417. }
  3418. for(i = 0; i < mapSizeType; i++)
  3419. {
  3420. if(_typeDic[i][0] == getDataType())
  3421. typeFormat = _typeDic[i][1];
  3422. }
  3423. setComponentSize(typeFormat );
  3424. setBpp (pixelFormat * typeFormat);
  3425. // set dimension
  3426. setDimension(0);
  3427. if(getDepth() == 1)
  3428. {
  3429. if(getHeight() == 1)
  3430. {
  3431. setDimension(1);
  3432. }
  3433. else
  3434. {
  3435. setDimension(2);
  3436. }
  3437. }
  3438. else
  3439. {
  3440. setDimension(3);
  3441. }
  3442. // set sideSize
  3443. setSideSize (calcMipmapSumSize(getMipMapCount() ));
  3444. // set frameSize
  3445. setFrameSize(getSideSize() * getSideCount());
  3446. // copy the data
  3447. if(allocMem && (byteCount = getSize()))
  3448. {
  3449. if(getPixel().size() != byteCount)
  3450. {
  3451. try
  3452. {
  3453. if(byteCount < getPixel().size())
  3454. {
  3455. editPixel().clear();
  3456. // free unused memory.
  3457. MFUInt8 tmp;
  3458. tmp.swap(editPixel());
  3459. }
  3460. editPixel().resize(byteCount);
  3461. }
  3462. catch(...)
  3463. {
  3464. FFATAL(("Image::createData : Couldn't allocate %u bytes!\n",
  3465. byteCount));
  3466. return false;
  3467. }
  3468. }
  3469. if(data)
  3470. {
  3471. memcpy(editData(), data, byteCount);
  3472. }
  3473. }
  3474. else
  3475. {
  3476. editPixel().clear();
  3477. }
  3478. return (getData() != NULL);
  3479. }
  3480. /*! Internal method to scale image data blocks
  3481. */
  3482. bool Image::scaleData(UInt8 *srcData,
  3483. Int32 srcW,
  3484. Int32 srcH,
  3485. Int32 srcD,
  3486. UInt8 *destData,
  3487. Int32 destW,
  3488. Int32 destH,
  3489. Int32 destD )
  3490. {
  3491. Real32 sx = Real32(srcW) / Real32(destW);
  3492. Real32 sy = Real32(srcH) / Real32(destH);
  3493. Real32 sz = Real32(srcD) / Real32(destD);
  3494. Int32 srcSize = srcW * srcH * srcD * getBpp();
  3495. // Int32 destDize = destW * destH * destD;
  3496. Int32 x, y, z, p;
  3497. UInt8 *slice, *line, *pixel;
  3498. if(destW == srcW && destH == srcH && destD == srcD)
  3499. {
  3500. // same size, just copy
  3501. memcpy(destData, srcData, srcSize);
  3502. }
  3503. else
  3504. { // different size, to 'nearest' copy
  3505. for(z = 0; z < destD; z++)
  3506. {
  3507. slice = srcData + int(sz * z) * getBpp() * srcW * srcH;
  3508. for(y = 0; y < destH; y++)
  3509. {
  3510. line = slice + int(sy * y) * getBpp() * srcW;
  3511. for(x = 0; x < destW; x++)
  3512. {
  3513. pixel = line + int(sx * x) * getBpp();
  3514. p = getBpp();
  3515. while(p--)
  3516. {
  3517. *destData++ = *pixel++;
  3518. }
  3519. }
  3520. }
  3521. }
  3522. }
  3523. return true;
  3524. }
  3525. /*! Assign operator. Does a copy of the given Image object.
  3526. */
  3527. Image &Image::operator=(const Image &image)
  3528. {
  3529. this->set((PixelFormat) image.getPixelFormat(),
  3530. image.getWidth (),
  3531. image.getHeight (),
  3532. image.getDepth (),
  3533. image.getMipMapCount(),
  3534. image.getFrameCount (),
  3535. image.getFrameDelay (),
  3536. image.getData (),
  3537. image.getDataType (),
  3538. true,
  3539. image.getSideCount ());
  3540. return *this;
  3541. }
  3542. /*! Less operator; compares the data sizes of the two images
  3543. */
  3544. bool Image::operator<(const Image &image)
  3545. {
  3546. return (getSize() < image.getSize()) ? true : false;
  3547. }
  3548. /*! Method to compare the object to another Image instance;
  3549. Checks first all parameter and afterwards the Image data;
  3550. */
  3551. bool Image::operator ==(const Image &image)
  3552. {
  3553. unsigned long i, s = getSize();
  3554. if((getWidth () == image.getWidth ()) &&
  3555. (getHeight () == image.getHeight ()) &&
  3556. (getDepth () == image.getDepth ()) &&
  3557. (getMipMapCount() == image.getMipMapCount()) &&
  3558. (getFrameCount () == image.getFrameCount ()) &&
  3559. (getFrameDelay () == image.getFrameDelay ()) &&
  3560. (getPixelFormat() == image.getPixelFormat()) &&
  3561. (getDataType () == image.getDataType ()) &&
  3562. (getSideCount () == image.getSideCount ()))
  3563. {
  3564. for(i = 0; i < s; ++i)
  3565. {
  3566. if(image.getData()[i] != getData()[i])
  3567. return false;
  3568. }
  3569. return true;
  3570. }
  3571. return false;
  3572. }
  3573. /*! Method to compare the object to another Image instance;
  3574. Checks first all parameter and afterwards the Image data;
  3575. */
  3576. bool Image::operator !=(const Image &image)
  3577. {
  3578. return !(*this == image);
  3579. }