mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Mask image
This commit is contained in:
@ -1088,7 +1088,7 @@ PDFColorSpacePointer PDFIndexedColorSpace::createIndexedColorSpace(const PDFDict
|
|||||||
const int colorCount = maxValue - MIN_VALUE + 1;
|
const int colorCount = maxValue - MIN_VALUE + 1;
|
||||||
const int componentCount = static_cast<int>(baseColorSpace->getColorComponentCount());
|
const int componentCount = static_cast<int>(baseColorSpace->getColorComponentCount());
|
||||||
const int byteCount = colorCount * componentCount;
|
const int byteCount = colorCount * componentCount;
|
||||||
if (byteCount != colors.size())
|
if (byteCount > colors.size())
|
||||||
{
|
{
|
||||||
throw PDFException(PDFTranslationContext::tr("Invalid colors for indexed color space. Color space has %1 colors, %2 color components and must have %3 size. Provided size is %4.").arg(colorCount).arg(componentCount).arg(byteCount).arg(colors.size()));
|
throw PDFException(PDFTranslationContext::tr("Invalid colors for indexed color space. Color space has %1 colors, %2 color components and must have %3 size. Provided size is %4.").arg(colorCount).arg(componentCount).arg(byteCount).arg(colors.size()));
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,6 @@ public:
|
|||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
ColorKeyMasking, ///< Masking by color key
|
ColorKeyMasking, ///< Masking by color key
|
||||||
Image, ///< Masking by image with alpha mask
|
|
||||||
ImageMask, ///< Masking by 1-bit image (see "ImageMask" entry in image's dictionary), current color from the graphic state is used to paint an image
|
ImageMask, ///< Masking by 1-bit image (see "ImageMask" entry in image's dictionary), current color from the graphic state is used to paint an image
|
||||||
SoftMask, ///< Image is masked by soft mask
|
SoftMask, ///< Image is masked by soft mask
|
||||||
};
|
};
|
||||||
@ -136,6 +135,9 @@ public:
|
|||||||
const std::vector<PDFReal>& getDecode() const { return m_decode; }
|
const std::vector<PDFReal>& getDecode() const { return m_decode; }
|
||||||
const std::vector<PDFReal>& getMatte() const { return m_matte; }
|
const std::vector<PDFReal>& getMatte() const { return m_matte; }
|
||||||
|
|
||||||
|
void setMaskingType(MaskingType maskingType) { m_maskingType = maskingType; }
|
||||||
|
void setDecode(std::vector<PDFReal> decode) { m_decode = qMove(decode); }
|
||||||
|
|
||||||
/// Returns number of color channels
|
/// Returns number of color channels
|
||||||
unsigned int getColorChannels() const { return m_components; }
|
unsigned int getColorChannels() const { return m_components; }
|
||||||
|
|
||||||
|
@ -125,10 +125,28 @@ PDFImage PDFImage::createImage(const PDFDocument* document,
|
|||||||
}
|
}
|
||||||
else if (object.isStream())
|
else if (object.isStream())
|
||||||
{
|
{
|
||||||
// TODO: Implement Mask Image
|
PDFImage softMaskImage = createImage(document, object.getStream(), colorSpace, false, renderingIntent, errorReporter);
|
||||||
PDFImage maskImage = createImage(document, object.getStream(), colorSpace, false, renderingIntent, errorReporter);
|
|
||||||
maskingType = PDFImageData::MaskingType::Image;
|
if (softMaskImage.m_imageData.getMaskingType() != PDFImageData::MaskingType::ImageMask ||
|
||||||
throw PDFRendererException(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Mask image is not implemented."));
|
softMaskImage.m_imageData.getColorChannels() != 1 ||
|
||||||
|
softMaskImage.m_imageData.getBitsPerComponent() != 1)
|
||||||
|
{
|
||||||
|
throw PDFRendererException(RenderErrorType::NotImplemented, PDFTranslationContext::tr("Invalid mask image."));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We must alter decode, because it has opposite meaning (it is transparency)
|
||||||
|
std::vector<PDFReal> decode = softMaskImage.m_imageData.getDecode();
|
||||||
|
if (decode.size() < 2)
|
||||||
|
{
|
||||||
|
decode = { 0.0, 1.0};
|
||||||
|
}
|
||||||
|
std::swap(decode[0], decode[1]);
|
||||||
|
|
||||||
|
// Create soft mask from image
|
||||||
|
maskingType = PDFImageData::MaskingType::SoftMask;
|
||||||
|
image.m_softMask = qMove(softMaskImage.m_imageData);
|
||||||
|
image.m_softMask.setMaskingType(PDFImageData::MaskingType::None);
|
||||||
|
image.m_softMask.setDecode(qMove(decode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (dictionary->hasKey("SMask"))
|
else if (dictionary->hasKey("SMask"))
|
||||||
|
Reference in New Issue
Block a user