/** * find an image in another image * @param img image * @return a Match or null */ public Match find(Image img) { log(-1, "find: not implemented yet"); return null; }
/** * find all images in another image * @param img image * @return Match or null */ public Iterator<Match> findAll(Image img) { log(-1, "findAll: not implemented yet"); return null; }
/** * create a new image from a buffered image<br> * giving it a descriptive name for printout and logging <br> * can only be reused with the object reference * * @param img BufferedImage * @param name descriptive name */ public Image(BufferedImage img, String name) { imageName = isBImg; if (name != null) { imageName += name; } bimg = img; bwidth = bimg.getWidth(); bheight = bimg.getHeight(); log(lvl, "BufferedImage: (%d, %d)%s", bwidth, bheight, (name == null ? "" : " with name: " + name)); }
protected boolean backup() { if (isValid()) { File fOrg = new File(fileURL.getPath()); File fBack = new File(fOrg.getParentFile(), "_BACKUP_" + fOrg.getName()); if (FileManager.xcopy(fOrg, fBack)) { hasBackup = fBack.getPath(); log(lvl, "backup: %s created", fBack.getName()); return true; } log(-1, "backup: %s did not work", fBack.getName()); } return false; }
protected boolean restore() { if (!hasBackup.isEmpty()) { File fBack = new File(hasBackup); File fOrg = new File(hasBackup.replace("_BACKUP_", "")); if (FileManager.xcopy(fBack, fOrg)) { log(lvl, "restore: %s restored", fOrg.getName()); FileManager.deleteFileOrFolder(fBack); hasBackup = ""; return true; } log(-1, "restore: %s did not work", fBack.getName()); } return false; }
log(lvl, "--- start of Image dump ---"); ImagePath.dump(lvl); log(lvl, "ImageFiles entries: %d", imageFiles.size()); Iterator<Map.Entry<URL, Image>> it = imageFiles.entrySet().iterator(); Map.Entry<URL, Image> entry; while (it.hasNext()) { entry = it.next(); log(lvl, entry.getKey().toString()); log(lvl, "ImageNames entries: %d", imageNames.size()); Iterator<Map.Entry<String, URL>> nit = imageNames.entrySet().iterator(); Map.Entry<String, URL> name; while (nit.hasNext()) { name = nit.next(); log(lvl, "%s %d KB (%s)", new File(name.getKey()).getName(), imageFiles.get(name.getValue()).getKB(), name.getValue()); log(lvl, "Cache state: switched off!"); } else { log(lvl, "Cache state: Max %d MB (entries: %d used: %d %% %d KB)", Settings.getImageCache(), images.size(), (int) (100 * currentMemory / (Settings.getImageCache() * MB)), (int) (currentMemory / KB)); log(lvl, "--- end of Image dump ---");
URL imgURL; Image img; log(lvl, "purge: ImagePath: %s", pathURL.getPath()); Iterator<Map.Entry<URL, Image>> it = imageFiles.entrySet().iterator(); Map.Entry<URL, Image> entry; imgURL = entry.getKey(); if (imgURL.toString().startsWith(pathURL.toString())) { log(lvl + 1, "purge: URL: %s", imgURL.toString()); img = entry.getValue(); imagePurgeList.add(img); if (imagePurgeList.contains(img)) { bit.remove(); log(lvl + 1, "purge: bimg: %s", img); currentMemoryDown(img.bsize);
private BufferedImage loadAgain() { BufferedImage bImage = null; if (fileURL != null) { bimg = null; try { bImage = ImageIO.read(fileURL); } catch (Exception e) { if (!beSilent) { log(-1, "could not be loaded again: %s", fileURL); } bHasIOException = true; imageFiles.remove(fileURL); return null; } imageFiles.put(fileURL, this); imageNames.put(imageName, fileURL); bwidth = bImage.getWidth(); bheight = bImage.getHeight(); bsize = bImage.getData().getDataBuffer().getSize(); log(lvl, "loaded again: %s (%s)", imageName, fileURL); } return bImage; }
/** * INTERNAL USE: IDE: to get rid of cache entries at script save, close or * save as * * @param bundlePath absolute path for an image set in this folder */ public static void purge(String bundlePath) { if (imageFiles.isEmpty() || ImagePath.getPaths().get(0) == null) { return; } URL pathURL = FileManager.makeURL(bundlePath); if (!ImagePath.getPaths().get(0).pathURL.equals(pathURL)) { log(-1, "purge: not current bundlepath: " + pathURL); return; } purge(pathURL); }
} catch (Exception e) { if (!beSilent) { log(-1, "could not be loaded: %s", fileURL); bheight = bImage.getHeight(); bsize = bImage.getData().getDataBuffer().getSize(); log(lvl, "loaded: %s (%s)", imageName, fileURL); if (isCaching()) { int maxMemory = Settings.getImageCache() * MB; bimg = bImage; images.add(this); log(lvl, "cached: %s (%d KB) (# %d KB %d -- %d %% of %d MB)", imageName, getKB(), images.size(), (int) (currentMemory / KB), log(-1, "invalid! not loaded! %s", fileURL);
private static Image createImageValidate(Image img, boolean verbose) { if (img == null) { log(-1, "Image not valid, creating empty Image"); return new Image("", null); } if (!img.isValid()) { if (Settings.OcrTextSearch) { img.setIsText(true); if (Settings.isValidImageFilename(img.getName())) { img.setIsText(false); } } else { if (verbose) { log(-1, "Image not valid, but TextSearch is switched off!"); } } } return img; }
/** * OCR-read the text from the image * @return the text or null */ public String text() { //TODO: use Tess4J here already?? if (Settings.OcrTextRead) { TextRecognizer tr = TextRecognizer.getInstance(); if (tr == null) { Debug.error("text: text recognition is now switched off"); return null; } String textRead = tr.recognize(this.get()); log(lvl, "text: #(" + textRead + ")#"); return textRead; } Debug.error("text: text recognition is currently switched off"); return null; }