- Changed yFormatter handling to be more flexible and produce more readable code for server pages. There are serverObject.putNum() methods to allow adding of number type values in a formatted form, and put() methods for number types that add them without formatting. This reduces the need to transform them into Strings in server pages and removes the HTML encoding step which is unecessary for numbers.

- some minor code cleanups (mostly unnecessary casts, null checks)

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4166 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
fuchsi 17 years ago
parent ca83f5a8d9
commit f717beecb1

@ -145,7 +145,7 @@ public class ConfigBasic {
// port settings
String port = env.getConfig("port", "8080"); //this allows a low port, but it will only get one, if the user edits the config himself.
if(post!=null && Integer.parseInt((String)post.get("port"))>1023){
port = (String)post.get("port", "8080");
port = post.get("port", "8080");
}
// admin password

@ -130,7 +130,7 @@ public class ConfigUpdate_p {
TreeSet downloadedreleases = new TreeSet();
for (int j = 0; j < downloaded.length; j++) {
try {
release = (yacyVersion) new yacyVersion(downloaded[j]);
release = new yacyVersion(downloaded[j]);
downloadedreleases.add(release);
} catch (RuntimeException e) {
// not a valid release

@ -244,7 +244,7 @@ public final class Connections_p {
Arrays.sort(a, httpc.connectionTimeComparatorInstance);
int c = 0;
for (int i = 0; i < a.length; i++) {
httpc clientConnection = (httpc) a[i];
httpc clientConnection = a[i];
if (clientConnection != null) {
prop.put("clientList_" + c + "_clientProtocol", (clientConnection.ssl) ? "HTTPS" : "HTTP");
prop.put("clientList_" + c + "_clientLifetime", System.currentTimeMillis() - clientConnection.initTime);

@ -60,7 +60,7 @@ public class CrawlStartExpert_p {
prop.put("crawlingIfOlderNumber", Math.round((float)crawlingIfOlder / (float)(60*24)));
prop.put("crawlingIfOlderUnitDayCheck", 1);
} else if (crawlingIfOlder >= 60) {
prop.put("crawlingIfOlderNumber", Math.round((float)crawlingIfOlder / 60f));
prop.put("crawlingIfOlderNumber", Math.round(crawlingIfOlder / 60f));
prop.put("crawlingIfOlderUnitHourCheck", 1);
} else {
prop.put("crawlingIfOlderNumber", crawlingIfOlder);

@ -67,7 +67,7 @@ public class CrawlStartSimple_p {
prop.put("crawlingIfOlderNumber", Math.round((float)crawlingIfOlder / (float)(60*24)));
prop.put("crawlingIfOlderUnitDayCheck", 1);
} else if (crawlingIfOlder >= 60) {
prop.put("crawlingIfOlderNumber", Math.round((float)crawlingIfOlder / 60f));
prop.put("crawlingIfOlderNumber", Math.round(crawlingIfOlder / 60f));
prop.put("crawlingIfOlderUnitHourCheck", 1);
} else {
prop.put("crawlingIfOlderNumber", crawlingIfOlder);

@ -97,10 +97,10 @@ public class IndexControl_p {
}
// default values
String keystring = ((String) post.get("keystring", "")).trim();
String keyhash = ((String) post.get("keyhash", "")).trim();
String urlstring = ((String) post.get("urlstring", "")).trim();
String urlhash = ((String) post.get("urlhash", "")).trim();
String keystring = post.get("keystring", "").trim();
String keyhash = post.get("keyhash", "").trim();
String urlstring = post.get("urlstring", "").trim();
String urlhash = post.get("urlhash", "").trim();
if (!urlstring.startsWith("http://") &&
!urlstring.startsWith("https://")) { urlstring = "http://" + urlstring; }

@ -229,7 +229,7 @@ public class Network {
peer = yacyCore.seedDB.getConnected(peer.hash);
if (peer == null) {
prop.put("table_comment",1);
prop.put("table_comment_status","publish: disconnected peer '" + peer.getName() + "/" + post.get("peerHash") + "' from " + peer.getPublicAddress());
prop.put("table_comment_status","publish: disconnected peer 'UNKNOWN/" + post.get("peerHash") + "' from UNKNOWN");
} else {
prop.put("table_comment",2);
prop.put("table_comment_status","publish: handshaked " + peer.get(yacySeed.PEERTYPE, yacySeed.PEERTYPE_SENIOR) + " peer '" + peer.getName() + "' at " + peer.getPublicAddress());

@ -123,7 +123,7 @@ public class PerformanceMemory_p {
long mem, totalmem = 0;
while (i.hasNext()) {
filename = (String) i.next();
map = (Map) kelondroFlexTable.memoryStats(filename);
map = kelondroFlexTable.memoryStats(filename);
mem = Long.parseLong((String) map.get("tableIndexMem"));
totalmem += mem;
prop.put("TableList_" + c + "_tableIndexPath", ((p = filename.indexOf("DATA")) < 0) ? filename : filename.substring(p));
@ -141,7 +141,7 @@ public class PerformanceMemory_p {
totalmem = 0;
while (i.hasNext()) {
filename = (String) i.next();
map = (Map) kelondroCachedRecords.memoryStats(filename);
map = kelondroCachedRecords.memoryStats(filename);
mem = Long.parseLong((String) map.get("nodeCacheMem"));
totalmem += mem;
prop.put("NodeList_" + c + "_nodeCachePath", ((p = filename.indexOf("DATA")) < 0) ? filename : filename.substring(p));
@ -167,7 +167,7 @@ public class PerformanceMemory_p {
long hitmem, missmem, totalhitmem = 0, totalmissmem = 0;
while (i.hasNext()) {
filename = (String) i.next();
map = (Map) kelondroCache.memoryStats(filename);
map = kelondroCache.memoryStats(filename);
prop.put("ObjectList_" + c + "_objectCachePath", ((p = filename.indexOf("DATA")) < 0) ? filename : filename.substring(p));
// hit cache

@ -349,8 +349,8 @@ public class ViewFile {
prop.put("viewMode_links_" + i + "_dark", ((dark) ? 1 : 0));
prop.put("viewMode_links_" + i + "_type", "image");
prop.putASIS("viewMode_links_" + i + "_text", markup(wordArray, entry.alt()));
prop.put("viewMode_links_" + i + "_url", (String) entry.url().toNormalform(false, true));
prop.putASIS("viewMode_links_" + i + "_link", markup(wordArray, (String) entry.url().toNormalform(false, true)));
prop.put("viewMode_links_" + i + "_url", entry.url().toNormalform(false, true));
prop.putASIS("viewMode_links_" + i + "_link", markup(wordArray, entry.url().toNormalform(false, true)));
if (entry.width() > 0 && entry.height() > 0)
prop.putASIS("viewMode_links_" + i + "_attr", entry.width() + "x" + entry.height() + " Pixel");
else

@ -155,8 +155,8 @@ public class ViewImage {
double scale = Math.min(hs, vs);
if (!auth) scale = Math.min(scale, 0.6); // this is for copyright purpose
if (scale < 1.0) {
width = (int) (((double) w) * scale);
height = (int) (((double) h) * scale);
width = (int) (w * scale);
height = (int) (h * scale);
} else {
width = w;
height = h;

@ -43,7 +43,7 @@ import de.anomic.ymage.ymageToolPrint;
public class WebStructurePicture_p {
private static final double maxlongd = (double) Long.MAX_VALUE;
private static final double maxlongd = Long.MAX_VALUE;
public static ymageMatrix respond(httpHeader header, serverObjects post, serverSwitch env) {
plasmaSwitchboard sb = (plasmaSwitchboard) env;
@ -125,7 +125,7 @@ public class WebStructurePicture_p {
}
if (nextlayer == maxlayer) return mynodes;
nextlayer++;
double radius = 1.0 / ((double) (1 << nextlayer));
double radius = 1.0 / (1 << nextlayer);
Map next = structure.references(centerhash);
Map.Entry entry;
String targethash, targethost;
@ -147,7 +147,7 @@ public class WebStructurePicture_p {
targets.add(new String[] {targethash, targethost});
if (graph.getPoint(targethost) != null) continue;
// set a new point. It is placed on a circle around the host point
double angle = ((double) kelondroBase64Order.enhancedCoder.cardinal((targethash + "____").getBytes())) / maxlongd * 2 * Math.PI;
double angle = kelondroBase64Order.enhancedCoder.cardinal((targethash + "____").getBytes()) / maxlongd * 2 * Math.PI;
//System.out.println("ANGLE = " + angle);
rr = radius * 0.25 * (1 - targetrefs / maxtargetrefs);
re = radius * 0.5 * (thisrefs / maxthisrefs);

@ -377,7 +377,7 @@ public class dir {
new Date(), // freshtime
"AAAAAAAAAAAA", // referrer
md5, // md5
(long) phrase.length(), // size
phrase.length(), // size
condenser.RESULT_NUMB_WORDS, // word count
plasmaHTCache.DT_SHARE, // doctype
new kelondroBitfield(4),

@ -226,7 +226,7 @@ public final class search {
//yacyCore.log.logFine("DEBUG HASH SEARCH: " + indexabstract);
}
}
if (partitions > 0) sb.requestedQueries = sb.requestedQueries + 1d / (double) partitions; // increase query counter
if (partitions > 0) sb.requestedQueries = sb.requestedQueries + 1d / partitions; // increase query counter
// prepare reference hints
localProcess.startTimer();

@ -75,7 +75,7 @@ public final class transferRWI {
// request values
final String iam = post.get("iam", ""); // seed hash of requester
final String youare = (String) post.get("youare", ""); // seed hash of the target peer, needed for network stability
final String youare = post.get("youare", ""); // seed hash of the target peer, needed for network stability
// final String key = (String) post.get("key", ""); // transmission key
final int wordc = Integer.parseInt(post.get("wordc", "")); // number of different words
final int entryc = Integer.parseInt(post.get("entryc", "")); // number of entries in indexes

@ -149,7 +149,7 @@ public class htmlFilterContentScraper extends htmlFilterAbstractScraper implemen
if ((b.length() != 0) && (!(punctuation(b.charAt(b.length() - 1))))) b.append((int) '.');
//System.out.println("*** Appended dot: " + b.toString());
}
if (b.length() != 0) content.append(b).append((int) 32);
if (b.length() != 0) content.append(b).append(32);
}
public static final String splitrex = " |/|\\(|\\)|-|\\:|_|\\.|,|\\?|!|'|" + '"';

@ -793,9 +793,9 @@ public final class httpdProxyHandler {
if (charSet == null) charSet = httpHeader.DEFAULT_CHARSET;
// make a transformer
if ((!(transformer.isIdentityTransformer())) &&
((ext == null) || (!(plasmaParser.supportedRealtimeFileExtContains(url)))) &&
((cachedResponseHeader == null) || (plasmaParser.realtimeParsableMimeTypesContains(cachedResponseHeader.mime())))) {
if (( !transformer.isIdentityTransformer()) &&
(ext == null || !plasmaParser.supportedRealtimeFileExtContains(url)) &&
(plasmaParser.realtimeParsableMimeTypesContains(cachedResponseHeader.mime()))) {
hfos = new htmlFilterWriter((chunkedOut != null) ? chunkedOut : respond, charSet, null, transformer, (ext.length() == 0));
} else {
hfos = (gzippedOut != null) ? gzippedOut : ((chunkedOut != null)? chunkedOut : respond);

@ -76,7 +76,7 @@ public class kelondroBufferedRA extends kelondroAbstractRA implements kelondroRA
}
public int read() throws IOException {
return (int) 0xff & sbb.byteAt((int) pos++);
return 0xff & sbb.byteAt((int) pos++);
}
public int read(byte[] b, int off, int len) throws IOException {

@ -538,7 +538,7 @@ public class kelondroRow {
bb.append((new kelondroBitfield(getColBytes(i))).exportB64());
} else if ((decimalCardinal) && (row[i].celltype() == kelondroColumn.celltype_binary)) {
assert row[i].cellwidth() == 1;
bb.append(Integer.toString((int) (0xff & getColByte(i))));
bb.append(Integer.toString((0xff & getColByte(i))));
} else {
bb.append(rowinstance, offset + colstart[i], row[i].cellwidth());
}

@ -208,8 +208,8 @@ public final class plasmaCondenser {
htmlFilterImageEntry ientry;
while (i.hasNext()) {
ientry = (htmlFilterImageEntry) i.next();
insertTextToWords((String) ientry.url().toNormalform(false, true), 99, flag_cat_hasimage, wflags);
insertTextToWords((String) ientry.alt(), 99, flag_cat_hasimage, wflags);
insertTextToWords(ientry.url().toNormalform(false, true), 99, flag_cat_hasimage, wflags);
insertTextToWords(ientry.alt(), 99, flag_cat_hasimage, wflags);
}
// finally check all words for missing flag entry

@ -96,8 +96,8 @@ public class plasmaGrafics {
this.color = color;
}
public int getAngle() { return (int)Math.round(360f*this.fraction); }
public int getFractionPercent() { return (int)Math.round(100f*this.fraction); }
public int getAngle() { return Math.round(360f*this.fraction); }
public int getFractionPercent() { return Math.round(100f*this.fraction); }
public Color getColor() { return this.color; }
public long getExecTime() { return this.execTime; }
public String getPieceName() { return this.pieceName; }
@ -133,7 +133,7 @@ public class plasmaGrafics {
// get a copy of a recent network picture
ymageMatrix eventPicture = getNetworkPicture(120000, plasmaSwitchboard.getSwitchboard().getConfig("network.unit.name", "unspecified"), plasmaSwitchboard.getSwitchboard().getConfig("network.unit.description", "unspecified"), COL_BACKGROUND);
if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture);
//if (eventPicture instanceof ymageMatrix) eventPicture = (ymageMatrix) eventPicture; //new ymageMatrix((ymageMatrix) eventPicture);
// TODO: fix cloning of ymageMatrix pictures
// get dimensions

@ -682,8 +682,8 @@ public class plasmaSnippetCache {
ArrayList result = new ArrayList();
while (i.hasNext()) {
ientry = (htmlFilterImageEntry) i.next();
url = (String) ientry.url().toNormalform(true, true);
desc = (String) ientry.alt();
url = ientry.url().toNormalform(true, true);
desc = ientry.alt();
s = removeAppearanceHashes(url, queryhashes);
if (s.size() == 0) {
result.add(new MediaSnippet(plasmaSearchQuery.CONTENTDOM_IMAGE, url, desc, ientry.width() + " x " + ientry.height()));

@ -225,8 +225,8 @@ public final class serverLog {
if (b.length == 0) return "[]";
length = Math.min(length, b.length - start);
StringBuffer sb = new StringBuffer(b.length * 4);
sb.append('[').append(Integer.toString((int) b[start])).append(',');
for (int i = 1; i < length; i++) sb.append(' ').append(Integer.toString((int) b[start + i])).append(',');
sb.append('[').append(Integer.toString(b[start])).append(',');
for (int i = 1; i < length; i++) sb.append(' ').append(Integer.toString(b[start + i])).append(',');
sb.append(']');
return sb.toString();
}
@ -240,7 +240,7 @@ public final class serverLog {
sb.append('\n').append("# ").append(Integer.toHexString(i)).append(": ");
else
sb.append(',');
sb.append(' ').append(Integer.toString(0xff & (int) b[i]));
sb.append(' ').append(Integer.toString(0xff & b[i]));
if (i >= 65535) break;
}
sb.append('\n');

@ -72,8 +72,8 @@ public final class serverCodings {
if (in == null) return "";
StringBuffer result = new StringBuffer(in.length * 8 / 3);
for (int i = 0; i < in.length; i++) {
if ((0Xff & (int) in[i]) < 8) result.append('0');
result.append(Integer.toOctalString(0Xff & (int) in[i]));
if ((0Xff & in[i]) < 8) result.append('0');
result.append(Integer.toOctalString(0Xff & in[i]));
}
return new String(result);
}
@ -82,8 +82,8 @@ public final class serverCodings {
if (in == null) return "";
StringBuffer result = new StringBuffer(in.length * 2);
for (int i = 0; i < in.length; i++) {
if ((0Xff & (int) in[i]) < 16) result.append('0');
result.append(Integer.toHexString(0Xff & (int) in[i]));
if ((0Xff & in[i]) < 16) result.append('0');
result.append(Integer.toHexString(0Xff & in[i]));
}
return new String(result);
}

@ -69,6 +69,7 @@ import java.util.Map;
import de.anomic.data.htmlTools;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.tools.yFormatter;
public class serverObjects extends Hashtable implements Cloneable {
@ -99,35 +100,102 @@ public class serverObjects extends Hashtable implements Cloneable {
}
}
// byte[] variant
/**
* Add byte array to the map, value is kept as it is.
* @param key key name as String.
* @param value mapped value as a byte array.
* @return the added value.
*/
public byte[] put(String key, byte[] value) {
return (byte[]) this.put((Object) key, (Object) value); //TODO: use wikiCode.replaceXMLEntities?!
}
// string variant
/**
* Add a String to the map. The content of the String is escaped to be usable in HTML output.
* @param key key name as String.
* @param value a String that will be reencoded for HTML output.
* @return the modified String that was added to the map.
* @see htmlTools#encodeUnicode2html(String, boolean)
*/
public String put(String key, String value) {
return (String) put((Object) key, (Object) htmlTools.encodeUnicode2html(value, true));
}
/**
* Add an unformatted String representation of a double/float value
* to the map.
* @param key key name as String.
* @param value value as double/float.
* @return value as it was added to the map or <code>NaN</code> if an error occured.
*/
public double put(String key, double value) {
String ret = this.put(key, Double.toString(value));
if (ret == null) {
return Double.NaN;
} else try {
return Double.parseDouble(ret);
} catch (NumberFormatException e) {
return Double.NaN;
}
}
/**
* same as {@link #put(String, double)} but for integer types
* @return Returns 0 for the error case.
*/
public long put(String key, long value) {
String result = this.put(key, Long.toString(value));
if (result == null) {
return 0;
} else try {
return Long.parseLong(result);
} catch (NumberFormatException e) {
return 0;
}
}
/**
* Add a byte/long/integer to the map. The number will be encoded into a String using
* a localized format specified by {@link yFormatter}.
* @param key key name as String.
* @param value integer type value to be added to the map in its formatted String
* representation.
* @return the String value added to the map.
*/
public String putNum(String key, long value) {
return (String) this.put((Object) key, (Object) yFormatter.number(value));
}
/**
* Variant for double/float types.
* @see #putNum(String, long)
*/
public String putNum(String key, double value) {
return (String) this.put((Object) key, (Object) yFormatter.number(value));
}
// ASIS methods don't reencode the values before adding them to the map
public byte[] putASIS(String key, byte[] value) {
return (byte[]) this.put((Object) key, (Object) value);
}
public String putASIS(Object key, String value) {
return (String) this.put(key, (Object) value);
public String putASIS(String key, String value) {
return (String) this.put((Object) key, (Object) value);
}
public String putWiki(Object key, String wikiCode){
public String putWiki(String key, String wikiCode){
return this.putASIS(key, plasmaSwitchboard.wikiParser.transform(wikiCode));
}
public String putWiki(Object key, byte[] wikiCode) {
public String putWiki(String key, byte[] wikiCode) {
try {
return this.putASIS(key, plasmaSwitchboard.wikiParser.transform(wikiCode));
} catch (UnsupportedEncodingException e) {
return this.putASIS(key, "Internal error pasting wiki-code: " + e.getMessage());
}
}
public String putWiki(Object key, String wikiCode, String publicAddress) {
public String putWiki(String key, String wikiCode, String publicAddress) {
return this.putASIS(key, plasmaSwitchboard.wikiParser.transform(wikiCode, publicAddress));
}
public String putWiki(Object key, byte[] wikiCode, String publicAddress) {
public String putWiki(String key, byte[] wikiCode, String publicAddress) {
try {
return this.putASIS(key, plasmaSwitchboard.wikiParser.transform(wikiCode, "UTF-8", publicAddress));
} catch (UnsupportedEncodingException e) {
@ -135,16 +203,6 @@ public class serverObjects extends Hashtable implements Cloneable {
}
}
// long variant
public long put(String key, long value) {
String result = this.put(key, Long.toString(value));
if (result == null) return 0; else try {
return Long.parseLong(result);
} catch (NumberFormatException e) {
return 0;
}
}
// inc variant: for counters
public long inc(String key) {
String c = (String) super.get(key);

@ -54,29 +54,35 @@ import java.util.Locale;
* to the locale set for YaCy.
*/
public final class yFormatter {
// default formatter
private static NumberFormat numForm = NumberFormat.getInstance(new Locale("en"));
// generic formatter that can be used when no localized formatting is allowed
private static final NumberFormat cleanNumForm =
new DecimalFormat("####.##", new DecimalFormatSymbols(Locale.ENGLISH));
static {
// just initialize defaults on class load
initDefaults();
}
/**
* @param locale the locale to set
* @param locale the {@link Locale} to set or <code>null</code> to set the special
* empty locale to create unformatted numbers
*/
public static void setLocale(Locale locale) {
numForm = NumberFormat.getInstance(locale);
numForm = (locale == null ? cleanNumForm : NumberFormat.getInstance(locale));
initDefaults();
}
/**
* @param lang an ISO 639 language code which is used to generate a {@link Locale}
*/
public static void setLocale(String lang) {
String l = (lang.equalsIgnoreCase("default") ? "en" : lang.toLowerCase());
if (l.equals("none")) {
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.ENGLISH);
dfs.setGroupingSeparator('.'); // not used
numForm = new DecimalFormat("####.##", dfs);
} else {
setLocale(new Locale(l));
initDefaults();
}
setLocale(l.equals("none") ? null : new Locale(l));
}
private static void initDefaults() {
@ -85,10 +91,16 @@ public final class yFormatter {
numForm.setMaximumFractionDigits(2); // 2 decimal digits for float/double
}
public static String number(double d, boolean localized) {
return (localized ? number(d) : cleanNumForm.format(d));
}
public static String number(double d) {
return numForm.format(d);
}
public static String number(long l, boolean localized) {
return (localized ? number(l) : cleanNumForm.format(l));
}
public static String number(long l) {
return numForm.format(l);
}

@ -76,20 +76,20 @@ public class ymageBMPParser {
public static final int DWORD(byte[] b, int offset) {
if (offset + 3 >= b.length) return 0;
int ret = ((int) b[offset + 3] & 0xff);
ret = (ret << 8) | ((int) b[offset + 2] & 0xff);
ret = (ret << 8) | ((int) b[offset + 1] & 0xff);
ret = (ret << 8) | ((int) b[offset] & 0xff);
int ret = (b[offset + 3] & 0xff);
ret = (ret << 8) | (b[offset + 2] & 0xff);
ret = (ret << 8) | (b[offset + 1] & 0xff);
ret = (ret << 8) | (b[offset] & 0xff);
return ret;
}
public static final int WORD(byte[] b, int offset) {
int ret = (((int) b[offset + 1] & 0xff) << 8) | ((int) b[offset] & 0xff);
int ret = ((b[offset + 1] & 0xff) << 8) | (b[offset] & 0xff);
return ret;
}
public static final int BYTE(byte[] b, int offset) {
int ret = ((int) b[offset] & 0xff);
int ret = (b[offset] & 0xff);
return ret;
}
@ -172,7 +172,7 @@ public class ymageBMPParser {
int b;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns = columns + 8) {
b = ((int) s[offset + n] & 0xff);
b = (s[offset + n] & 0xff);
n++;
image.setRGB(columns, (height - rows - 1), colortable.colorindex[(b & 0x80) >> 7]);
image.setRGB(columns + 1, (height - rows - 1), colortable.colorindex[(b & 0x40) >> 6]);
@ -192,7 +192,7 @@ public class ymageBMPParser {
int b;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns = columns + 2) {
b = ((int) s[offset + n] & 0xff);
b = (s[offset + n] & 0xff);
n++;
image.setRGB(columns, (height - rows - 1), colortable.colorindex[(b & 0xf0) >> 4]);
image.setRGB(columns + 1, (height - rows - 1), colortable.colorindex[b & 0xf]);
@ -205,7 +205,7 @@ public class ymageBMPParser {
int n = 0;
for (int rows = 0; rows < height; rows++) {
for (int columns = 0; columns < width; columns++) {
image.setRGB(columns, (height - rows - 1), colortable.colorindex[((int) s[offset + n] & 0xff)]);
image.setRGB(columns, (height - rows - 1), colortable.colorindex[(s[offset + n] & 0xff)]);
n++;
}
n += fill4(n);

@ -63,21 +63,21 @@ public class ymageCaptcha extends ymageMatrix {
int x;
int y;
int ub = 0;
int widthPerChar = (int)(width/chars);
int widthPerChar = width/chars;
int pixels = width * height;
//printing code
for(int i=0;i<chars;i++){
y = random.nextInt((int)(height/2)) + (int)(height/4);
y = random.nextInt(height/2) + (height/4);
setColor(((random.nextInt(128)+64)<<16) + ((random.nextInt(128)+64)<<8) + random.nextInt(128)+64);
ymageToolPrint.print(this, widthPerChar*i+random.nextInt((int)(widthPerChar/2)) , y , 0, code.substring(i,i+1), -1);
ymageToolPrint.print(this, widthPerChar*i+random.nextInt(widthPerChar/2) , y , 0, code.substring(i,i+1), -1);
}
//adding some noise
//random pixels
ub = (int)(pixels/100);
ub = pixels/100;
for(int i=0;i<ub;i++){
setColor(((random.nextInt(128)+64)<<16) + ((random.nextInt(128)+64)<<8) + random.nextInt(128)+64);
x = random.nextInt(width);
@ -86,7 +86,7 @@ public class ymageCaptcha extends ymageMatrix {
}
//random lines
ub = (int)(pixels/1000);
ub = pixels/1000;
for(int i=0;i<ub;i++){
setColor(((random.nextInt(128)+64)<<16) + ((random.nextInt(128)+64)<<8) + random.nextInt(128)+64);
x = random.nextInt(width);

Loading…
Cancel
Save