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).

1  
// an indexing structure for grayscale images
2  
// -all images have the same size
3  
// -images are sorted by
4  
//   1. average brightness
5  
//   2. "lexical" scanline ordering (within same brightness)
6  
// -every image can have an arbitrary value associated (type "A")
7  
8  
persistable sclass ScaledGrayscaleCache<A> extends Meta is WidthAndHeight, IntSize {
9  
  int w, h;
10  
  new TreeSet<Entry> entries;
11  
  
12  
  persistable class Entry is Comparable<Entry> {
13  
    double brightness;
14  
    BWImage image;
15  
    settable A value;
16  
    
17  
    *(BWImage *image) {
18  
      brightness = image.averageBrightness();
19  
    }
20  
    
21  
    public int compareTo(Entry e) {
22  
      if (brightness != e.brightness)
23  
        ret cmp(brightness, e.brightness);
24  
      ret compareBWImagesByScanlineOrdering(image, e.image);
25  
    }
26  
  }
27  
  
28  
  *(int w) { this(w, w); }
29  
  *(int *w, int *h) {}
30  
  
31  
  public int getWidth() { ret w; }
32  
  public int getHeight() { ret h; }
33  
  
34  
  // returns true if image was new
35  
  bool add(IBWImage image) {
36  
    BWImage scaledImage = scaledBWImageFromBWIntegralImage(w, h, image);
37  
    var entry = new Entry(scaledImage);
38  
    var existingEntry = entries.floor(entry);
39  
    if (cmp(entry, existingEntry) == 0)
40  
      false;
41  
    entries.add(entry);
42  
    true;
43  
  }
44  
  
45  
  public int size() { ret entries.size(); }
46  
}

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: 65 / 125
Version history: 4 change(s)
Referenced in: [show references]