Skip to content

Commit

Permalink
+允许提取灰度掩膜图像
Browse files Browse the repository at this point in the history
  • Loading branch information
wmjordan committed Jan 18, 2023
1 parent eda248e commit 4c4adb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 3 additions & 8 deletions App/Processor/ImageExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,16 @@ internal void ExtractImage(ImageInfo info) {
var fileName = GetNewImageFileName();
if (info.ExtName == Constants.FileExtensions.Png
|| info.ExtName == Constants.FileExtensions.Tif
//|| info.MaskBytes != null
) {
SaveBitmap(info, bytes, fileName);
}
else {
SaveImageBytes(info, bytes, fileName);
}
if (info.MaskBytes != null) {
using (var m = new FreeImageBitmap(
info.MaskSize.Width, info.MaskSize.Height,
(info.MaskSize.Width + 7) / 8, PixelFormat.Format1bppIndexed,
info.MaskBytes)) {
//var r = bmp.Composite (false, null, m);
if (info.Mask != null) {
using (var m = info.Mask) {
m.Palette.CreateGrayscalePalette();
m.Save(fileName + "[mask]" + Constants.FileExtensions.Tif);
m.Save($"{fileName}[mask]{(info.Mask.PixelFormat == PixelFormat.Format1bppIndexed ? Constants.FileExtensions.Tif : Constants.FileExtensions.Png)}");
}
}
_totalImageCount++;
Expand Down
8 changes: 3 additions & 5 deletions App/Processor/Imaging/ImageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ internal sealed class ImageInfo
public PdfName PaletteColorSpace { get; private set; }
public byte[] PaletteBytes { get; private set; }
public byte[] ICCProfile { get; private set; }
public Size MaskSize { get; private set; }
public byte[] MaskBytes { get; private set; }
public FreeImageBitmap Mask { get; private set; }
public int PaletteEntryCount { get; private set; }
public RGBQUAD[] PaletteArray { get; private set; }
public PdfImageData InlineImage { get; private set; }
Expand Down Expand Up @@ -200,9 +199,8 @@ private static byte[] DecodeImage(ImageInfo info, ImageExtracterOptions options)
) {
var mi = new ImageInfo(sm);
var mask = DecodeImage(mi, new ImageExtracterOptions() { InvertBlackAndWhiteImages = !options.InvertSoftMask });
if (mask != null && mi.BitsPerComponent == 1) {
info.MaskBytes = mask;
info.MaskSize = new Size(mi.Width, mi.Height);
if (mask != null) {
info.Mask = ImageExtractor.CreateFreeImageBitmap(mi, ref mask, options.VerticalFlipImages, false);
}
}
return decodedBytes;
Expand Down

0 comments on commit 4c4adb3

Please sign in to comment.