mirror of
https://github.com/ONLYOFFICE/core.git
synced 2026-02-10 18:05:41 +08:00
12
This commit is contained in:
@ -78,7 +78,14 @@ HEADERS += \
|
||||
./../MetafileToGraphicsRenderer.h \
|
||||
./../structures.h \
|
||||
./../Graphics.h \
|
||||
./../GraphicsRenderer.h
|
||||
./../GraphicsRenderer.h \
|
||||
\
|
||||
./../../fontengine/ApplicationFonts.h \
|
||||
./../../fontengine/FontFile.h \
|
||||
./../../fontengine/FontPath.h \
|
||||
./../../fontengine/GlyphString.h \
|
||||
./../../fontengine/FontManager.h
|
||||
|
||||
|
||||
SOURCES += \
|
||||
./../Matrix.cpp \
|
||||
@ -91,7 +98,13 @@ SOURCES += \
|
||||
./../Clip.cpp \
|
||||
./../Graphics.cpp \
|
||||
./../GraphicsRenderer.cpp \
|
||||
./../Image.cpp
|
||||
./../Image.cpp \
|
||||
\
|
||||
./../../fontengine/ApplicationFonts.cpp \
|
||||
./../../fontengine/FontFile.cpp \
|
||||
./../../fontengine/FontManager.cpp \
|
||||
./../../fontengine/FontPath.cpp \
|
||||
./../../fontengine/GlyphString.cpp
|
||||
|
||||
SOURCES += $$PWD/graphics_pri.cpp
|
||||
|
||||
|
||||
@ -91,12 +91,6 @@
|
||||
#include "../../../freetype-2.5.2/src/smooth/smooth.c"
|
||||
*/
|
||||
|
||||
#include "../../../fontengine/ApplicationFonts.cpp"
|
||||
#include "../../../fontengine/FontFile.cpp"
|
||||
#include "../../../fontengine/FontManager.cpp"
|
||||
#include "../../../fontengine/FontPath.cpp"
|
||||
#include "../../../fontengine/GlyphString.cpp"
|
||||
|
||||
#include "../../../fontengine/fontconverter/StringExt.cpp"
|
||||
#include "../../../fontengine/fontconverter/Hash.cpp"
|
||||
#include "../../../fontengine/fontconverter/FontConverter.cpp"
|
||||
|
||||
@ -37,6 +37,349 @@
|
||||
#include "Jp2/J2kFile.h"
|
||||
#include "JBig2/source/JBig2File.h"
|
||||
|
||||
void CxImageToMediaFrame( CxImage& img, CBgraFrame* bgra )
|
||||
{
|
||||
if( !img.IsValid() )
|
||||
return;
|
||||
|
||||
int nWidth = img.GetWidth();
|
||||
int nHeight = img.GetHeight();
|
||||
|
||||
BYTE* pData = new BYTE[4 * nWidth * nHeight];
|
||||
|
||||
if (!pData)
|
||||
return;
|
||||
|
||||
bgra->put_Data(pData);
|
||||
bgra->put_Width(nWidth);
|
||||
bgra->put_Height(nHeight);
|
||||
bgra->put_Stride(-4 * nWidth);
|
||||
|
||||
BYTE* pPixels = bgra->get_Data();
|
||||
|
||||
int nBitsPerPixel = img.GetBpp();
|
||||
int nStride = img.GetEffWidth();
|
||||
BYTE* pBuffer = img.GetBits();
|
||||
RGBQUAD* pPalette = img.GetPalette();
|
||||
bool bIsAlphaPalettePresent = img.AlphaPaletteIsEnabled();
|
||||
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;
|
||||
|
||||
int nTransIndex = img.GetTransIndex();
|
||||
if (bIsAlphaApplied)
|
||||
nTransIndex = -1;
|
||||
|
||||
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;
|
||||
|
||||
if (bIsAlphaPalettePresent)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else if (-1 != nTransIndex)
|
||||
{
|
||||
if (index == nTransIndex)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else
|
||||
dst[3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 != nTransIndex || bIsAlphaPalettePresent)
|
||||
bIsAlphaApplied = true;
|
||||
}
|
||||
else
|
||||
if( 8 == nBitsPerPixel )
|
||||
{
|
||||
BYTE* src = pBuffer;
|
||||
BYTE* dst = pPixels;
|
||||
|
||||
nStride -= nWidth;
|
||||
|
||||
int nTransIndex = img.GetTransIndex();
|
||||
if (bIsAlphaApplied)
|
||||
nTransIndex = -1;
|
||||
|
||||
if( pPalette )
|
||||
{
|
||||
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;
|
||||
|
||||
if (bIsAlphaPalettePresent)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else if (-1 != nTransIndex)
|
||||
{
|
||||
if (index == nTransIndex)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else
|
||||
dst[3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 != nTransIndex || bIsAlphaPalettePresent)
|
||||
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] = 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
|
||||
{
|
||||
bgra->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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CBgraFrame::CBgraFrame()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
CBgraFrame::~CBgraFrame()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
void CBgraFrame::Destroy()
|
||||
{
|
||||
if (NULL != m_pData)
|
||||
delete []m_pData;
|
||||
|
||||
Clear();
|
||||
}
|
||||
void CBgraFrame::Clear()
|
||||
{
|
||||
m_nFileType = 0;
|
||||
m_lWidth = 0;
|
||||
m_lHeight = 0;
|
||||
m_lStride = 0;
|
||||
m_pData = NULL;
|
||||
m_bIsGrayScale = false;
|
||||
}
|
||||
|
||||
void CBgraFrame::ClearNoAttack()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
int CBgraFrame::get_Width()
|
||||
{
|
||||
return m_lWidth;
|
||||
}
|
||||
int CBgraFrame::get_Height()
|
||||
{
|
||||
return m_lHeight;
|
||||
}
|
||||
void CBgraFrame::put_Width(const int& lWidth)
|
||||
{
|
||||
m_lWidth = lWidth;
|
||||
}
|
||||
void CBgraFrame::put_Height(const int& lHeight)
|
||||
{
|
||||
m_lHeight = lHeight;
|
||||
}
|
||||
int CBgraFrame::get_Stride()
|
||||
{
|
||||
return m_lStride;
|
||||
}
|
||||
void CBgraFrame::put_Stride(const int& lStride)
|
||||
{
|
||||
m_lStride = lStride;
|
||||
}
|
||||
BYTE* CBgraFrame::get_Data()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
void CBgraFrame::put_Data(BYTE* pData)
|
||||
{
|
||||
m_pData = pData;
|
||||
}
|
||||
|
||||
bool CBgraFrame::IsGrayScale()
|
||||
{
|
||||
return m_bIsGrayScale;
|
||||
}
|
||||
|
||||
bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileType)
|
||||
{
|
||||
m_nFileType = nFileType;
|
||||
@ -62,7 +405,7 @@ bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileTyp
|
||||
if (!img.Decode(oFile.GetFileNative(), m_nFileType))
|
||||
return false;
|
||||
|
||||
CxImageToMediaFrame(img);
|
||||
CxImageToMediaFrame(img, this);
|
||||
m_bIsGrayScale = img.IsGrayScale();
|
||||
return true;
|
||||
}
|
||||
@ -115,7 +458,7 @@ bool CBgraFrame::Resize(const long& nNewWidth, const long& nNewHeight, bool bDes
|
||||
if (bDestroyData)
|
||||
Destroy();
|
||||
|
||||
CxImageToMediaFrame( imgDst );
|
||||
CxImageToMediaFrame( imgDst, this );
|
||||
return true;
|
||||
}
|
||||
bool CBgraFrame::ReColorPatternImage(const std::wstring& strFileName, unsigned int rgbColorBack, unsigned int rgbColorFore)
|
||||
@ -156,276 +499,3 @@ bool CBgraFrame::ReColorPatternImage(const std::wstring& strFileName, unsigned i
|
||||
}
|
||||
return false;
|
||||
}
|
||||
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 = img.AlphaPaletteIsEnabled();
|
||||
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;
|
||||
|
||||
int nTransIndex = img.GetTransIndex();
|
||||
if (bIsAlphaApplied)
|
||||
nTransIndex = -1;
|
||||
|
||||
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;
|
||||
|
||||
if (bIsAlphaPalettePresent)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else if (-1 != nTransIndex)
|
||||
{
|
||||
if (index == nTransIndex)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else
|
||||
dst[3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 != nTransIndex || bIsAlphaPalettePresent)
|
||||
bIsAlphaApplied = true;
|
||||
}
|
||||
else
|
||||
if( 8 == nBitsPerPixel )
|
||||
{
|
||||
BYTE* src = pBuffer;
|
||||
BYTE* dst = pPixels;
|
||||
|
||||
nStride -= nWidth;
|
||||
|
||||
int nTransIndex = img.GetTransIndex();
|
||||
if (bIsAlphaApplied)
|
||||
nTransIndex = -1;
|
||||
|
||||
if( pPalette )
|
||||
{
|
||||
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;
|
||||
|
||||
if (bIsAlphaPalettePresent)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else if (-1 != nTransIndex)
|
||||
{
|
||||
if (index == nTransIndex)
|
||||
dst[3] = pPalette[index].rgbReserved;
|
||||
else
|
||||
dst[3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (-1 != nTransIndex || bIsAlphaPalettePresent)
|
||||
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] = 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,6 @@
|
||||
#include <string>
|
||||
#include "../common/Types.h"
|
||||
|
||||
class CxImage;
|
||||
class CBgraFrame
|
||||
{
|
||||
private:
|
||||
@ -50,75 +49,25 @@ private:
|
||||
bool m_bIsGrayScale;
|
||||
|
||||
public:
|
||||
CBgraFrame()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
~CBgraFrame()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
private:
|
||||
inline void Destroy()
|
||||
{
|
||||
if (NULL != m_pData)
|
||||
delete []m_pData;
|
||||
|
||||
Clear();
|
||||
}
|
||||
inline void Clear()
|
||||
{
|
||||
m_nFileType = 0;
|
||||
m_lWidth = 0;
|
||||
m_lHeight = 0;
|
||||
m_lStride = 0;
|
||||
m_pData = NULL;
|
||||
m_bIsGrayScale = false;
|
||||
}
|
||||
CBgraFrame();
|
||||
~CBgraFrame();
|
||||
|
||||
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;
|
||||
}
|
||||
void Destroy();
|
||||
void Clear();
|
||||
|
||||
inline bool IsGrayScale()
|
||||
{
|
||||
return m_bIsGrayScale;
|
||||
}
|
||||
public:
|
||||
void ClearNoAttack();
|
||||
int get_Width();
|
||||
int get_Height();
|
||||
void put_Width(const int& lWidth);
|
||||
void put_Height(const int& lHeight);
|
||||
int get_Stride();
|
||||
void put_Stride(const int& lStride);
|
||||
BYTE* get_Data();
|
||||
void put_Data(BYTE* pData);
|
||||
|
||||
bool IsGrayScale();
|
||||
|
||||
public:
|
||||
bool OpenFile(const std::wstring& strFileName, unsigned int nFileType = 0); //0 - detect
|
||||
@ -127,9 +76,6 @@ public:
|
||||
bool Resize(const long& nNewWidth, const long& nNewHeight, bool bDestroyData = true);
|
||||
|
||||
bool ReColorPatternImage(const std::wstring& strFileName, unsigned int rgbColorBack, unsigned int rgbColorFore);
|
||||
private:
|
||||
|
||||
void CxImageToMediaFrame( CxImage& img );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -52,6 +52,16 @@ typedef struct ___tagBITMAPINFOHEADER {
|
||||
DWORD biClrImportant;
|
||||
} ___BITMAPINFOHEADER;
|
||||
|
||||
CImageFileFormatChecker::CImageFileFormatChecker()
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
CImageFileFormatChecker::CImageFileFormatChecker(std::wstring sFileName)
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
isImageFile(sFileName);
|
||||
}
|
||||
|
||||
//bmp ( http://ru.wikipedia.org/wiki/BMP )
|
||||
bool CImageFileFormatChecker::isBmpFile(BYTE* pBuffer,DWORD dwBytes)
|
||||
{
|
||||
@ -594,4 +604,4 @@ std::wstring CImageFileFormatChecker::DetectFormatByData(BYTE *Data, int DataSiz
|
||||
else if (isSvmFile(Data,DataSize)) return L"svm";
|
||||
|
||||
return L"jpg";
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,31 +35,32 @@
|
||||
#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,
|
||||
_CXIMAGE_FORMAT_SVM = 23
|
||||
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,
|
||||
_CXIMAGE_FORMAT_SVM = 23
|
||||
};
|
||||
|
||||
class CImageFileFormatChecker
|
||||
@ -67,15 +68,8 @@ class CImageFileFormatChecker
|
||||
public:
|
||||
__ENUM_CXIMAGE_FORMATS eFileType;
|
||||
|
||||
CImageFileFormatChecker()
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
}
|
||||
CImageFileFormatChecker(std::wstring sFileName)
|
||||
{
|
||||
eFileType = _CXIMAGE_FORMAT_UNKNOWN;
|
||||
isImageFile(sFileName);
|
||||
}
|
||||
CImageFileFormatChecker();
|
||||
CImageFileFormatChecker(std::wstring sFileName);
|
||||
|
||||
bool isImageFile(std::wstring& fileName);
|
||||
bool isPngFile(std::wstring& fileName);
|
||||
|
||||
@ -184,6 +184,10 @@
|
||||
|
||||
#define EMR_MAX 122
|
||||
|
||||
#else
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef EMR_SMALLTEXTOUT
|
||||
|
||||
Reference in New Issue
Block a user