/Source/System/Image/WS/OSGImage.cpp

https://github.com/msteners/OpenSGDevMaster_Toolbox · C++ · 4396 lines · 3567 code · 562 blank · 267 comment · 523 complexity · ff0725ce8aebf3f44e101061dc457d17 MD5 · raw file

Large files are truncated click here to view the full file

  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. #if __GNUC__ >= 4 || __GNUC_MINOR__ >=3
  39. #pragma GCC diagnostic warning "-Wsign-compare"
  40. #endif
  41. #ifdef WIN32
  42. #pragma warning( disable : 4018 )
  43. #endif
  44. //---------------------------------------------------------------------------
  45. // Includes
  46. //---------------------------------------------------------------------------
  47. #define OSG_COMPILEIMAGE
  48. #include <cstdlib>
  49. #include <cstdio>
  50. #include <algorithm>
  51. #include "OSGConfig.h"
  52. #include "OSGLog.h"
  53. #include "OSGImageGenericAtt.h"
  54. #include "OSGFieldContainerFields.h"
  55. #include "OSGFileSystem.h"
  56. #include "OSGImageFileHandler.h"
  57. #include "OSGSquish.h"
  58. /*
  59. #include "OSGPathHandler.h"
  60. #include "OSGSceneFileHandler.h"
  61. */
  62. #include "OSGImage.h"
  63. OSG_USING_NAMESPACE
  64. /*! \class OSG::Image
  65. 1D/2D/3D Image with various pixel types data, can also optional hold
  66. mipMap and simple multi-frame data.
  67. */
  68. /*------------------------------------------------------------------------*/
  69. /* static member */
  70. /*! Static dictionary to map pixelData values to the bytes per pixel
  71. (bpp) value.
  72. Internaly used in the createData() method.
  73. */
  74. UInt32 Image::_formatDic[][2] =
  75. {
  76. { OSG_A_PF, 1 },
  77. { OSG_I_PF, 1 },
  78. { OSG_L_PF, 1 },
  79. { OSG_LA_PF, 2 },
  80. { OSG_RGB_PF, 3 },
  81. { OSG_RGBA_PF, 4 },
  82. { OSG_BGR_PF, 3 },
  83. { OSG_BGRA_PF, 4 },
  84. { OSG_RGB_DXT1, 3 },
  85. { OSG_RGBA_DXT1, 4 },
  86. { OSG_RGBA_DXT3, 4 },
  87. { OSG_RGBA_DXT5, 4 },
  88. { OSG_ALPHA_INTEGER_PF, 1 },
  89. { OSG_RGB_INTEGER_PF, 3 },
  90. { OSG_RGBA_INTEGER_PF, 4 },
  91. { OSG_BGR_INTEGER_PF, 3 },
  92. { OSG_BGRA_INTEGER_PF, 4 },
  93. { OSG_LUMINANCE_INTEGER_PF, 1 },
  94. { OSG_LUMINANCE_ALPHA_INTEGER_PF, 2 }
  95. };
  96. Int32 Image::_typeDic[][2] =
  97. {
  98. { OSG_INVALID_IMAGEDATATYPE, 0 },
  99. { OSG_UINT8_IMAGEDATA, 1 },
  100. { OSG_UINT16_IMAGEDATA, 2 },
  101. { OSG_UINT32_IMAGEDATA, 4 },
  102. { OSG_FLOAT32_IMAGEDATA, 4 },
  103. { OSG_FLOAT16_IMAGEDATA, 2 },
  104. { OSG_INT16_IMAGEDATA, 2 },
  105. { OSG_INT32_IMAGEDATA, 4 }
  106. };
  107. /*----------------------------- class specific ----------------------------*/
  108. void Image::initMethod(InitPhase ePhase)
  109. {
  110. }
  111. /*! Inform parents, when image was changed
  112. */
  113. void Image::changed(ConstFieldMaskArg whichField,
  114. UInt32 origin,
  115. BitVector details)
  116. {
  117. const Image *pThis = this;
  118. MFParentFieldContainerPtr::const_iterator parentsIt =
  119. pThis->_mfParents.begin();
  120. MFParentFieldContainerPtr::const_iterator parentsEnd =
  121. pThis->_mfParents.end();
  122. while(parentsIt != parentsEnd)
  123. {
  124. (*parentsIt)->changed(
  125. TypeTraits<BitVector>::One << parentsIt.getParentFieldPos(),
  126. ChangedOrigin::Child,
  127. whichField);
  128. ++parentsIt;
  129. }
  130. if(0x0000 != (whichField & DataTypeFieldMask))
  131. {
  132. // Update internals
  133. Int32 mapSizeType = sizeof(_typeDic) / sizeof(UInt32[2]);
  134. UInt32 typeFormat = 0;
  135. Int32 i;
  136. for(i = 0; i < mapSizeType; i++)
  137. {
  138. if(_typeDic[i][0] == _sfDataType.getValue())
  139. {
  140. typeFormat = _typeDic[i][1];
  141. }
  142. }
  143. setComponentSize( typeFormat );
  144. }
  145. if(0x0000 != (whichField & (MipMapCountFieldMask |
  146. WidthFieldMask |
  147. HeightFieldMask |
  148. DepthFieldMask |
  149. PixelFormatFieldMask )))
  150. {
  151. setSideSize(calcMipmapSumSize(_sfMipMapCount.getValue()));
  152. }
  153. if(0x0000 != (whichField & (SideSizeFieldMask | SideCountFieldMask)))
  154. {
  155. setFrameSize(_sfSideSize.getValue() * _sfSideCount.getValue());
  156. }
  157. calcMipmapOffsets();
  158. Inherited::changed(whichField, origin, details);
  159. }
  160. /*----------------------------- output ------------------------------------*/
  161. void Image::dump( UInt32 ,
  162. const BitVector ) const
  163. {
  164. const Char8 *pfStr = "UNDEF_PIXEL_FORMAT";
  165. const Char8 *typeStr = "INVALID_IMAGEDATA_TYPE";
  166. switch(getPixelFormat())
  167. {
  168. case OSG_A_PF:
  169. pfStr = "ALPHA";
  170. break;
  171. case OSG_I_PF:
  172. pfStr = "INTENSITY";
  173. break;
  174. case OSG_L_PF:
  175. pfStr = "LUMINANCE";
  176. break;
  177. case OSG_LA_PF:
  178. pfStr = "LUMINANCE_ALPHA";
  179. break;
  180. case OSG_BGR_PF:
  181. pfStr = "BGR";
  182. break;
  183. case OSG_BGRA_PF:
  184. pfStr = "BGRA";
  185. break;
  186. case OSG_RGB_PF:
  187. pfStr = "RGB";
  188. break;
  189. case OSG_RGBA_PF:
  190. pfStr = "RGBA";
  191. break;
  192. case OSG_RGB_DXT1:
  193. pfStr = "RGB_DXT1";
  194. break;
  195. case OSG_RGBA_DXT1:
  196. pfStr = "RGBA_DXT1";
  197. break;
  198. case OSG_RGBA_DXT3:
  199. pfStr = "RGBA_DXT3";
  200. break;
  201. case OSG_RGBA_DXT5:
  202. pfStr = "RGBA_DXT5";
  203. break;
  204. case OSG_ALPHA_INTEGER_PF:
  205. pfStr = "ALPHA_INTEGER";
  206. break;
  207. case OSG_RGB_INTEGER_PF:
  208. pfStr = "RGB_INTEGER";
  209. break;
  210. case OSG_RGBA_INTEGER_PF:
  211. pfStr = "RGBA_INTEGER";
  212. break;
  213. case OSG_BGR_INTEGER_PF:
  214. pfStr = "BGR_INTEGER";
  215. break;
  216. case OSG_BGRA_INTEGER_PF:
  217. pfStr = "BGRA_INTEGER";
  218. break;
  219. case OSG_LUMINANCE_INTEGER_PF:
  220. pfStr = "LUMINANCE_INTEGER";
  221. break;
  222. case OSG_LUMINANCE_ALPHA_INTEGER_PF:
  223. pfStr = "LUMINANCE_ALPHA_INTEGER";
  224. break;
  225. default:
  226. pfStr = "UNKNOWN_PIXEL_FORMAT";
  227. break;
  228. };
  229. switch (getDataType())
  230. {
  231. case OSG_UINT8_IMAGEDATA:
  232. typeStr = "IMAGEDATA_TYPE UCHAR8";
  233. break;
  234. case OSG_UINT16_IMAGEDATA:
  235. typeStr = "IMAGEDATA_TYPE UCHAR16";
  236. break;
  237. case OSG_UINT32_IMAGEDATA:
  238. typeStr = "IMAGEDATA_TYPE UCHAR32";
  239. break;
  240. case OSG_FLOAT16_IMAGEDATA:
  241. typeStr = "IMAGEDATA_TYPE FLOAT16";
  242. break;
  243. case OSG_FLOAT32_IMAGEDATA:
  244. typeStr = "IMAGEDATA_TYPE FLOAT32";
  245. break;
  246. case OSG_INT16_IMAGEDATA:
  247. typeStr = "IMAGEDATA_TYPE INT16";
  248. break;
  249. case OSG_INT32_IMAGEDATA:
  250. typeStr = "IMAGEDATA_TYPE INT32";
  251. break;
  252. default:
  253. typeStr = "UNKNOWN_IMAGEDATA_TYPE";
  254. break;
  255. };
  256. FLOG (("ImageDump: %s; %d/%d/%d; #mm: %d, side %d, #frame: %d, "
  257. "frameDelay %g, dataType %s, size: %ld\n",
  258. pfStr,
  259. getWidth(),
  260. getHeight(),
  261. getDepth(),
  262. getMipMapCount(),
  263. getSideCount(),
  264. getFrameCount(),
  265. getFrameDelay(),
  266. typeStr,
  267. getSize()));
  268. }
  269. // Return the number of components per pixel.
  270. UInt8 Image::getComponents(void) const
  271. {
  272. UInt16 mapSizeFormat = sizeof(_formatDic) / sizeof(UInt32[2]);
  273. for(UInt16 i = 0; i < mapSizeFormat; i++)
  274. {
  275. if(_formatDic[i][0] == getPixelFormat())
  276. return _formatDic[i][1];
  277. }
  278. FWARNING(("Image::getComponents: image %p has unknown pixel format 0x%x!",
  279. this, getPixelFormat()));
  280. return 0;
  281. }
  282. /*------------------------------ set object data --------------------------*/
  283. /*! method to set the image data. Use the doCopy parameter to specify, whether
  284. the method should copy or link the pixel data.
  285. */
  286. bool Image::set( UInt32 pF,
  287. Int32 w,
  288. Int32 h,
  289. Int32 d,
  290. Int32 mmS,
  291. Int32 fS,
  292. Time fD,
  293. const UChar8 *da,
  294. Int32 t,
  295. bool allocMem,
  296. Int32 sS)
  297. {
  298. setPixelFormat(pF );
  299. setWidth (osgMax ( 1, w ));
  300. setHeight (osgMax ( 1, h ));
  301. setDepth (osgMax ( 1, d ));
  302. setMipMapCount(osgMax ( 1, mmS));
  303. setSideCount (osgMax ( 1, sS ));
  304. setFrameCount (osgMax ( 1, fS ));
  305. setFrameDelay (fD);
  306. setDataType (t );
  307. calcMipmapOffsets();
  308. return createData(da, allocMem);
  309. }
  310. /*! method to set the image from another image object.
  311. Use the doCopy parameter to specify, whether
  312. the method should copy or link the pixel data.
  313. */
  314. bool Image::set(Image *image)
  315. {
  316. this->set(image->getPixelFormat(),
  317. image->getWidth (),
  318. image->getHeight (),
  319. image->getDepth (),
  320. image->getMipMapCount(),
  321. image->getFrameCount (),
  322. image->getFrameDelay (),
  323. image->getData (),
  324. image->getDataType (),
  325. true,
  326. image->getSideCount ());
  327. return true;
  328. }
  329. /*! method to set only the image pixel data, all parameter (e. pixelFormat
  330. width,height and depth) stay the same
  331. */
  332. bool Image::setData(const UChar8 *da)
  333. {
  334. if(da)
  335. {
  336. createData(da);
  337. }
  338. else
  339. {
  340. FWARNING(("Image::setData(Null) call\n"));
  341. }
  342. return (da ? true : false);
  343. }
  344. void Image::clearData(void)
  345. {
  346. editMFPixel()->clear();
  347. }
  348. /*! method to update just a subregion of the image data
  349. all paramter (e. pixelFormat,width,height,depth) stay the same
  350. */
  351. bool Image::setSubData( Int32 offX,
  352. Int32 offY,
  353. Int32 offZ,
  354. Int32 srcW,
  355. Int32 srcH,
  356. Int32 srcD,
  357. const UInt8 *src )
  358. {
  359. UChar8 *dest = editData();
  360. UInt64 lineSize;
  361. FDEBUG(( "Image::setSubData (%d %d %d) - (%d %d %d) - src %p\n",
  362. offX, offY, offZ, srcW, srcH, srcD, src ));
  363. if (hasCompressedData())
  364. {
  365. FFATAL (("Invalid Image::setSubData for compressed image\n"));
  366. return false;
  367. }
  368. if(!src || !dest)
  369. {
  370. FFATAL(("Invalid data pointer in Image::setSubData\n"));
  371. return false;
  372. }
  373. // determine the area to actually copy
  374. UInt32 xMin = osgMax(0, offX);
  375. UInt32 yMin = osgMax(0, offY);
  376. UInt32 zMin = osgMax(0, offZ);
  377. UInt32 xMax = osgMin(getWidth (), offX + srcW);
  378. UInt32 yMax = osgMin(getHeight(), offY + srcH);
  379. UInt32 zMax = osgMin(getDepth (), offZ + srcD);
  380. // fill the destination buffer with the subdata
  381. UInt32 destIdx, srcIdx = 0;
  382. for(UInt32 z = zMin; z < zMax; z++)
  383. {
  384. for(UInt32 y = yMin; y < yMax; y++)
  385. {
  386. lineSize = (xMax - xMin) * getBpp();
  387. destIdx = ((z * getHeight() + y) * getWidth() + xMin) * getBpp();
  388. memcpy (&dest[destIdx], &src[srcIdx], size_t(lineSize));
  389. srcIdx += Int32((srcW - (xMax - xMin)) * getBpp() + lineSize);
  390. }
  391. srcIdx += (srcH - (yMax - yMin)) * srcW * getBpp();
  392. }
  393. return true;
  394. }
  395. /*! The Image is not just a 2D container. The class can hold 3D (volume)
  396. and movie data. If we have 3D/singleFrame or 2D/multiFrame data without
  397. mipmaps we can flip between this two formats by just swapping the
  398. getFrameCount() and getDepth() values.
  399. */
  400. bool Image::flipDepthFrameData(void)
  401. {
  402. bool retCode = false;
  403. Int32 value;
  404. if((getMipMapCount() == 1) &&
  405. ((getFrameCount() == 1) || (getDepth() == 1)))
  406. {
  407. value = getFrameCount();
  408. setFrameCount(getDepth());
  409. setDepth (value );
  410. retCode = true;
  411. }
  412. else
  413. {
  414. FWARNING (("Cant flipDepthFrameData(); invalid data layout\n"));
  415. }
  416. return retCode;
  417. }
  418. /*! This method is used by the parser to fill the image with
  419. string pixel data. It expects the data in VRML PixelTexture Format.
  420. */
  421. bool Image::addValue(const char *value)
  422. {
  423. static Image *currentImage = 0;
  424. static UChar8 *currentData = 0;
  425. Int64 j;
  426. Int64 v;
  427. bool isHead = strchr(value, ' ') ? true : false;
  428. if (hasCompressedData())
  429. {
  430. FFATAL (("Invalid Image::addValue for compressed image\n"));
  431. return false;
  432. }
  433. // make sure we only read one image at a time
  434. if(currentImage == this)
  435. {
  436. if(isHead)
  437. {
  438. FDEBUG(("Start new read cycle in image::addValue()\n"));
  439. }
  440. }
  441. else
  442. {
  443. if(!isHead)
  444. {
  445. FFATAL(("Additional image date for different image\n"));
  446. }
  447. }
  448. currentImage = this;
  449. if(isHead == true)
  450. {
  451. Int32 width;
  452. Int32 height;
  453. Int32 pixelDepth;
  454. PixelFormat pf = Image::OSG_INVALID_PF;
  455. // read the head
  456. sscanf(value, "%d %d %d", &width, &height, &pixelDepth);
  457. FDEBUG(("Image::addValue() set: w/h/bpp: %d/%d/%d\n",
  458. width, height, pixelDepth));
  459. switch(getDataType())
  460. {
  461. case OSG_UINT8_IMAGEDATA:
  462. switch(pixelDepth)
  463. {
  464. case 1:
  465. pf = OSG::Image::OSG_L_PF;
  466. break;
  467. case 2:
  468. pf = OSG::Image::OSG_LA_PF;
  469. break;
  470. case 3:
  471. pf = OSG::Image::OSG_RGB_PF;
  472. break;
  473. case 4:
  474. pf = OSG::Image::OSG_RGBA_PF;
  475. break;
  476. default:
  477. pf = OSG::Image::OSG_INVALID_PF;
  478. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  479. break;
  480. }
  481. break;
  482. case OSG_UINT16_IMAGEDATA:
  483. switch(pixelDepth)
  484. {
  485. case 2:
  486. pf = OSG::Image::OSG_L_PF;
  487. break;
  488. case 4:
  489. pf = OSG::Image::OSG_LA_PF;
  490. break;
  491. case 6:
  492. pf = OSG::Image::OSG_RGB_PF;
  493. break;
  494. case 8:
  495. pf = OSG::Image::OSG_RGBA_PF;
  496. break;
  497. default:
  498. pf = OSG::Image::OSG_INVALID_PF;
  499. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  500. break;
  501. }
  502. break;
  503. case OSG_UINT32_IMAGEDATA:
  504. switch(pixelDepth)
  505. {
  506. case 4:
  507. pf = OSG::Image::OSG_L_PF;
  508. break;
  509. case 8:
  510. pf = OSG::Image::OSG_LA_PF;
  511. break;
  512. case 12:
  513. pf = OSG::Image::OSG_RGB_PF;
  514. break;
  515. case 16:
  516. pf = OSG::Image::OSG_RGBA_PF;
  517. break;
  518. default:
  519. pf = OSG::Image::OSG_INVALID_PF;
  520. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  521. break;
  522. }
  523. break;
  524. case OSG_FLOAT32_IMAGEDATA:
  525. switch(pixelDepth)
  526. {
  527. case 4:
  528. pf = OSG::Image::OSG_L_PF;
  529. break;
  530. case 8:
  531. pf = OSG::Image::OSG_LA_PF;
  532. break;
  533. case 12:
  534. pf = OSG::Image::OSG_RGB_PF;
  535. break;
  536. case 16:
  537. pf = OSG::Image::OSG_RGBA_PF;
  538. break;
  539. default:
  540. pf = OSG::Image::OSG_INVALID_PF;
  541. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  542. break;
  543. }
  544. break;
  545. case OSG_FLOAT16_IMAGEDATA:
  546. switch(pixelDepth)
  547. {
  548. case 2:
  549. pf = OSG::Image::OSG_L_PF;
  550. break;
  551. case 4:
  552. pf = OSG::Image::OSG_LA_PF;
  553. break;
  554. case 6:
  555. pf = OSG::Image::OSG_RGB_PF;
  556. break;
  557. case 8:
  558. pf = OSG::Image::OSG_RGBA_PF;
  559. break;
  560. default:
  561. pf = OSG::Image::OSG_INVALID_PF;
  562. FFATAL(("Invalid pixel depth: %d\n", pixelDepth));
  563. break;
  564. }
  565. break;
  566. case OSG_INT16_IMAGEDATA:
  567. case OSG_INT32_IMAGEDATA:
  568. {
  569. FFATAL((" 'addValue' NYI\n "));
  570. }
  571. break;
  572. default:
  573. setDataType(OSG_INVALID_IMAGEDATATYPE);
  574. FFATAL(("Invalid type of image data: %d\n", getDataType()));
  575. }
  576. if(pf != 0 && (width > 0) && (height > 0))
  577. {
  578. set(pf, width, height);
  579. currentData = editData();
  580. }
  581. else
  582. {
  583. currentData = NULL;
  584. }
  585. }
  586. else
  587. {
  588. if(currentData != NULL)
  589. {
  590. // add data
  591. // TODO; should we check the bounds, should be done by the parser
  592. v = strtoul(value, 0, strchr(value, 'x') ? 16 : 10);
  593. for(j = getBpp(); j--;)
  594. {
  595. *currentData++ = UChar8( (v >> (8 * j)) & 255 );
  596. }
  597. }
  598. }
  599. return currentData ? true : false;
  600. }
  601. /*! It is a simple method to reformat the image pixelFormat (not the size).
  602. So you can for example convert a RGBA to RGB or RGB to Grey image.
  603. */
  604. bool Image::reformat(const Image::PixelFormat pixelFormat,
  605. Image *destination,
  606. Int32 iCompressionFlags)
  607. {
  608. UChar8 *data = NULL;
  609. const UChar8 *sourceData = NULL;
  610. UInt32 srcI, destI, destSize = 0;
  611. UInt32 sum;
  612. Real64 sumReal;
  613. ImageUnrecPtr dest(destination);
  614. if (hasCompressedData())
  615. {
  616. FFATAL (("Invalid Image::reformat for compressed image\n"));
  617. return false;
  618. }
  619. if(destination == NULL)
  620. {
  621. dest = Image::create();
  622. }
  623. FINFO(("Try to reformat image from pixelDepth %d to %d\n",
  624. getPixelFormat(),
  625. pixelFormat ));
  626. if(iCompressionFlags == 0)
  627. {
  628. iCompressionFlags = (osgsquish::kColourMetricPerceptual |
  629. osgsquish::kColourRangeFit );
  630. }
  631. iCompressionFlags &= ~0x07;
  632. // TODO !!! code all the cases !!!
  633. if(getSize() != 0 &&
  634. pixelFormat != OSG_INVALID_PF &&
  635. (destination != 0 || (pixelFormat != static_cast<Image::PixelFormat>(getPixelFormat()))))
  636. {
  637. dest->set(pixelFormat,
  638. getWidth (),
  639. getHeight (),
  640. getDepth (),
  641. getMipMapCount(),
  642. getFrameCount (),
  643. getFrameDelay (),
  644. NULL,
  645. getDataType (),
  646. true,
  647. getSideCount ());
  648. sourceData = getData();
  649. data = dest->editData();
  650. destSize = dest->getSize();
  651. const UInt16 *sourceDataUC16 =
  652. reinterpret_cast<const UInt16 *>(sourceData);
  653. UInt16 *destDataUC16 = reinterpret_cast<UInt16 *>(data);
  654. const UInt32 *sourceDataUC32 =
  655. reinterpret_cast<const UInt32 *>(sourceData);
  656. UInt32 *destDataUC32 = reinterpret_cast<UInt32 *>(data);
  657. const Real32 *sourceDataF32 =
  658. reinterpret_cast<const Real32 *>(sourceData);
  659. Real32 *destDataF32 = reinterpret_cast<Real32 *>(data);
  660. const Real16 *sourceDataH16 =
  661. reinterpret_cast<const Real16 *>(sourceData);
  662. Real16 *destDataH16 = reinterpret_cast<Real16 *>(data);
  663. if(data)
  664. {
  665. switch (getPixelFormat())
  666. {
  667. //-----------------------------------------------------
  668. case OSG_A_PF:
  669. switch (pixelFormat)
  670. {
  671. case OSG_A_PF:
  672. case OSG_I_PF:
  673. case OSG_L_PF:
  674. switch (getDataType())
  675. {
  676. case OSG_UINT8_IMAGEDATA:
  677. case OSG_UINT16_IMAGEDATA:
  678. case OSG_UINT32_IMAGEDATA:
  679. case OSG_FLOAT32_IMAGEDATA:
  680. case OSG_FLOAT16_IMAGEDATA:
  681. memcpy (data, getData(), destSize);
  682. break;
  683. default:
  684. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  685. break;
  686. }
  687. break;
  688. case OSG_LA_PF:
  689. switch (getDataType())
  690. {
  691. case OSG_UINT8_IMAGEDATA:
  692. for (srcI = destI = 0; destI < destSize;)
  693. {
  694. data[destI++] = sourceData[srcI];
  695. data[destI++] = sourceData[srcI++];
  696. }
  697. break;
  698. case OSG_UINT16_IMAGEDATA:
  699. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  700. {
  701. destDataUC16[destI++] = sourceDataUC16[srcI];
  702. destDataUC16[destI++] = sourceDataUC16[srcI++];
  703. }
  704. break;
  705. case OSG_UINT32_IMAGEDATA:
  706. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  707. {
  708. destDataUC32[destI++] = sourceDataUC32[srcI];
  709. destDataUC32[destI++] = sourceDataUC32[srcI++];
  710. }
  711. break;
  712. case OSG_FLOAT32_IMAGEDATA:
  713. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  714. {
  715. destDataF32[destI++] = sourceDataF32[srcI];
  716. destDataF32[destI++] = sourceDataF32[srcI++];
  717. }
  718. break;
  719. case OSG_FLOAT16_IMAGEDATA:
  720. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  721. {
  722. destDataH16[destI++] = sourceDataH16[srcI];
  723. destDataH16[destI++] = sourceDataH16[srcI++];
  724. }
  725. break;
  726. default:
  727. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  728. break;
  729. }
  730. break;
  731. case OSG_RGB_PF:
  732. switch (getDataType())
  733. {
  734. case OSG_UINT8_IMAGEDATA:
  735. for (srcI = destI = 0; destI < destSize;)
  736. {
  737. data[destI++] = sourceData[srcI];
  738. data[destI++] = sourceData[srcI];
  739. data[destI++] = sourceData[srcI++];
  740. }
  741. break;
  742. case OSG_UINT16_IMAGEDATA:
  743. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  744. {
  745. destDataUC16[destI++] = sourceDataUC16[srcI];
  746. destDataUC16[destI++] = sourceDataUC16[srcI];
  747. destDataUC16[destI++] = sourceDataUC16[srcI++];
  748. }
  749. break;
  750. case OSG_UINT32_IMAGEDATA:
  751. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  752. {
  753. destDataUC32[destI++] = sourceDataUC32[srcI];
  754. destDataUC32[destI++] = sourceDataUC32[srcI];
  755. destDataUC32[destI++] = sourceDataUC32[srcI++];
  756. }
  757. break;
  758. case OSG_FLOAT32_IMAGEDATA:
  759. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  760. {
  761. destDataF32[destI++] = sourceDataF32[srcI];
  762. destDataF32[destI++] = sourceDataF32[srcI];
  763. destDataF32[destI++] = sourceDataF32[srcI++];
  764. }
  765. break;
  766. case OSG_FLOAT16_IMAGEDATA:
  767. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  768. {
  769. destDataH16[destI++] = sourceDataH16[srcI];
  770. destDataH16[destI++] = sourceDataH16[srcI];
  771. destDataH16[destI++] = sourceDataH16[srcI++];
  772. }
  773. break;
  774. default:
  775. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  776. break;
  777. }
  778. break;
  779. case OSG_RGBA_PF:
  780. switch (getDataType())
  781. {
  782. case OSG_UINT8_IMAGEDATA:
  783. for (srcI = destI = 0; destI < destSize;)
  784. {
  785. data[destI++] = sourceData[srcI];
  786. data[destI++] = sourceData[srcI];
  787. data[destI++] = sourceData[srcI];
  788. data[destI++] = sourceData[srcI++];
  789. }
  790. break;
  791. case OSG_UINT16_IMAGEDATA:
  792. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  793. {
  794. destDataUC16[destI++] = sourceDataUC16[srcI];
  795. destDataUC16[destI++] = sourceDataUC16[srcI];
  796. destDataUC16[destI++] = sourceDataUC16[srcI];
  797. destDataUC16[destI++] = sourceDataUC16[srcI++];
  798. }
  799. break;
  800. case OSG_UINT32_IMAGEDATA:
  801. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  802. {
  803. destDataUC32[destI++] = sourceDataUC32[srcI];
  804. destDataUC32[destI++] = sourceDataUC32[srcI];
  805. destDataUC32[destI++] = sourceDataUC32[srcI];
  806. destDataUC32[destI++] = sourceDataUC32[srcI++];
  807. }
  808. break;
  809. case OSG_FLOAT32_IMAGEDATA:
  810. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  811. {
  812. destDataF32[destI++] = sourceDataF32[srcI];
  813. destDataF32[destI++] = sourceDataF32[srcI];
  814. destDataF32[destI++] = sourceDataF32[srcI];
  815. destDataF32[destI++] = sourceDataF32[srcI++];
  816. }
  817. break;
  818. case OSG_FLOAT16_IMAGEDATA:
  819. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  820. {
  821. destDataH16[destI++] = sourceDataH16[srcI];
  822. destDataH16[destI++] = sourceDataH16[srcI];
  823. destDataH16[destI++] = sourceDataH16[srcI];
  824. destDataH16[destI++] = sourceDataH16[srcI++];
  825. }
  826. break;
  827. default:
  828. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  829. break;
  830. }
  831. break;
  832. default:
  833. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  834. break;
  835. }
  836. break;
  837. //-----------------------------------------------------
  838. case OSG_I_PF:
  839. switch (pixelFormat)
  840. {
  841. case OSG_A_PF:
  842. case OSG_I_PF:
  843. case OSG_L_PF:
  844. switch (getDataType())
  845. {
  846. case OSG_UINT8_IMAGEDATA:
  847. memcpy (data, getData(), destSize);
  848. break;
  849. case OSG_UINT16_IMAGEDATA:
  850. memcpy (data, getData(), destSize);
  851. break;
  852. case OSG_UINT32_IMAGEDATA:
  853. memcpy (data, getData(), destSize);
  854. break;
  855. case OSG_FLOAT32_IMAGEDATA:
  856. memcpy (data, getData(), destSize);
  857. break;
  858. case OSG_FLOAT16_IMAGEDATA:
  859. memcpy (data, getData(), destSize);
  860. break;
  861. default:
  862. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  863. break;
  864. }
  865. break;
  866. case OSG_LA_PF:
  867. switch (getDataType())
  868. {
  869. case OSG_UINT8_IMAGEDATA:
  870. for (srcI = destI = 0; destI < destSize;)
  871. {
  872. data[destI++] = sourceData[srcI];
  873. data[destI++] = sourceData[srcI++];
  874. }
  875. break;
  876. case OSG_UINT16_IMAGEDATA:
  877. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  878. {
  879. destDataUC16[destI++] = sourceDataUC16[srcI];
  880. destDataUC16[destI++] = sourceDataUC16[srcI++];
  881. }
  882. break;
  883. case OSG_UINT32_IMAGEDATA:
  884. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  885. {
  886. destDataUC32[destI++] = sourceDataUC32[srcI];
  887. destDataUC32[destI++] = sourceDataUC32[srcI++];
  888. }
  889. break;
  890. case OSG_FLOAT32_IMAGEDATA:
  891. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  892. {
  893. destDataF32[destI++] = sourceDataF32[srcI];
  894. destDataF32[destI++] = sourceDataF32[srcI++];
  895. }
  896. break;
  897. case OSG_FLOAT16_IMAGEDATA:
  898. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  899. {
  900. destDataH16[destI++] = sourceDataH16[srcI];
  901. destDataH16[destI++] = sourceDataH16[srcI++];
  902. }
  903. break;
  904. default:
  905. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  906. break;
  907. }
  908. break;
  909. case OSG_RGB_PF:
  910. switch (getDataType())
  911. {
  912. case OSG_UINT8_IMAGEDATA:
  913. for (srcI = destI = 0; destI < destSize;)
  914. {
  915. data[destI++] = sourceData[srcI];
  916. data[destI++] = sourceData[srcI];
  917. data[destI++] = sourceData[srcI++];
  918. }
  919. break;
  920. case OSG_UINT16_IMAGEDATA:
  921. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  922. {
  923. destDataUC16[destI++] = sourceDataUC16[srcI];
  924. destDataUC16[destI++] = sourceDataUC16[srcI];
  925. destDataUC16[destI++] = sourceDataUC16[srcI++];
  926. }
  927. break;
  928. case OSG_UINT32_IMAGEDATA:
  929. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  930. {
  931. destDataUC32[destI++] = sourceDataUC32[srcI];
  932. destDataUC32[destI++] = sourceDataUC32[srcI];
  933. destDataUC32[destI++] = sourceDataUC32[srcI++];
  934. }
  935. break;
  936. case OSG_FLOAT32_IMAGEDATA:
  937. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  938. {
  939. destDataF32[destI++] = sourceDataF32[srcI];
  940. destDataF32[destI++] = sourceDataF32[srcI];
  941. destDataF32[destI++] = sourceDataF32[srcI++];
  942. }
  943. break;
  944. case OSG_FLOAT16_IMAGEDATA:
  945. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  946. {
  947. destDataH16[destI++] = sourceDataH16[srcI];
  948. destDataH16[destI++] = sourceDataH16[srcI];
  949. destDataH16[destI++] = sourceDataH16[srcI++];
  950. }
  951. break;
  952. default:
  953. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  954. break;
  955. }
  956. break;
  957. case OSG_RGBA_PF:
  958. switch (getDataType())
  959. {
  960. case OSG_UINT8_IMAGEDATA:
  961. for (srcI = destI = 0; destI < destSize;)
  962. {
  963. data[destI++] = sourceData[srcI];
  964. data[destI++] = sourceData[srcI];
  965. data[destI++] = sourceData[srcI];
  966. data[destI++] = sourceData[srcI++];
  967. }
  968. break;
  969. case OSG_UINT16_IMAGEDATA:
  970. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  971. {
  972. destDataUC16[destI++] = sourceDataUC16[srcI];
  973. destDataUC16[destI++] = sourceDataUC16[srcI];
  974. destDataUC16[destI++] = sourceDataUC16[srcI];
  975. destDataUC16[destI++] = sourceDataUC16[srcI++];
  976. }
  977. break;
  978. case OSG_UINT32_IMAGEDATA:
  979. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  980. {
  981. destDataUC32[destI++] = sourceDataUC32[srcI];
  982. destDataUC32[destI++] = sourceDataUC32[srcI];
  983. destDataUC32[destI++] = sourceDataUC32[srcI];
  984. destDataUC32[destI++] = sourceDataUC32[srcI++];
  985. }
  986. break;
  987. case OSG_FLOAT32_IMAGEDATA:
  988. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  989. {
  990. destDataF32[destI++] = sourceDataF32[srcI];
  991. destDataF32[destI++] = sourceDataF32[srcI];
  992. destDataF32[destI++] = sourceDataF32[srcI];
  993. destDataF32[destI++] = sourceDataF32[srcI++];
  994. }
  995. break;
  996. case OSG_FLOAT16_IMAGEDATA:
  997. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  998. {
  999. destDataH16[destI++] = sourceDataH16[srcI];
  1000. destDataH16[destI++] = sourceDataH16[srcI];
  1001. destDataH16[destI++] = sourceDataH16[srcI];
  1002. destDataH16[destI++] = sourceDataH16[srcI++];
  1003. }
  1004. break;
  1005. default:
  1006. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1007. break;
  1008. }
  1009. break;
  1010. default:
  1011. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1012. break;
  1013. }
  1014. break;
  1015. //-----------------------------------------------------
  1016. case OSG_L_PF:
  1017. switch (pixelFormat)
  1018. {
  1019. case OSG_A_PF:
  1020. case OSG_I_PF:
  1021. case OSG_L_PF:
  1022. switch (getDataType())
  1023. {
  1024. case OSG_UINT8_IMAGEDATA:
  1025. memcpy (data, getData(), destSize);
  1026. break;
  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. case OSG_FLOAT32_IMAGEDATA:
  1034. memcpy (data, getData(), destSize);
  1035. break;
  1036. case OSG_FLOAT16_IMAGEDATA:
  1037. memcpy (data, getData(), destSize);
  1038. break;
  1039. default:
  1040. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1041. break;
  1042. }
  1043. break;
  1044. case OSG_LA_PF:
  1045. switch (getDataType())
  1046. {
  1047. case OSG_UINT8_IMAGEDATA:
  1048. for (srcI = destI = 0; destI < destSize;)
  1049. {
  1050. data[destI++] = sourceData[srcI];
  1051. data[destI++] = sourceData[srcI++];
  1052. }
  1053. break;
  1054. case OSG_UINT16_IMAGEDATA:
  1055. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1056. {
  1057. destDataUC16[destI++] = sourceDataUC16[srcI];
  1058. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1059. }
  1060. break;
  1061. case OSG_UINT32_IMAGEDATA:
  1062. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1063. {
  1064. destDataUC32[destI++] = sourceDataUC32[srcI];
  1065. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1066. }
  1067. break;
  1068. case OSG_FLOAT32_IMAGEDATA:
  1069. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1070. {
  1071. destDataF32[destI++] = sourceDataF32[srcI];
  1072. destDataF32[destI++] = sourceDataF32[srcI++];
  1073. }
  1074. break;
  1075. case OSG_FLOAT16_IMAGEDATA:
  1076. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1077. {
  1078. destDataH16[destI++] = sourceDataH16[srcI];
  1079. destDataH16[destI++] = sourceDataH16[srcI++];
  1080. }
  1081. break;
  1082. default:
  1083. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));
  1084. break;
  1085. }
  1086. break;
  1087. case OSG_RGB_PF:
  1088. switch (getDataType())
  1089. {
  1090. case OSG_UINT8_IMAGEDATA:
  1091. for (srcI = destI = 0; destI < destSize;)
  1092. {
  1093. data[destI++] = sourceData[srcI];
  1094. data[destI++] = sourceData[srcI];
  1095. data[destI++] = sourceData[srcI++];
  1096. }
  1097. break;
  1098. case OSG_UINT16_IMAGEDATA:
  1099. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1100. {
  1101. destDataUC16[destI++] = sourceDataUC16[srcI];
  1102. destDataUC16[destI++] = sourceDataUC16[srcI];
  1103. destDataUC16[destI++] = sourceDataUC16[srcI++];
  1104. }
  1105. break;
  1106. case OSG_UINT32_IMAGEDATA:
  1107. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1108. {
  1109. destDataUC32[destI++] = sourceDataUC32[srcI];
  1110. destDataUC32[destI++] = sourceDataUC32[srcI];
  1111. destDataUC32[destI++] = sourceDataUC32[srcI++];
  1112. }
  1113. break;
  1114. case OSG_FLOAT32_IMAGEDATA:
  1115. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1116. {
  1117. destDataF32[destI++] = sourceDataF32[srcI];
  1118. destDataF32[destI++] = sourceDataF32[srcI];
  1119. destDataF32[destI++] = sourceDataF32[srcI++];
  1120. }
  1121. break;
  1122. case OSG_FLOAT16_IMAGEDATA:
  1123. for (srcI = destI = 0; destI < destSize/getComponentSize();)
  1124. {
  1125. destDataH16[destI++] = sourceDataH16[srcI];
  1126. destDataH16[destI++] = sourceDataH16[srcI];
  1127. destDataH16[destI++] = sourceDataH16[srcI++];
  1128. }
  1129. break;
  1130. default:
  1131. FWARNING (( "Invalid IMAGE_DATA_TYPE\n" ));