19 package org.sleuthkit.autopsy.contentviewers.imagetagging;
21 import java.awt.image.BufferedImage;
22 import java.io.BufferedInputStream;
23 import java.io.ByteArrayInputStream;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.util.Collection;
27 import java.util.concurrent.ExecutionException;
28 import javafx.concurrent.Task;
29 import javafx.embed.swing.SwingFXUtils;
30 import javafx.scene.image.Image;
31 import javax.imageio.ImageIO;
32 import org.opencv.core.Core;
33 import org.opencv.core.Mat;
34 import org.opencv.core.MatOfByte;
35 import org.opencv.core.Point;
36 import org.opencv.core.Scalar;
37 import org.opencv.core.Size;
38 import org.opencv.highgui.Highgui;
39 import org.opencv.imgproc.Imgproc;
50 private final static String
AWT_PNG =
"png";
67 Collection<ImageTagRegion> tagRegions)
throws IOException, InterruptedException, ExecutionException {
74 try (ByteArrayInputStream taggedStream =
new ByteArrayInputStream(taggedMatrix.toArray())) {
75 return ImageIO.read(taggedStream);
77 sourceImage.release();
78 taggedMatrix.release();
91 private static BufferedImage
getImageFromFile(AbstractFile file)
throws IOException, InterruptedException, ExecutionException {
94 try (BufferedInputStream bufferedReadContentStream =
95 new BufferedInputStream(
new ReadContentInputStream(file))) {
96 return ImageIO.read(bufferedReadContentStream);
102 Image fxResult = readImageTask.get();
103 return SwingFXUtils.fromFXImage(fxResult, null);
117 private static Mat
getImageMatFromFile(AbstractFile file)
throws InterruptedException, ExecutionException, IOException {
122 try (ByteArrayOutputStream outStream =
new ByteArrayOutputStream()) {
123 ImageIO.write(buffImage, AWT_PNG, outStream);
125 byte[] imageBytes = outStream.toByteArray();
126 MatOfByte rawSourceBytes =
new MatOfByte(imageBytes);
127 Mat sourceImage = Highgui.imdecode(rawSourceBytes, Highgui.IMREAD_COLOR);
128 rawSourceBytes.release();
145 Point topLeft =
new Point(region.getX(), region.getY());
146 Point bottomRight =
new Point(topLeft.x + region.getWidth(),
147 topLeft.y + region.getHeight());
149 Scalar rectangleBorderColor =
new Scalar(0, 0, 255);
151 int rectangleBorderWidth = (int) Math.rint(region.getStrokeThickness());
153 Core.rectangle(sourceImage, topLeft, bottomRight,
154 rectangleBorderColor, rectangleBorderWidth);
157 MatOfByte taggedMatrix =
new MatOfByte();
158 Highgui.imencode(OPENCV_PNG, sourceImage, taggedMatrix);
175 IconSize iconSize)
throws IOException, InterruptedException, ExecutionException {
184 try (ByteArrayInputStream thumbnailStream =
new ByteArrayInputStream(thumbnailMatrix.toArray())) {
185 return ImageIO.read(thumbnailStream);
187 sourceImage.release();
188 taggedMatrix.release();
189 thumbnailMatrix.release();
203 Mat taggedImage = Highgui.imdecode(taggedMatrix, Highgui.IMREAD_COLOR);
205 Mat thumbnailImage =
new Mat();
206 Imgproc.resize(taggedImage, thumbnailImage, resizeDimensions);
208 MatOfByte thumbnailMatrix =
new MatOfByte();
209 Highgui.imencode(OPENCV_PNG, thumbnailImage, thumbnailMatrix);
211 thumbnailImage.release();
212 taggedImage.release();
214 return thumbnailMatrix;
static boolean isGIF(AbstractFile file)
static MatOfByte getResizedMatrix(MatOfByte taggedMatrix, IconSize size)
static BufferedImage getImageWithTags(AbstractFile file, Collection< ImageTagRegion > tagRegions)
static Task< javafx.scene.image.Image > newReadImageTask(AbstractFile file)
static BufferedImage getImageFromFile(AbstractFile file)
static BufferedImage getThumbnailWithTags(AbstractFile file, Collection< ImageTagRegion > tagRegions, IconSize iconSize)
static MatOfByte getTaggedImageMatrix(Mat sourceImage, Collection< ImageTagRegion > tagRegions)
static Mat getImageMatFromFile(AbstractFile file)
static final String OPENCV_PNG
static final String AWT_PNG