PageRenderTime 60ms CodeModel.GetById 24ms 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

Large files files are truncated, but you can 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. //---------------------------------------------------------------------------
  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];

Large files files are truncated, but you can click here to view the full file