Gridarta Editor
DoubleImageFilter.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.face;
21 
22 import java.awt.image.ColorModel;
23 import java.awt.image.ImageFilter;
24 
30 public class DoubleImageFilter extends ImageFilter {
31 
35  private static final ColorModel RGB_DEFAULT_COLOR_MODEL = ColorModel.getRGBdefault();
36 
40  private final int doubleFaceOffset;
41 
45  private int width;
46 
50  private int[] raster;
51 
56  public DoubleImageFilter(final int doubleFaceOffset) {
57  this.doubleFaceOffset = doubleFaceOffset;
58  }
59 
60  @Override
61  public void setDimensions(final int width, final int height) {
62  this.width = width;
63  final int newHeight = height + doubleFaceOffset;
64  raster = new int[width * newHeight];
65  super.setDimensions(width, newHeight);
66  }
67 
68  @Override
69  public void setHints(final int hints) {
70  super.setHints((hints & ~(SINGLEPASS | TOPDOWNLEFTRIGHT)) | COMPLETESCANLINES | RANDOMPIXELORDER);
71  }
72 
73  @Override
74  public void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final byte[] pixels, final int off, final int scansize) {
75  int srcOff = off;
76  int dstOff = y * width + x;
77  for (int yc = 0; yc < h; yc++) {
78  for (int xc = 0; xc < w; xc++) {
79  raster[dstOff++] = model.getRGB(pixels[srcOff++] & 0xff);
80  }
81  srcOff += scansize - w;
82  dstOff += width - w;
83  }
84  }
85 
86  @Override
87  public void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final int[] pixels, final int off, final int scansize) {
88  int srcOff = off;
89  int dstOff = y * width + x;
90  for (int yc = 0; yc < h; yc++) {
91  for (int xc = 0; xc < w; xc++) {
92  raster[dstOff++] = model.getRGB(pixels[srcOff++]);
93  }
94  srcOff += scansize - w;
95  dstOff += width - w;
96  }
97  }
98 
99  @Override
100  public void imageComplete(final int status) {
101  if (status != IMAGEERROR && status != IMAGEABORTED) {
102  final int offset = width * doubleFaceOffset;
103  for (int i = raster.length - 1; i >= offset; i--) {
104  if ((raster[i] & 0xFF000000) == 0) {
105  raster[i] = raster[i - offset];
106  }
107  }
108  super.setPixels(0, 0, width, raster.length / width, RGB_DEFAULT_COLOR_MODEL, raster, 0, width);
109  }
110  super.imageComplete(status);
111  }
112 
113 }
static final ColorModel RGB_DEFAULT_COLOR_MODEL
The default RGB color model.
An ImageFilter that produces double faces: the source image is drawn twice with a vertical shift...
void setDimensions(final int width, final int height)
final int doubleFaceOffset
The offset for shifting the two images.
int [] raster
The destination image&#39;s pixels.
DoubleImageFilter(final int doubleFaceOffset)
Creates a new instance.
void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final int[] pixels, final int off, final int scansize)
void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final byte[] pixels, final int off, final int scansize)