00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 package com.realtime.crossfire.jxclient.faces;
00023
00024 import org.jetbrains.annotations.NotNull;
00025
00030 public class RawScale2x {
00031
00035 @NotNull
00036 private final int[] srcImage;
00037
00041 @NotNull
00042 private final int[] dstImage;
00043
00047 private final int width;
00048
00052 private final int height;
00053
00061 public RawScale2x(@NotNull final int[] imageData, final int dataWidth, final int dataHeight) {
00062 width = dataWidth;
00063 height = dataHeight;
00064 srcImage = imageData;
00065 dstImage = new int[imageData.length*4];
00066 }
00067
00075 private static boolean different(final int a, final int b) {
00076 return a != b;
00077 }
00078
00085 private void setDestPixel(final int x, final int y, final int p) {
00086 dstImage[x+y*width*2] = p;
00087 }
00088
00096 private int getSourcePixel(final int x, final int y) {
00097 final int xx = Math.min(width-1, Math.max(0, x));
00098 final int yy = Math.min(height-1, Math.max(0, y));
00099 return srcImage[xx+yy*width];
00100 }
00101
00108 private void process(final int x, final int y) {
00109
00110 final int b = getSourcePixel(x, y-1);
00111
00112 final int d = getSourcePixel(x-1, y);
00113 final int e = getSourcePixel(x, y);
00114 final int f = getSourcePixel(x+1, y);
00115
00116 final int h = getSourcePixel(x, y+1);
00117
00118 final int e0;
00119 final int e1;
00120 final int e2;
00121 final int e3;
00122 if (different(b, h) && different(d, f)) {
00123 e0 = different(d, b) ? e : d;
00124 e1 = different(b, f) ? e : f;
00125 e2 = different(d, h) ? e : d;
00126 e3 = different(h, f) ? e : f;
00127 } else {
00128 e0 = e;
00129 e1 = e;
00130 e2 = e;
00131 e3 = e;
00132 }
00133
00134 setDestPixel(x*2, y*2, e0);
00135 setDestPixel(x*2+1, y*2, e1);
00136 setDestPixel(x*2, y*2+1, e2);
00137 setDestPixel(x*2+1, y*2+1, e3);
00138 }
00139
00146 @NotNull
00147 public int[] getScaledData() {
00148 for (int x = 0; x < width; x++) {
00149 for (int y = 0; y < height; y++) {
00150 process(x, y);
00151 }
00152 }
00153
00154 return dstImage;
00155 }
00156
00157 }