MCPcopy Create free account
hub / github.com/w3c/epubcheck / BitmapChecker

Class BitmapChecker

src/main/java/com/adobe/epubcheck/bitmap/BitmapChecker.java:45–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43import io.mola.galimatias.URL;
44
45public class BitmapChecker extends PublicationResourceChecker
46{
47 private static final int HEIGHT_MAX = 2 * 1080;
48 private static final int WIDTH_MAX = 2 * 1920;
49 private static final long IMAGESIZE_MAX = 4 * 1024 * 1024;
50
51 public BitmapChecker(ValidationContext context)
52 {
53 super(context);
54 }
55
56 private void checkHeader(byte[] header)
57 {
58 String mimeType = context.mimeType;
59 boolean passed;
60 if (mimeType.equals("image/jpeg"))
61 {
62 passed = header[0] == (byte) 0xFF && header[1] == (byte) 0xD8;
63 }
64 else if (mimeType.equals("image/gif"))
65 {
66 passed = header[0] == (byte) 'G' && header[1] == (byte) 'I'
67 && header[2] == (byte) 'F' && header[3] == (byte) '8';
68 }
69 else
70 {
71 passed = !mimeType.equals("image/png") || header[0] == (byte) 0x89 && header[1] == (byte) 'P' && header[2] == (byte) 'N' && header[3] == (byte) 'G';
72 }
73 if (!passed)
74 {
75 report.message(MessageId.OPF_029, EPUBLocation.of(context), context.path, mimeType);
76 }
77 }
78
79
80 /**
81 * Gets image dimensions for given file
82 *
83 * @return dimensions of image
84 * @throws IOException if the file is not a known image
85 */
86 private ImageHeuristics getImageSizes() throws
87 IOException
88 {
89 OCFContainer container = context.container.get();
90 URL imgURL = context.url;
91 //FIXME 2022 move extension extraction to URL utils
92 int pos = imgURL.path().lastIndexOf(".");
93 if (pos == -1)
94 {
95 throw new IOException("No extension for file: " + imgURL);
96 }
97
98 String suffix = imgURL.path().substring(pos + 1);
99 File tempFile = null;
100 if ("svg".compareToIgnoreCase(suffix) == 0)
101 {
102 tempFile = getImageFile(container, imgURL);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…