Commit d993363c authored by Elen.Subbotina's avatar Elen.Subbotina Committed by Alexander Trofimov

.....

git-svn-id: svn://fileserver/activex/AVS/Sources/TeamlabOffice/trunk/ServerComponents@61940 954022d7-b5bf-4e40-9824-e11837661b57
parent 4f5be317
#include "BgraFrame.h"
#include "../common/File.h"
#include "../cximage/CxImage/ximage.h"
bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileType)
{
NSFile::CFileBinary oFile;
if (!oFile.OpenFile(strFileName))
return false;
CxImage img;
if( !img.Decode( oFile.GetFileNative(), nFileType ) )
return false;
CxImageToMediaFrame( img );
return true;
}
bool CBgraFrame::SaveFile(const std::wstring& strFileName, unsigned int nFileType)
{
NSFile::CFileBinary oFile;
if (!oFile.CreateFileW(strFileName))
return false;
uint32_t lStride = 4 * m_lWidth;
uint32_t lBitsPerPixel = 4;
if (0 != m_lStride)
{
lStride = (m_lStride > 0) ? (uint32_t)m_lStride : (uint32_t)(-m_lStride);
lBitsPerPixel = lStride / m_lWidth;
}
CxImage img;
if (!img.CreateFromArray(m_pData, m_lWidth, m_lHeight, lBitsPerPixel * 8, lStride, (m_lStride >= 0) ? true : false))
return false;
if (!img.Encode( oFile.GetFileNative(), nFileType ))
return false;
oFile.CloseFile();
return true;
}
bool CBgraFrame::Resize(const long& nNewWidth, const long& nNewHeight)
{
CxImage img;
if (!img.CreateFromArray(m_pData, m_lWidth, m_lHeight, 32, 4 * m_lWidth, (m_lStride >= 0) ? true : false))
return false;
CxImage imgDst;
if (!img.Resample( nNewWidth, nNewHeight, 2/*bicubic spline interpolation*/, &imgDst ))
return false;
CxImageToMediaFrame( imgDst );
return true;
}
void CBgraFrame::CxImageToMediaFrame( CxImage& img )
{
if( !img.IsValid() )
return;
int nWidth = img.GetWidth();
int nHeight = img.GetHeight();
m_pData = new BYTE[4 * nWidth * nHeight];
if (!m_pData)
return;
m_lWidth = nWidth;
m_lHeight = nHeight;
m_lStride = -4 * nWidth;
BYTE* pPixels = m_pData;
int nBitsPerPixel = img.GetBpp();
int nStride = img.GetEffWidth();
BYTE* pBuffer = img.GetBits();
RGBQUAD* pPalette = img.GetPalette();
bool bIsAlphaPalettePresent = false;//img.GetPaletteAlphaEnabled();
bool bIsAlphaApplied = false;
if( 1 == nBitsPerPixel )
{
RGBQUAD pal[2];
if( !pPalette )
{
for( int i = 0; i < 2; i++ )
{
int c = i * 255;
pal[i].rgbBlue = c;
pal[i].rgbGreen = c;
pal[i].rgbRed = c;
}
pPalette = pal;
}
BYTE* src = pBuffer;
BYTE* dst = pPixels;
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, dst += 4 )
{
int index = (src[nPos >> 3] >> (7 - (nPos & 7)) * 1) & 1;
dst[0] = pPalette[index].rgbBlue;
dst[1] = pPalette[index].rgbGreen;
dst[2] = pPalette[index].rgbRed;
}
}
}
else
if( 2 == nBitsPerPixel )
{
RGBQUAD pal[4];
if( !pPalette )
{
for( int i = 0; i < 4; i++ )
{
int c = (i * 255 + 2) / 3;
pal[i].rgbBlue = c;
pal[i].rgbGreen = c;
pal[i].rgbRed = c;
}
pPalette = pal;
}
BYTE* src = pBuffer;
BYTE* dst = pPixels;
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, dst += 4 )
{
int index = (src[nPos >> 2] >> (3 - (nPos & 3)) * 2) & 3;
dst[0] = pPalette[index].rgbBlue;
dst[1] = pPalette[index].rgbGreen;
dst[2] = pPalette[index].rgbRed;
}
}
}
else
if( 4 == nBitsPerPixel )
{
RGBQUAD pal[16];
if( !pPalette )
{
for( int i = 0; i < 16; i++ )
{
int c = (i * 255 + 8) / 15;
pal[i].rgbBlue = c;
pal[i].rgbGreen = c;
pal[i].rgbRed = c;
}
pPalette = pal;
}
BYTE* src = pBuffer;
BYTE* dst = pPixels;
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, dst += 4 )
{
int index = (src[nPos >> 1] >> (1 - (nPos & 1)) * 4) & 15;
dst[0] = pPalette[index].rgbBlue;
dst[1] = pPalette[index].rgbGreen;
dst[2] = pPalette[index].rgbRed;
}
}
}
else
if( 8 == nBitsPerPixel )
{
BYTE* src = pBuffer;
BYTE* dst = pPixels;
nStride -= nWidth;
if( pPalette )
{
if (bIsAlphaPalettePresent)
{
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, src += 1, dst += 4 )
{
int index = src[0];
dst[0] = pPalette[index].rgbBlue;
dst[1] = pPalette[index].rgbGreen;
dst[2] = pPalette[index].rgbRed;
dst[3] = pPalette[index].rgbReserved;
}
}
bIsAlphaApplied = true;
}
else
{
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, src += 1, dst += 4 )
{
int index = src[0];
dst[0] = pPalette[index].rgbBlue;
dst[1] = pPalette[index].rgbGreen;
dst[2] = pPalette[index].rgbRed;
}
}
}
}
else
{
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, src += 1, dst += 4 )
{
int index = src[0];
dst[0] = index;
dst[1] = index;
dst[2] = index;
}
}
}
}
else if( 24 == nBitsPerPixel )
{
BYTE* src = pBuffer;
BYTE* dst = pPixels;
nStride -= nWidth * 3;
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, src += 3, dst += 4 )
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
}
}
else if( 32 == nBitsPerPixel )
{
BYTE* src = pBuffer;
BYTE* dst = pPixels;
nStride -= nWidth * 4;
for( int nRow = 0; nRow < nHeight; ++nRow, src += nStride )
{
for( int nPos = 0; nPos < nWidth; ++nPos, src += 4, dst += 4 )
{
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
}
}
}
else
{
Destroy();
return;
}
if( img.AlphaIsValid() )
{
BYTE* pAlpha = img.AlphaGetPointer();
DWORD nMaxAlpha = img.AlphaGetMax();
if( 255 == nMaxAlpha )
{
BYTE* src = pAlpha;
BYTE* dst = pPixels;
int nSize = nWidth * nHeight;
for( int i = 0; i < nSize; ++i, ++src, dst += 4 )
{
dst[3] = src[0];
}
}
else
{
BYTE table[256];
for( DWORD i = 0; i < 256; ++i )
{
DWORD a = (i * 255 + nMaxAlpha / 2) / nMaxAlpha;
table[i] = (a > 255) ? 255 : a;
}
BYTE* src = pAlpha;
BYTE* dst = pPixels;
int nSize = nWidth * nHeight;
for( int i = 0; i < nSize; ++i, ++src, dst += 4 )
{
dst[3] = table[src[0]];
}
}
}
else if (!bIsAlphaApplied)
{
BYTE* dst = pPixels;
int nSize = nWidth * nHeight;
for( int i = 0; i < nSize; ++i, dst += 4 )
{
dst[3] = 255;
}
}
}
#ifndef _BUILD_BGRA_FRAME_
#define _BUILD_BGRA_FRAME_
#include <string>
#include "../common/Types.h"
class CxImage;
class CBgraFrame
{
private:
int m_lWidth;
int m_lHeight;
int m_lStride;
BYTE* m_pData;
public:
CBgraFrame()
{
Clear();
}
~CBgraFrame()
{
Destroy();
}
private:
inline void Destroy()
{
if (NULL != m_pData)
delete []m_pData;
Clear();
}
inline void Clear()
{
m_lWidth = 0;
m_lHeight = 0;
m_lStride = 0;
m_pData = NULL;
}
public:
inline void ClearNoAttack()
{
Clear();
}
inline int get_Width()
{
return m_lWidth;
}
inline int get_Height()
{
return m_lHeight;
}
inline void put_Width(const int& lWidth)
{
m_lWidth = lWidth;
}
inline void put_Height(const int& lHeight)
{
m_lHeight = lHeight;
}
inline int get_Stride()
{
return m_lStride;
}
inline void put_Stride(const int& lStride)
{
m_lStride = lStride;
}
inline BYTE* get_Data()
{
return m_pData;
}
inline void put_Data(BYTE* pData)
{
m_pData = pData;
}
public:
bool OpenFile(const std::wstring& strFileName, unsigned int nFileType = 0); //0 - detect
bool SaveFile(const std::wstring& strFileName, unsigned int nFileType);
bool Resize(const long& nNewWidth, const long& nNewHeight);
private:
void CxImageToMediaFrame( CxImage& img );
};
#endif
This diff is collapsed.
#ifndef _BUILD_IMAGE_FILE_CHECKER_
#define _BUILD_IMAGE_FILE_CHECKER_
#include <string>
#include "../common/Types.h"
enum __ENUM_CXIMAGE_FORMATS {
_CXIMAGE_FORMAT_UNKNOWN = 0,
_CXIMAGE_FORMAT_BMP = 1,
_CXIMAGE_FORMAT_GIF = 2,
_CXIMAGE_FORMAT_JPG = 3,
_CXIMAGE_FORMAT_PNG = 4,
_CXIMAGE_FORMAT_ICO = 5,
_CXIMAGE_FORMAT_TIF = 6,
_CXIMAGE_FORMAT_TGA = 7,
_CXIMAGE_FORMAT_PCX = 8,
_CXIMAGE_FORMAT_WBMP = 9,
_CXIMAGE_FORMAT_WMF = 10,
_CXIMAGE_FORMAT_JP2 = 11,
_CXIMAGE_FORMAT_JPC = 12,
_CXIMAGE_FORMAT_PGX = 13,
_CXIMAGE_FORMAT_PNM = 14,
_CXIMAGE_FORMAT_RAS = 15,
_CXIMAGE_FORMAT_JBG = 16,
_CXIMAGE_FORMAT_MNG = 17,
_CXIMAGE_FORMAT_SKA = 18,
_CXIMAGE_FORMAT_RAW = 19,
_CXIMAGE_FORMAT_PSD = 20,
_CXIMAGE_FORMAT_EMF = 21,
_CXIMAGE_FORMAT_WB = 22,
};
class CImageFileFormatChecker
{
public:
__ENUM_CXIMAGE_FORMATS eFileType;
CImageFileFormatChecker()
{
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
}
CImageFileFormatChecker(std::wstring sFileName)
{
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
isImageFile(sFileName);
}
bool isImageFile(std::wstring& fileName);
bool isPngFile(std::wstring& fileName);
bool isRawFile(std::wstring& fileName);
bool isSvgFile(std::wstring& fileName);
bool isBmpFile(BYTE* pBuffer,DWORD dwBytes);
bool isGifFile(BYTE* pBuffer,DWORD dwBytes);
bool isPngFile(BYTE* pBuffer,DWORD dwBytes);
bool isEmfFile(BYTE* pBuffer,DWORD dwBytes);
bool isWmfFile(BYTE* pBuffer,DWORD dwBytes);
bool isTgaFile(BYTE* pBuffer,DWORD dwBytes);
bool isPcxFile(BYTE* pBuffer,DWORD dwBytes);
bool isTiffFile(BYTE* pBuffer,DWORD dwBytes);
bool isJpgFile(BYTE* pBuffer,DWORD dwBytes);
bool isWbFile(BYTE* pBuffer,DWORD dwBytes);
bool isIcoFile(BYTE* pBuffer,DWORD dwBytes);
bool isRasFile(BYTE* pBuffer,DWORD dwBytes);
bool isPsdFile(BYTE* pBuffer,DWORD dwBytes);
bool isSvmFile(BYTE* pBuffer,DWORD dwBytes);
bool isSwfFile(BYTE* pBuffer,DWORD dwBytes);
bool isSfwFile(BYTE* pBuffer,DWORD dwBytes);
bool isWbcFile(BYTE* pBuffer,DWORD dwBytes);
bool isWbzFile(BYTE* pBuffer,DWORD dwBytes);
bool isJ2kFile(BYTE* pBuffer,DWORD dwBytes);
bool isJp2File(BYTE* pBuffer,DWORD dwBytes);
bool isMj2File(BYTE* pBuffer,DWORD dwBytes);
bool isIpodFile(BYTE* pBuffer,DWORD dwBytes);
bool isPgxFile(BYTE* pBuffer,DWORD dwBytes);
std::wstring DetectFormatByData(BYTE *Data, int DataSize);
};
#endif //_BUILD_IMAGE_FILE_CHECKER_

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raster", "raster.vcproj", "{C739151F-5384-41DF-A1A6-F089E2C1AD56}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Debug|Win32.ActiveCfg = Debug|Win32
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Debug|Win32.Build.0 = Debug|Win32
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Debug|x64.ActiveCfg = Debug|x64
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Debug|x64.Build.0 = Debug|x64
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Release|Win32.ActiveCfg = Release|Win32
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Release|Win32.Build.0 = Release|Win32
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Release|x64.ActiveCfg = Release|x64
{C739151F-5384-41DF-A1A6-F089E2C1AD56}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment