Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

46
LINES

< > BotCompany Repo | #1035766 // ScaledGrayscaleCache [dev.]

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (13950L/82K).

// an indexing structure for grayscale images
// -all images have the same size
// -images are sorted by
//   1. average brightness
//   2. "lexical" scanline ordering (within same brightness)
// -every image can have an arbitrary value associated (type "A")

persistable sclass ScaledGrayscaleCache<A> extends Meta is WidthAndHeight, IntSize {
  int w, h;
  new TreeSet<Entry> entries;
  
  persistable class Entry is Comparable<Entry> {
    double brightness;
    BWImage image;
    settable A value;
    
    *(BWImage *image) {
      brightness = image.averageBrightness();
    }
    
    public int compareTo(Entry e) {
      if (brightness != e.brightness)
        ret cmp(brightness, e.brightness);
      ret compareBWImagesByScanlineOrdering(image, e.image);
    }
  }
  
  *(int w) { this(w, w); }
  *(int *w, int *h) {}
  
  public int getWidth() { ret w; }
  public int getHeight() { ret h; }
  
  // returns true if image was new
  bool add(IBWImage image) {
    BWImage scaledImage = scaledBWImageFromBWIntegralImage(w, h, image);
    var entry = new Entry(scaledImage);
    var existingEntry = entries.floor(entry);
    if (cmp(entry, existingEntry) == 0)
      false;
    entries.add(entry);
    true;
  }
  
  public int size() { ret entries.size(); }
}

Author comment

Began life as a copy of #1035743

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035766
Snippet name: ScaledGrayscaleCache [dev.]
Eternal ID of this version: #1035766/5
Text MD5: a2ac2af4da5be278fede888722bfabad
Transpilation MD5: adc2ed43b19f8ad7827b4fd36649013c
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-21 20:05:39
Source code size: 1314 bytes / 46 lines
Pitched / IR pitched: No / No
Views / Downloads: 62 / 121
Version history: 4 change(s)
Referenced in: [show references]