PageRenderTime 683ms CodeModel.GetById 342ms app.highlight 267ms RepoModel.GetById 55ms app.codeStats 1ms

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

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

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