23 package org.sleuthkit.autopsy.coreutils;
25 import java.awt.Image;
26 import java.awt.image.BufferedImage;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.List;
33 import java.util.logging.Level;
34 import javax.imageio.ImageIO;
35 import javax.swing.ImageIcon;
54 private static final Image
DEFAULT_ICON =
new ImageIcon(
"/org/sleuthkit/autopsy/images/file-icon.png").getImage();
55 private static final List<String>
SUPP_EXTENSIONS = Arrays.asList(ImageIO.getReaderFileSuffixes());
56 private static final List<String>
SUPP_MIME_TYPES =
new ArrayList<>(Arrays.asList(ImageIO.getReaderMIMETypes()));
58 SUPP_MIME_TYPES.add(
"image/x-ms-bmp");
89 if (SUPP_MIME_TYPES.contains(attribute.getValueString())) {
94 if (attributes.size() > 0) {
99 logger.log(Level.WARNING,
"Error while getting file signature from blackboard.", ex);
104 if (extension.equals(
"") ==
false) {
106 if (SUPP_EXTENSIONS.contains(extension)) {
131 BufferedImage bicon = ImageIO.read(file);
134 }
else if (bicon.getWidth() != iconSize) {
139 }
catch (IOException ex) {
140 logger.log(Level.WARNING,
"Error while reading image.", ex);
157 if (
getIcon(content, iconSize) != null) {
186 byte[] fileHeaderBuffer =
new byte[2];
189 bytesRead = file.
read(fileHeaderBuffer, 0, 2);
194 if (bytesRead != 2) {
201 return (((fileHeaderBuffer[0] & 0xff) == 0xff) && ((fileHeaderBuffer[1] & 0xff) == 0xd8));
209 byte[] fileHeaderBuffer =
new byte[8];
212 bytesRead = file.
read(fileHeaderBuffer, 0, 8);
217 if (bytesRead != 8) {
224 return (((fileHeaderBuffer[1] & 0xff) == 0x50) && ((fileHeaderBuffer[2] & 0xff) == 0x4E) &&
225 ((fileHeaderBuffer[3] & 0xff) == 0x47) && ((fileHeaderBuffer[4] & 0xff) == 0x0D) &&
226 ((fileHeaderBuffer[5] & 0xff) == 0x0A) && ((fileHeaderBuffer[6] & 0xff) == 0x1A) &&
227 ((fileHeaderBuffer[7] & 0xff) == 0x0A));
245 if (saveFile.exists()) {
248 ImageIO.write((BufferedImage) icon,
"png", saveFile);
250 }
catch (IOException ex) {
251 logger.log(Level.WARNING,
"Could not write cache thumbnail: " + content, ex);
261 InputStream inputStream = null;
262 BufferedImage bi = null;
265 bi = ImageIO.read(inputStream);
267 logger.log(Level.WARNING,
"No image reader for file: " + content.
getName());
273 }
catch (IllegalArgumentException e) {
276 BufferedImage biCropped =
ScalrWrapper.
cropImage(bi, Math.min(iconSize, bi.getWidth()), Math.min(iconSize, bi.getHeight()));
279 catch (OutOfMemoryError e) {
280 logger.log(Level.WARNING,
"Could not scale image (too large): " + content.
getName(), e);
282 }
catch (Exception e) {
283 logger.log(Level.WARNING,
"Could not scale image: " + content.
getName(), e);
286 if (inputStream != null) {
289 }
catch (IOException ex) {
290 logger.log(Level.WARNING,
"Could not close input stream after resizing thumbnail: " + content.
getName(), ex);
static final Image DEFAULT_ICON
static File getIconFile(Content content, int iconSize)
static boolean isPngFileHeader(AbstractFile file)
static boolean thumbnailSupported(Content content)
static File getFile(long id)
static Image getIcon(Content content, int iconSize)
static final Logger logger
String getNameExtension()
static final int ICON_SIZE_SMALL
static BufferedImage generateIcon(Content content, int iconSize)
static synchronized BufferedImage resizeFast(BufferedImage input, int size)
static boolean isJpegFileHeader(AbstractFile file)
static Image generateAndSaveIcon(Content content, int iconSize, File saveFile)
static final int ICON_SIZE_MEDIUM
static Image getDefaultIcon()
static final List< String > SUPP_EXTENSIONS
static final List< String > SUPP_MIME_TYPES
String getCacheDirectory()
static Case getCurrentCase()
static final int ICON_SIZE_LARGE
final int read(byte[] buf, long offset, long len)
ArrayList< BlackboardAttribute > getGenInfoAttributes(ATTRIBUTE_TYPE attr_type)
static Logger getLogger(String name)
static synchronized BufferedImage cropImage(BufferedImage input, int width, int height)