bool CIMGCodec::Encode( const CImage& inputImage , CORE::CIOAccess& encodedOutput ) {GUCEF_TRACE; if ( inputImage.HasFrames() ) { CORE::CDynamicBuffer inputBuffer( 102400, true ); CORE::CDynamicBufferAccess bufferAccess( &inputBuffer, false ); // Fill our header TImageInfo imageInfo; imageInfo.version = GUCEF_IMAGE_TIMAGEINFO_VERSION; imageInfo.nrOfFramesInImage = inputImage.GetFrameCount(); // write header bufferAccess.Write( &imageInfo, sizeof( TImageInfo ), 1 ); // Now we add each frame's info + mipmap info TImageFrameInfo frameInfo; frameInfo.version = GUCEF_IMAGE_TIMAGEFRAMEINFO_VERSION; TImageMipMapLevelInfo mipMapInfo; mipMapInfo.version = GUCEF_IMAGE_TIMAGEMIPMAPLEVELINFO_VERSION; const CImage::TMipMapList* mipMapList = NULL; const TPixelMapPtr* pixelMap = NULL; for ( UInt32 frameNr=0; frameNr<imageInfo.nrOfFramesInImage; ++frameNr ) { mipMapList = &inputImage.GetFrame( frameNr ); frameInfo.nrOfMipmapLevels = static_cast< UInt32 >( mipMapList->size() ); bufferAccess.Write( &frameInfo, sizeof( TImageFrameInfo ), 1 ); // Now we add the info for each mipmap level for ( UInt32 mipLvl=0; mipLvl<frameInfo.nrOfMipmapLevels; ++mipLvl ) { pixelMap = &(*mipMapList)[ mipLvl ]; mipMapInfo.frameWidth = (*pixelMap)->GetWidthInPixels(); mipMapInfo.frameHeight = (*pixelMap)->GetHeightInPixels(); mipMapInfo.pixelStorageFormat = (*pixelMap)->GetPixelStorageFormat(); mipMapInfo.pixelComponentDataType = (*pixelMap)->GetPixelComponentDataType(); bufferAccess.Write( &mipMapInfo, sizeof( TImageMipMapLevelInfo ), 1 ); } } // Now it is time to add the pixel data itself for ( UInt32 frameNr=0; frameNr<imageInfo.nrOfFramesInImage; ++frameNr ) { mipMapList = &inputImage.GetFrame( frameNr ); for ( UInt32 mipLvl=0; mipLvl<mipMapList->size(); ++mipLvl ) { pixelMap = &(*mipMapList)[ mipLvl ]; bufferAccess.Write( (*pixelMap)->GetDataPtr(), (*pixelMap)->GetTotalSizeInBytes(), 1 ); } } // We have now merged all the image object data into a single buffer using the decoded 'ImageCodec' format // It is time to perform the actual Encode() return Encode( bufferAccess , encodedOutput ); } return false; }