Skip to content

Commit

Permalink
GH-314 make sure we burn the mask as well as there can be some readab…
Browse files Browse the repository at this point in the history
…le data for those who know how to look.
  • Loading branch information
Patrick Corless committed Dec 5, 2023
1 parent d69ed5a commit d4a25d0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ public static BufferedImage applyExplicitOutline(BufferedImage baseImage, Buffer
}

/**
* Treats the base image as as mask data applying the specified fill colour
* Treats the base image as a mask data applying the specified fill colour
* to the flagged bytes and a transparency value otherwise. This method
* creates a new BufferedImage with a transparency model so it will cause
* a memory spike.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.icepdf.core.util.redaction;

import org.icepdf.core.pobjects.PObject;
import org.icepdf.core.pobjects.Reference;
import org.icepdf.core.pobjects.graphics.images.ImageDecoder;
import org.icepdf.core.pobjects.graphics.images.ImageStream;
import org.icepdf.core.pobjects.graphics.images.ImageUtility;
Expand Down Expand Up @@ -36,12 +35,6 @@ private static void checkAndBurnMasks(ImageStream imageStream, GeneralPath redac
maskImageStream.setGraphicsTransformMatrix(imageStream.getGraphicsTransformMatrix());
BufferedImage imageMask = imageMaskDecoder.decode();
burnImage(maskImageStream, imageMask, redactionPath, false);
// todo we get an inverted mask after the paint, need to correct the data.
BufferedImage decodedImage = maskImageStream.getDecodedImage();
Reference reference = maskImageStream.getPObjectReference();
ImageUtility.displayImage(maskImageStream.getDecodedImage(),
reference.toString() + decodedImage.getWidth() +
" " + "x" + decodedImage.getHeight());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.icepdf.core.pobjects.PObject;
import org.icepdf.core.pobjects.Page;
import org.icepdf.core.pobjects.StateManager;
import org.icepdf.core.pobjects.annotations.Annotation;
import org.icepdf.core.pobjects.annotations.RedactionAnnotation;

import java.io.IOException;
Expand Down Expand Up @@ -41,11 +40,12 @@ public static void burnRedactions(Document document) throws InterruptedException
private static void convertRedactionToSquareAnnotation(StateManager stateManager,
List<RedactionAnnotation> redactionAnnotations) {
for (RedactionAnnotation redactionAnnotation : redactionAnnotations) {
redactionAnnotation.setSubtype(Annotation.SUBTYPE_SQUARE);
redactionAnnotation.setFlag(Annotation.FLAG_LOCKED, true);
redactionAnnotation.setFlag(Annotation.FLAG_READ_ONLY, true);
redactionAnnotation.setFlag(Annotation.FLAG_LOCKED_CONTENTS, true);
stateManager.addChange(new PObject(redactionAnnotation, redactionAnnotation.getPObjectReference()));
// redactionAnnotation.setSubtype(Annotation.SUBTYPE_SQUARE);
// redactionAnnotation.setFlag(Annotation.FLAG_LOCKED, true);
// redactionAnnotation.setFlag(Annotation.FLAG_READ_ONLY, true);
// redactionAnnotation.setFlag(Annotation.FLAG_LOCKED_CONTENTS, true);
// stateManager.addChange(new PObject(redactionAnnotation, redactionAnnotation.getPObjectReference()));
stateManager.addDeletion(new PObject(redactionAnnotation, redactionAnnotation.getPObjectReference()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import org.icepdf.core.io.CountingOutputStream;
import org.icepdf.core.pobjects.DictionaryEntries;
import org.icepdf.core.pobjects.Stream;
import org.icepdf.core.pobjects.graphics.images.ImageParams;
import org.icepdf.core.pobjects.graphics.images.ImageStream;
import org.icepdf.core.pobjects.security.SecurityManager;
import org.icepdf.core.util.Library;
import org.icepdf.core.util.updater.writeables.image.ImageEncoder;
import org.icepdf.core.util.updater.writeables.image.ImageEncoderFactory;

Expand All @@ -20,10 +18,6 @@ public void write(ImageStream imageStream, SecurityManager securityManager, Coun
byte[] outputData;
// decoded image is only set if the image was touch via a redaction burn.
if (imageStream.getDecodedImage() != null) {

Library library = imageStream.getLibrary();
Object tmp = library.getObject(imageStream.getEntries(), ImageParams.COLORSPACE_KEY);

ImageEncoder imageEncoder = ImageEncoderFactory.createEncodedImage(imageStream);
imageStream = imageEncoder.encode();
outputData = imageStream.getRawBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public ImageStream encode() throws IOException {

DictionaryEntries entries = imageStream.getEntries();
entries.put(Stream.FILTER_KEY, Stream.FILTER_CCITT_FAX_DECODE);
// don't need this anymore as the data has already been normalized
entries.remove(DECODE_KEY);
if (imageStream.getEntries().get(Stream.DECODEPARAM_KEY) != null) {
DictionaryEntries decodeParams = imageStream.getLibrary().getDictionary(imageStream.getEntries(),
Stream.DECODEPARAM_KEY);
// group 4 encoding
decodeParams.put(K_KEY, -1);
decodeParams.put(BLACKIS1_KEY, true);
if (imageStream.getEntries().get(Stream.DECODEPARAM_KEY) == null) {
imageStream.getEntries().put(Stream.DECODEPARAM_KEY, new DictionaryEntries());
}
DictionaryEntries decodeParams = imageStream.getLibrary().getDictionary(imageStream.getEntries(),
Stream.DECODEPARAM_KEY);
// group 4 encoding
decodeParams.put(K_KEY, -1);
decodeParams.put(BLACKIS1_KEY, true);

imageStream.setRawBytes(byteArrayOutputStream.toByteArray());

Expand Down

0 comments on commit d4a25d0

Please sign in to comment.