PageRenderTime 301ms CodeModel.GetById 61ms app.highlight 199ms RepoModel.GetById 22ms app.codeStats 2ms

/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

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

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