Crossfire JXClient, Trunk
RawScale8d.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 java.util.HashMap;
26 import java.util.Map;
27 import java.util.Map.Entry;
28 import org.jetbrains.annotations.NotNull;
29 
34 public class RawScale8d {
35 
39  private final int @NotNull [] srcImage;
40 
44  private final int @NotNull [] dstImage;
45 
49  private final int width;
50 
54  private final int height;
55 
59  @NotNull
60  private final Map<Integer, Integer> pixels = new HashMap<>();
61 
68  public RawScale8d(final int @NotNull [] imageData, final int dataWidth, final int dataHeight) {
69  width = dataWidth;
70  height = dataHeight;
71  //noinspection AssignmentOrReturnOfFieldWithMutableType
72  srcImage = imageData;
73  dstImage = new int[imageData.length*4];
74  }
75 
82  private void setDestPixel(final int x, final int y, final int p) {
83  dstImage[x+y*width/8] = p;
84  }
85 
92  private int getSourcePixel(final int x, final int y) {
93  return srcImage[x+y*width];
94  }
95 
101  private void process(final int x, final int y) {
102  pixels.clear();
103  for (int dx = 0; dx < 8; dx++) {
104  for (int dy = 0; dy < 8; dy++) {
105  final int value = getSourcePixel(8*x+dx, 8*y+dy);
106  if (value != 0) {
107  final Integer count = pixels.get(value);
108  pixels.put(value, count == null ? 1 : count+1);
109  }
110  }
111  }
112  int maxCount = 0;
113  int maxPixel = 0;
114  for (Entry<Integer, Integer> e : pixels.entrySet()) {
115  final int thisCount = e.getValue();
116  if (thisCount > maxCount) {
117  maxCount = thisCount;
118  maxPixel = e.getKey();
119  }
120  }
121  pixels.clear();
122 
123  setDestPixel(x, y, maxPixel);
124  }
125 
132  public int @NotNull [] getScaledData() {
133  for (int x = 0; x < width/8; x++) {
134  for (int y = 0; y < height/8; y++) {
135  process(x, y);
136  }
137  }
138 
139  //noinspection AssignmentOrReturnOfFieldWithMutableType
140  return dstImage;
141  }
142 
143 }
com.realtime.crossfire.jxclient.faces.RawScale8d.process
void process(final int x, final int y)
Definition: RawScale8d.java:101
com.realtime.crossfire.jxclient.faces.RawScale8d.pixels
final Map< Integer, Integer > pixels
Definition: RawScale8d.java:60
com.realtime.crossfire.jxclient.faces.RawScale8d.height
final int height
Definition: RawScale8d.java:54
com.realtime.crossfire.jxclient.faces.RawScale8d.getScaledData
int[] getScaledData()
Definition: RawScale8d.java:132
com.realtime.crossfire.jxclient.faces.RawScale8d.RawScale8d
RawScale8d(final int @NotNull[] imageData, final int dataWidth, final int dataHeight)
Definition: RawScale8d.java:68
com.realtime.crossfire.jxclient.faces.RawScale8d
Definition: RawScale8d.java:34
com.realtime.crossfire.jxclient.faces.RawScale8d.width
final int width
Definition: RawScale8d.java:49
com.realtime.crossfire.jxclient.faces.RawScale8d.setDestPixel
void setDestPixel(final int x, final int y, final int p)
Definition: RawScale8d.java:82
com.realtime.crossfire.jxclient.faces.RawScale8d.srcImage
final int[] srcImage
Definition: RawScale8d.java:39
com.realtime.crossfire.jxclient.faces.RawScale8d.getSourcePixel
int getSourcePixel(final int x, final int y)
Definition: RawScale8d.java:92
com.realtime.crossfire.jxclient.faces.RawScale8d.dstImage
final int[] dstImage
Definition: RawScale8d.java:44