Crossfire JXClient, Trunk
RawScale2x.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.faces;
24 
25 import org.jetbrains.annotations.NotNull;
26 
31 public class RawScale2x {
32 
36  private final int @NotNull [] srcImage;
37 
41  private final int @NotNull [] dstImage;
42 
46  private final int width;
47 
51  private final int height;
52 
60  public RawScale2x(final int @NotNull [] imageData, final int dataWidth, final int dataHeight) {
61  width = dataWidth;
62  height = dataHeight;
63  //noinspection AssignmentToCollectionOrArrayFieldFromParameter
64  srcImage = imageData;
65  dstImage = new int[imageData.length*4];
66  }
67 
75  private static boolean different(final int a, final int b) {
76  return a != b;
77  }
78 
85  private void setDestPixel(final int x, final int y, final int p) {
86  dstImage[x+y*width*2] = p;
87  }
88 
96  private int getSourcePixel(final int x, final int y) {
97  final int xx = Math.min(width-1, Math.max(0, x));
98  final int yy = Math.min(height-1, Math.max(0, y));
99  return srcImage[xx+yy*width];
100  }
101 
108  private void process(final int x, final int y) {
109  //final int a = getSourcePixel(x-1, y-1);
110  final int b = getSourcePixel(x, y-1);
111  //final int c = getSourcePixel(x+1, y-1);
112  final int d = getSourcePixel(x-1, y);
113  final int e = getSourcePixel(x, y);
114  final int f = getSourcePixel(x+1, y);
115  //final int g = getSourcePixel(x-1, y+1);
116  final int h = getSourcePixel(x, y+1);
117  //final int i = getSourcePixel(x+1, y+1);
118  final int e0;
119  final int e1;
120  final int e2;
121  final int e3;
122  if (different(b, h) && different(d, f)) {
123  e0 = different(d, b) ? e : d;
124  e1 = different(b, f) ? e : f;
125  e2 = different(d, h) ? e : d;
126  e3 = different(h, f) ? e : f;
127  } else {
128  e0 = e;
129  e1 = e;
130  e2 = e;
131  e3 = e;
132  }
133 
134  setDestPixel(x*2, y*2, e0);
135  setDestPixel(x*2+1, y*2, e1);
136  setDestPixel(x*2, y*2+1, e2);
137  setDestPixel(x*2+1, y*2+1, e3);
138  }
139 
146  public int @NotNull [] getScaledData() {
147  for (int x = 0; x < width; x++) {
148  for (int y = 0; y < height; y++) {
149  process(x, y);
150  }
151  }
152 
153  //noinspection AssignmentOrReturnOfFieldWithMutableType
154  return dstImage;
155  }
156 
157 }
com.realtime.crossfire.jxclient.faces.RawScale2x
Definition: RawScale2x.java:31
com.realtime.crossfire.jxclient.faces.RawScale2x.different
static boolean different(final int a, final int b)
Definition: RawScale2x.java:75
com.realtime.crossfire.jxclient.faces.RawScale2x.setDestPixel
void setDestPixel(final int x, final int y, final int p)
Definition: RawScale2x.java:85
com.realtime.crossfire.jxclient.faces.RawScale2x.dstImage
final int[] dstImage
Definition: RawScale2x.java:41
com.realtime.crossfire.jxclient.faces.RawScale2x.height
final int height
Definition: RawScale2x.java:51
com.realtime.crossfire.jxclient.faces.RawScale2x.srcImage
final int[] srcImage
Definition: RawScale2x.java:36
com.realtime.crossfire.jxclient.faces.RawScale2x.process
void process(final int x, final int y)
Definition: RawScale2x.java:108
com.realtime.crossfire.jxclient.faces.RawScale2x.RawScale2x
RawScale2x(final int @NotNull[] imageData, final int dataWidth, final int dataHeight)
Definition: RawScale2x.java:60
com.realtime.crossfire.jxclient.faces.RawScale2x.getSourcePixel
int getSourcePixel(final int x, final int y)
Definition: RawScale2x.java:96
com.realtime.crossfire.jxclient.faces.RawScale2x.width
final int width
Definition: RawScale2x.java:46
com.realtime.crossfire.jxclient.faces.RawScale2x.getScaledData
int[] getScaledData()
Definition: RawScale2x.java:146