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 import org.jetbrains.annotations.NotNull;
25 
31 public class DoubleImageFilter extends ImageFilter {
32 
36  private static final ColorModel RGB_DEFAULT_COLOR_MODEL = ColorModel.getRGBdefault();
37 
41  private final int doubleFaceOffset;
42 
46  private int width;
47 
51  private int @NotNull [] raster;
52 
57  public DoubleImageFilter(final int doubleFaceOffset) {
58  this.doubleFaceOffset = doubleFaceOffset;
59  }
60 
61  @Override
62  public void setDimensions(final int width, final int height) {
63  this.width = width;
64  final int newHeight = height + doubleFaceOffset;
65  raster = new int[width * newHeight];
66  super.setDimensions(width, newHeight);
67  }
68 
69  @Override
70  public void setHints(final int hints) {
71  super.setHints((hints & ~(SINGLEPASS | TOPDOWNLEFTRIGHT)) | COMPLETESCANLINES | RANDOMPIXELORDER);
72  }
73 
74  @Override
75  public void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final byte @NotNull [] pixels, final int off, final int scansize) {
76  int srcOff = off;
77  int dstOff = y * width + x;
78  for (int yc = 0; yc < h; yc++) {
79  for (int xc = 0; xc < w; xc++) {
80  raster[dstOff++] = model.getRGB(pixels[srcOff++] & 0xff);
81  }
82  srcOff += scansize - w;
83  dstOff += width - w;
84  }
85  }
86 
87  @Override
88  public void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final int @NotNull [] pixels, final int off, final int scansize) {
89  int srcOff = off;
90  int dstOff = y * width + x;
91  for (int yc = 0; yc < h; yc++) {
92  for (int xc = 0; xc < w; xc++) {
93  raster[dstOff++] = model.getRGB(pixels[srcOff++]);
94  }
95  srcOff += scansize - w;
96  dstOff += width - w;
97  }
98  }
99 
100  @Override
101  public void imageComplete(final int status) {
102  if (status != IMAGEERROR && status != IMAGEABORTED) {
103  final int offset = width * doubleFaceOffset;
104  for (int i = raster.length - 1; i >= offset; i--) {
105  if ((raster[i] & 0xFF000000) == 0) {
106  raster[i] = raster[i - offset];
107  }
108  }
109  super.setPixels(0, 0, width, raster.length / width, RGB_DEFAULT_COLOR_MODEL, raster, 0, width);
110  }
111  super.imageComplete(status);
112  }
113 
114 }
net.sf.gridarta.model.face.DoubleImageFilter.DoubleImageFilter
DoubleImageFilter(final int doubleFaceOffset)
Definition: DoubleImageFilter.java:57
net.sf.gridarta.model.face.DoubleImageFilter.setHints
void setHints(final int hints)
Definition: DoubleImageFilter.java:70
net.sf.gridarta.model.face.DoubleImageFilter.setDimensions
void setDimensions(final int width, final int height)
Definition: DoubleImageFilter.java:62
net.sf.gridarta.model.face.DoubleImageFilter
Definition: DoubleImageFilter.java:31
net.sf.gridarta.model.face.DoubleImageFilter.imageComplete
void imageComplete(final int status)
Definition: DoubleImageFilter.java:101
net.sf.gridarta.model.face.DoubleImageFilter.setPixels
void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final byte @NotNull[] pixels, final int off, final int scansize)
Definition: DoubleImageFilter.java:75
net.sf.gridarta.model.face.DoubleImageFilter.raster
int[] raster
Definition: DoubleImageFilter.java:51
net.sf.gridarta.model.face.DoubleImageFilter.RGB_DEFAULT_COLOR_MODEL
static final ColorModel RGB_DEFAULT_COLOR_MODEL
Definition: DoubleImageFilter.java:36
net.sf.gridarta.model.face.DoubleImageFilter.doubleFaceOffset
final int doubleFaceOffset
Definition: DoubleImageFilter.java:41
net.sf.gridarta.model.face.DoubleImageFilter.width
int width
Definition: DoubleImageFilter.java:46
net.sf.gridarta.model.face.DoubleImageFilter.setPixels
void setPixels(final int x, final int y, final int w, final int h, final ColorModel model, final int @NotNull[] pixels, final int off, final int scansize)
Definition: DoubleImageFilter.java:88