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

82
LINES

< > BotCompany Repo | #1024653 // WholeImageFilter

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

Libraryless. Click here for Pure Java version (1938L/13K).

1  
/*
2  
Copyright 2006 Jerry Huxtable
3  
4  
Licensed under the Apache License, Version 2.0 (the "License");
5  
you may not use this file except in compliance with the License.
6  
You may obtain a copy of the License at
7  
8  
   http://www.apache.org/licenses/LICENSE-2.0
9  
10  
Unless required by applicable law or agreed to in writing, software
11  
distributed under the License is distributed on an "AS IS" BASIS,
12  
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  
See the License for the specific language governing permissions and
14  
limitations under the License.
15  
*/
16  
17  
/**
18  
 * A filter which acts as a superclass for filters which need to have the whole image in memory
19  
 * to do their stuff.
20  
 */
21  
static abstract class WholeImageFilter extends AbstractBufferedImageOp implements IF1<BufferedImage> {
22  
23  
  /**
24  
     * The output image bounds.
25  
     */
26  
    protected Rectangle transformedSpace;
27  
28  
  /**
29  
     * The input image bounds.
30  
     */
31  
  protected Rectangle originalSpace;
32  
  
33  
  /**
34  
   * Construct a WholeImageFilter.
35  
   */
36  
  public WholeImageFilter() {
37  
  }
38  
39  
  public BufferedImage get(BufferedImage src) {
40  
    ret filter(src, null);
41  
  }
42  
43  
    public BufferedImage filter( BufferedImage src, BufferedImage dst ) {
44  
        int width = src.getWidth();
45  
        int height = src.getHeight();
46  
    int type = src.getType();
47  
    WritableRaster srcRaster = src.getRaster();
48  
49  
    originalSpace = new Rectangle(0, 0, width, height);
50  
    transformedSpace = new Rectangle(0, 0, width, height);
51  
    transformSpace(transformedSpace);
52  
53  
        if ( dst == null ) {
54  
            ColorModel dstCM = src.getColorModel();
55  
      dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster(transformedSpace.width, transformedSpace.height), dstCM.isAlphaPremultiplied(), null);
56  
    }
57  
    WritableRaster dstRaster = dst.getRaster();
58  
59  
    int[] inPixels = getRGB( src, 0, 0, width, height, null );
60  
    inPixels = filterPixels( width, height, inPixels, transformedSpace );
61  
    setRGB( dst, 0, 0, transformedSpace.width, transformedSpace.height, inPixels );
62  
63  
        return dst;
64  
    }
65  
66  
  /**
67  
     * Calculate output bounds for given input bounds.
68  
     * @param rect input and output rectangle
69  
     */
70  
  protected void transformSpace(Rectangle rect) {
71  
  }
72  
  
73  
  /**
74  
     * Actually filter the pixels.
75  
     * @param width the image width
76  
     * @param height the image height
77  
     * @param inPixels the image pixels
78  
     * @param transformedSpace the output bounds
79  
     * @return the output pixels
80  
     */
81  
  protected abstract int[] filterPixels( int width, int height, int[] inPixels, Rectangle transformedSpace );
82  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024653
Snippet name: WholeImageFilter
Eternal ID of this version: #1024653/3
Text MD5: 0de5d2c846a339688afb242d52a8b79d
Transpilation MD5: b0ccba240d28bf66676ffffafc581f17
Author: stefan
Category: javax / imaging
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-24 14:26:52
Source code size: 2665 bytes / 82 lines
Pitched / IR pitched: No / No
Views / Downloads: 235 / 626
Version history: 2 change(s)
Referenced in: [show references]