Commit 7bc35a15 authored by Ilya Kirillov's avatar Ilya Kirillov

Implemented case when the size of the masked image doesn't match to the size of the mask.

parent 903245e8
......@@ -3309,9 +3309,7 @@ namespace PdfReader
if (m_bDrawOnlyText)
return;
// Вообще, размеры маски и самой картинки могут не совпадать (в этом случае мы должны срезайзить до размеров картинки)
// TO DO: Сделать, когда появится файл
if (nWidth != nMaskWidth || nHeight != nMaskHeight)
if (nMaskWidth <= 0 || nMaskHeight <= 0)
DrawImage(pGState, pRef, pStream, nWidth, nHeight, pColorMap, NULL, false);
double dPageHeight = pGState->GetPageHeight();
......@@ -3334,6 +3332,59 @@ namespace PdfReader
pMask->Reset();
pImageStream->Reset();
if (nWidth != nMaskWidth || nHeight != nMaskHeight)
{
unsigned char *pMaskBuffer = new unsigned char[nMaskWidth * nMaskHeight];
if (!pMaskBuffer)
{
delete pMask;
delete pImageStream;
return;
}
unsigned char unMask = 0;
for (int nY = nMaskHeight - 1; nY >= 0; nY--)
{
for (int nX = 0; nX < nMaskWidth; nX++)
{
int nIndex = nX + nY * nMaskWidth;
pMask->GetPixel(&unMask);
pMaskBuffer[nIndex] = unMask;
}
}
double dScaleWidth = (double)nWidth / (double)nMaskWidth;
double dScaleHeight = (double)nHeight / (double)nMaskHeight;
unsigned char unPixel[4] ={ 0, 0, 0, 0 };
for (int nY = nHeight - 1; nY >= 0; nY--)
{
for (int nX = 0; nX < nWidth; nX++)
{
int nIndex = 4 * (nX + nY * nWidth);
pImageStream->GetPixel(unPixel);
int nNearestY = std::min((int)(nY / dScaleHeight), nMaskHeight - 1);
int nNearestX = std::min((int)(nX / dScaleWidth), nMaskWidth - 1);
unMask = pMaskBuffer[nNearestY * nMaskWidth + nNearestX];
GrRGB oRGB;
pColorMap->GetRGB(unPixel, &oRGB);
pBufferPtr[nIndex + 0] = ColorToByte(oRGB.b);
pBufferPtr[nIndex + 1] = ColorToByte(oRGB.g);
pBufferPtr[nIndex + 2] = ColorToByte(oRGB.r);
if (unMask && !bMaskInvert)
pBufferPtr[nIndex + 3] = 0;
else
pBufferPtr[nIndex + 3] = 255;
}
}
delete[] pMaskBuffer;
}
else
{
unsigned char unPixel[4] ={ 0, 0, 0, 0 };
unsigned char unMask = 0;
for (int nY = nHeight - 1; nY >= 0; nY--)
......@@ -3355,6 +3406,7 @@ namespace PdfReader
pBufferPtr[nIndex + 3] = 255;
}
}
}
delete pMask;
delete pImageStream;
......
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