comparison exporters.pde @ 196:5c08f024e542

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 23 Aug 2018 20:24:04 +0300
parents 934934bb1fbb
children 4bdb6d0df3ca
comparison
equal deleted inserted replaced
195:b36cfb497223 196:5c08f024e542
1040 if (image.width <= 16 || image.height <= 16) 1040 if (image.width <= 16 || image.height <= 16)
1041 return false; 1041 return false;
1042 1042
1043 int balx, baly, xx, yy, x2, y2, rr, gg, bb, avg, i, j, target; 1043 int balx, baly, xx, yy, x2, y2, rr, gg, bb, avg, i, j, target;
1044 int cx, cy; 1044 int cx, cy;
1045 int aas, bbs, swap, idefix, avx, avy; 1045 int swap, idefix, avx, avy;
1046 int[] pixut = new int[260]; 1046 int[] pixut = new int[260];
1047 int[] idx = new int[260]; 1047 int[] idx = new int[260];
1048 int[] histog = new int[8192]; 1048 int[] histog = new int[8192];
1049 float ww, hh, fld, compa; 1049 float ww, hh, fld, compa;
1050 color c; 1050 color c;
1147 for (i = 0; i < xcolors; i++) 1147 for (i = 0; i < xcolors; i++)
1148 { 1148 {
1149 pixut[i] = 0; 1149 pixut[i] = 0;
1150 idx[i] = i; 1150 idx[i] = i;
1151 } 1151 }
1152 for (yy = cy * vertti; yy <= cy * vertti + vertti - 1; yy++) { 1152 for (yy = cy * vertti; yy <= cy * vertti + vertti - 1; yy++)
1153 for (xx = cx * 8; xx <= cx * 8 + 7; xx = xx + g_pixelw) { 1153 for (xx = cx * 8; xx <= cx * 8 + 7; xx = xx + g_pixelw)
1154 x2 = int(image.width / X) * xx; 1154 {
1155 y2 = int(image.height / Y) * yy; 1155 x2 = int(image.width / X) * xx;
1156 rr = 0; 1156 y2 = int(image.height / Y) * yy;
1157 gg = 0; 1157 rr = 0;
1158 bb = 0; 1158 gg = 0;
1159 avg = 0; 1159 bb = 0;
1160 1160 avg = 0;
1161 for (avy = 0; avy < baly; avy++) 1161
1162 for (avx = 0; avx < balx; avx++) 1162 for (avy = 0; avy < baly; avy++)
1163 for (avx = 0; avx < balx; avx++)
1164 {
1165 c = image.get(x2 + avx, y2 + avy);
1166 rr += int(red(c));
1167 gg += int(green(c));
1168 bb += int(blue(c));
1169 avg++;
1170 }
1171
1172 rr = int(rr / avg);
1173 gg = int(gg / avg);
1174 bb = int(bb / avg);
1175 g_farge = 0;
1176 target = -1;
1177 compa = 9999;
1178 for (i = 0; i < xcolors; i++)
1179 {
1180 fld = dist(rr, gg, bb, g_r[i], g_g[i], g_b[i]);
1181 if (fld < compa)
1163 { 1182 {
1164 c = image.get(x2 + avx, y2 + avy); 1183 compa = fld;
1165 rr += int(red(c)); 1184 target = i;
1166 gg += int(green(c));
1167 bb += int(blue(c));
1168 avg++;
1169 } 1185 }
1170
1171 rr = int(rr / avg);
1172 gg = int(gg / avg);
1173 bb = int(bb / avg);
1174 g_farge = 0;
1175 target = -1;
1176 compa = 9999;
1177 for (i = 0; i < xcolors; i++)
1178 {
1179 fld = dist(rr, gg, bb, g_r[i], g_g[i], g_b[i]);
1180 if (fld < compa)
1181 {
1182 compa = fld;
1183 target = i;
1184 }
1185 }
1186
1187 g_farge = target;
1188 pixut[target]++; //histogramming
1189 } 1186 }
1190 } 1187
1191 1188 g_farge = target;
1192 for (aas = 0; aas < xcolors; aas++) 1189 pixut[target]++; //histogramming
1193 for (bbs = 0; bbs <= aas; bbs++) 1190 }
1191
1192 for (int aas = 0; aas < xcolors; aas++)
1193 for (int bbs = 0; bbs <= aas; bbs++)
1194 { 1194 {
1195 if (pixut[aas] > pixut[bbs]) 1195 if (pixut[aas] > pixut[bbs])
1196 { 1196 {
1197 swap = pixut[aas]; 1197 swap = pixut[aas];
1198 pixut[aas] = pixut[bbs]; 1198 pixut[aas] = pixut[bbs];
1204 } 1204 }
1205 1205
1206 for (idefix = 0; idefix < limitter; idefix++) 1206 for (idefix = 0; idefix < limitter; idefix++)
1207 { 1207 {
1208 i = idx[idefix]; 1208 i = idx[idefix];
1209
1209 for (yy = cy * vertti; yy <= cy * vertti + vertti - 1; yy++) 1210 for (yy = cy * vertti; yy <= cy * vertti + vertti - 1; yy++)
1210 for (xx = cx * 8; xx <= cx * 8 + 7; xx = xx + g_pixelw) 1211 for (xx = cx * 8; xx <= cx * 8 + 7; xx = xx + g_pixelw)
1211 { 1212 {
1212 x2 = int(image.width / X) * xx; 1213 x2 = int(image.width / X) * xx;
1213 y2 = int(image.height / Y) * yy; 1214 y2 = int(image.height / Y) * yy;
1215 rr = 0; 1216 rr = 0;
1216 gg = 0; 1217 gg = 0;
1217 bb = 0; 1218 bb = 0;
1218 avg = 0; 1219 avg = 0;
1219 for (avy = 0; avy < baly; avy++) 1220 for (avy = 0; avy < baly; avy++)
1220 for (avx = 0; avx < balx; avx++) { 1221 for (avx = 0; avx < balx; avx++)
1222 {
1221 c = image.get(x2 + avx, y2 + avy); 1223 c = image.get(x2 + avx, y2 + avy);
1222 rr = rr + int(red(c)); 1224 rr = rr + int(red(c));
1223 gg = gg + int(green(c)); 1225 gg = gg + int(green(c));
1224 bb = bb + int(blue(c)); 1226 bb = bb + int(blue(c));
1225 avg++; 1227 avg++;
1226 } 1228 }
1227 1229
1228 rr = int(rr / avg); 1230 rr = int(rr / avg);
1229 gg = int(gg / avg); 1231 gg = int(gg / avg);
1230 bb = int(bb / avg); 1232 bb = int(bb / avg);
1233
1231 g_farge = 0; 1234 g_farge = 0;
1232 target = -1; 1235 target = -1;
1233 compa = 9999; 1236 compa = 9999;
1234 for (j = 0; j < limitter; j++) 1237 for (j = 0; j < limitter; j++)
1235 { 1238 {
1236 fld = dist(rr, gg, bb, g_r[idx[j]], g_g[idx[j]], g_b[idx[j]]); 1239 fld = dist(rr, gg, bb, g_r[idx[j]], g_g[idx[j]], g_b[idx[j]]);
1237 if (fld < compa) { 1240 if (fld < compa)
1241 {
1238 compa = fld; 1242 compa = fld;
1239 target = idx[j]; 1243 target = idx[j];
1240 } 1244 }
1241 } 1245 }
1242 if (i == target) 1246 if (i == target)
1263 void mpRenderToImageAt(PImage output, int xoffs, int yoffs, int omag) 1267 void mpRenderToImageAt(PImage output, int xoffs, int yoffs, int omag)
1264 { 1268 {
1265 if (output == null) 1269 if (output == null)
1266 return; 1270 return;
1267 1271
1272 color c = color(g_r[259], g_g[259], g_b[259]);
1268 for (int yy = 0; yy < output.width; yy++) 1273 for (int yy = 0; yy < output.width; yy++)
1269 for (int xx = 0; xx < output.width; xx++) 1274 for (int xx = 0; xx < output.width; xx++)
1270 {
1271 color c = color(g_r[259], g_g[259], g_b[259]);
1272 output.set(xx, yy, c); 1275 output.set(xx, yy, c);
1273 }
1274 1276
1275 for (int yy = 0; yy < Y; yy++) 1277 for (int yy = 0; yy < Y; yy++)
1276 for (int xx = 0; xx < X; xx++) 1278 for (int xx = 0; xx < X; xx++)
1277 { 1279 {
1278 int f; 1280 int f;
1283 // f = getabsa(xx, yy, 0); 1285 // f = getabsa(xx, yy, 0);
1284 1286
1285 if (g_machine == MSX && f == 0) 1287 if (g_machine == MSX && f == 0)
1286 f = g_map[1]; 1288 f = g_map[1];
1287 1289
1288 color c = color(g_r[f], g_g[f], g_b[f]); 1290 c = color(g_r[f], g_g[f], g_b[f]);
1289 1291
1290 for (int vertti = 0; vertti <= omag; vertti++) 1292 for (int vertti = 0; vertti <= omag; vertti++)
1291 for (int mortti = 0; mortti <= omag; mortti++) 1293 for (int mortti = 0; mortti <= omag; mortti++)
1292 { 1294 {
1293 output.set( 1295 output.set(