CFX_ByteString CPWL_Image::GetImageAppStream() { CFX_ByteTextBuf sAppStream; CFX_ByteString sAlias = GetImageAlias(); CFX_FloatRect rcPlate = GetClientRect(); CFX_Matrix mt; mt.SetReverse(GetImageMatrix()); FX_FLOAT fHScale = 1.0f; FX_FLOAT fVScale = 1.0f; GetScale(fHScale, fVScale); FX_FLOAT fx = 0.0f; FX_FLOAT fy = 0.0f; GetImageOffset(fx, fy); if (m_pPDFStream && sAlias.GetLength() > 0) { sAppStream << "q\n"; sAppStream << rcPlate.left << " " << rcPlate.bottom << " " << rcPlate.right - rcPlate.left << " " << rcPlate.top - rcPlate.bottom << " re W n\n"; sAppStream << fHScale << " 0 0 " << fVScale << " " << rcPlate.left + fx << " " << rcPlate.bottom + fy << " cm\n"; sAppStream << mt.GetA() << " " << mt.GetB() << " " << mt.GetC() << " " << mt.GetD() << " " << mt.GetE() << " " << mt.GetF() << " cm\n"; sAppStream << "0 g 0 G 1 w /" << sAlias.AsStringC() << " Do\n" << "Q\n"; } return sAppStream.MakeString(); }
//----------------------------------------------------------------------------- // Returns a pointer to the data associated with a particular frame, face, and mip level //----------------------------------------------------------------------------- unsigned char *CVTFTexture::ImageData( int iFrame, int iFace, int iMipLevel ) { Assert( m_pImageData ); int iOffset = GetImageOffset( iFrame, iFace, iMipLevel, m_Format ); return &m_pImageData[iOffset]; }
//----------------------------------------------------------------------------- // Converts the texture's image format. Use IMAGE_FORMAT_DEFAULT // if you want to be able to use various tool functions below //----------------------------------------------------------------------------- void CVTFTexture::ConvertImageFormat( ImageFormat fmt, bool bNormalToDUDV ) { if ( !m_pImageData ) return; if (fmt == IMAGE_FORMAT_DEFAULT) fmt = IMAGE_FORMAT_RGBA8888; if( bNormalToDUDV && !( fmt == IMAGE_FORMAT_UV88 || fmt == IMAGE_FORMAT_UVWQ8888 ) ) { Assert( 0 ); return; } if (m_Format == fmt) return; // FIXME: Should this be re-written to not do an allocation? int iConvertedSize = ComputeTotalSize( fmt ); unsigned char *pConvertedImage = (unsigned char*)MemAllocScratch(iConvertedSize); for (int iMip = 0; iMip < m_nMipCount; ++iMip) { int nMipWidth, nMipHeight; ComputeMipLevelDimensions( iMip, &nMipWidth, &nMipHeight ); for (int iFrame = 0; iFrame < m_nFrameCount; ++iFrame) { for (int iFace = 0; iFace < m_nFaceCount; ++iFace) { unsigned char *pSrcData = ImageData( iFrame, iFace, iMip ); unsigned char *pDstData = pConvertedImage + GetImageOffset( iFrame, iFace, iMip, fmt ); if( bNormalToDUDV ) { if( fmt == IMAGE_FORMAT_UV88 ) { ImageLoader::ConvertNormalMapRGBA8888ToDUDVMapUV88( pSrcData, nMipWidth, nMipHeight, pDstData ); } else if( fmt == IMAGE_FORMAT_UVWQ8888 ) { ImageLoader::ConvertNormalMapRGBA8888ToDUDVMapUVWQ8888( pSrcData, nMipWidth, nMipHeight, pDstData ); } else { Assert( 0 ); return; } } else { ImageLoader::ConvertImageFormat( pSrcData, m_Format, pDstData, fmt, nMipWidth, nMipHeight ); } } } } AllocateImageData(iConvertedSize); memcpy( m_pImageData, pConvertedImage, iConvertedSize ); m_Format = fmt; MemFreeScratch(); }