mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
Add indexed color space for stencils
This commit is contained in:
parent
8c6f705d2a
commit
f8990a79b8
@ -150,7 +150,7 @@
|
||||
var decodedBytes = ImageHelpers.LoadFileBytes("ccittfax-decoded.bin");
|
||||
var image = new TestPdfImage
|
||||
{
|
||||
ColorSpaceDetails = IndexedColorSpaceDetails.CCITTFaxColorSpaceDetails,
|
||||
ColorSpaceDetails = IndexedColorSpaceDetails.StencilBlackIs1,
|
||||
DecodedBytes = decodedBytes,
|
||||
WidthInSamples = 1800,
|
||||
HeightInSamples = 3113,
|
||||
|
@ -85,13 +85,25 @@
|
||||
public class IndexedColorSpaceDetails : ColorSpaceDetails
|
||||
{
|
||||
/// <summary>
|
||||
/// The lossless CCITT compression schemes are used for bitonal black and white images.
|
||||
/// This is equivalent to an IndexedColorSpaceDetails with a black and white palette.
|
||||
/// A color space useful for extracting stencil masks as black-and-white images.
|
||||
/// Index 0 is black and index 1 is white.
|
||||
/// </summary>
|
||||
internal static readonly IndexedColorSpaceDetails StencilBlackIs0
|
||||
= new IndexedColorSpaceDetails(DeviceGrayColorSpaceDetails.Instance, 1, new byte[] { 0, 255 });
|
||||
|
||||
/// <summary>
|
||||
/// A color space useful for extracting stencil masks as black-and-white images.
|
||||
/// Index 0 is white and index 1 is black.
|
||||
/// </summary>
|
||||
internal static readonly IndexedColorSpaceDetails CCITTFaxColorSpaceDetails
|
||||
internal static readonly IndexedColorSpaceDetails StencilBlackIs1
|
||||
= new IndexedColorSpaceDetails(DeviceGrayColorSpaceDetails.Instance, 1, new byte[] { 255, 0 });
|
||||
|
||||
internal static ColorSpaceDetails Stencil(decimal[] decode)
|
||||
{
|
||||
return decode.Length >= 2 && decode[0] == 1 && decode[1] == 0 ?
|
||||
StencilBlackIs1 : StencilBlackIs0 /* default */;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The base color space in which the values in the color table are to be interpreted.
|
||||
/// It can be any device or CIE-based color space or(in PDF 1.3) a Separation or DeviceN space,
|
||||
@ -119,7 +131,7 @@
|
||||
HiVal = hiVal;
|
||||
ColorTable = colorTable;
|
||||
BaseType = baseColorSpaceDetails.BaseType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -75,9 +75,12 @@
|
||||
ILookupFilterProvider filterProvider,
|
||||
bool cannotRecurse = false)
|
||||
{
|
||||
if (filterProvider.GetFilters(imageDictionary).OfType<CcittFaxDecodeFilter>().Any())
|
||||
if (imageDictionary.GetDictionaryObject(NameToken.ImageMask, NameToken.Im) != null)
|
||||
{
|
||||
return IndexedColorSpaceDetails.CCITTFaxColorSpaceDetails;
|
||||
var decodeRaw = imageDictionary.GetDictionaryObject(NameToken.Decode, NameToken.D) as ArrayToken
|
||||
?? new ArrayToken(EmptyArray<IToken>.Instance);
|
||||
var decode = decodeRaw.Data.OfType<NumericToken>().Select(x => x.Data).ToArray();
|
||||
return IndexedColorSpaceDetails.Stencil(decode);
|
||||
}
|
||||
|
||||
if (!colorSpace.HasValue)
|
||||
|
Loading…
Reference in New Issue
Block a user