Merge branch 'master' of ssh://git@gitorious.org/yacy/rc1.git

pull/1/head
orbiter 12 years ago
commit 3e79bd4b1f

@ -68,7 +68,7 @@ public class RankingSolr_p {
}
}
if (post != null && post.containsKey("ResetBoosts")) {
String s = "text_t^2.0,url_paths_sxt^20.0,title^100.0,synonyms_sxt^1.0";
String s = "url_paths_sxt^1000.0,synonyms_sxt^1.0,title^10000.0,text_t^2.0,h1_txt^1000.0,h2_txt^100.0,host_organization_s^100000.0";
sb.setConfig(SwitchboardConstants.SEARCH_RANKING_SOLR_COLLECTION_BOOSTFIELDS_ + profileNr, s);
sb.index.fulltext().getDefaultConfiguration().getRanking(profileNr).updateBoosts(s);
}
@ -96,7 +96,7 @@ public class RankingSolr_p {
}
}
if (post != null && post.containsKey("ResetBF")) {
String bf = ""; //"div(add(1,references_i),pow(add(1,inboundlinkscount_i),1.6))";
String bf = "product(recip(rord(last_modified),1,1000,1000),div(product(log(product(references_external_i,references_exthosts_i)),div(references_internal_i,host_extent_i)),add(clickdepth_i,1)))";
if (bf != null) {
sb.setConfig(SwitchboardConstants.SEARCH_RANKING_SOLR_COLLECTION_BOOSTFUNCTION_ + profileNr, bf);
sb.index.fulltext().getDefaultConfiguration().getRanking(profileNr).setBoostFunction(bf);

@ -52,6 +52,12 @@ public final class ByteBuffer extends OutputStream {
this.offset = 0;
}
public ByteBuffer(final byte[] bb) {
this.buffer = bb;
this.length = bb.length;
this.offset = 0;
}
public ByteBuffer(final String s) {
this.buffer = UTF8.getBytes(s);
this.length = this.buffer.length;

@ -1,17 +1,52 @@
/**
* EncodedImage
* Copyright 2010 by Michael Christen
* First released 28.07.2010 at http://yacy.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21.txt
* If not, see <http://www.gnu.org/licenses/>.
*/
package net.yacy.peers.graphics;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import net.yacy.kelondro.util.ByteBuffer;
import net.yacy.visualization.AnimationGIF;
import net.yacy.visualization.RasterPlotter;
public class EncodedImage {
private ByteBuffer image;
private String extension;
public EncodedImage(final RasterPlotter sourceImage, final String targetExt) {
this.image = "png".equals(targetExt) ? sourceImage.exportPng() : RasterPlotter.exportImage(sourceImage.getImage(), targetExt);
this.extension = targetExt;
}
public EncodedImage(final AnimationGIF sourceImage) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
bos.write(sourceImage.get());
bos.close();
} catch (IOException e) {
}
this.image = new ByteBuffer(bos.toByteArray());
this.extension = "gif";
}
public ByteBuffer getImage() {
return this.image;
}

@ -58,7 +58,7 @@ public class NetworkGraph {
private static int longestName = 30;
public static final String COL_BACKGROUND = "FFFFFF";
private static final String COL_DHTCIRCLE = "006020";
public static final String COL_DHTCIRCLE = "006020";
private static final String COL_HEADLINE = "FFFFFF";
private static final String COL_ACTIVE_DOT = "000044";
private static final String COL_ACTIVE_LINE = "113322";

@ -854,7 +854,7 @@ public final class Fulltext {
this.failure = null;
this.format = format;
this.dom = dom;
if ((dom) && (format == 2)) dom = false;
//if ((dom) && (format == 2)) dom = false;
}
@Override
@ -878,7 +878,7 @@ public final class Fulltext {
if (this.dom) {
Map<String, ReversibleScoreMap<String>> scores = Fulltext.this.getDefaultConnector().getFacets(CollectionSchema.httpstatus_i.getSolrFieldName() + ":200", 100000, CollectionSchema.host_s.getSolrFieldName());
Map<String, ReversibleScoreMap<String>> scores = Fulltext.this.getDefaultConnector().getFacets(CollectionSchema.httpstatus_i.getSolrFieldName() + ":200", 100000000, CollectionSchema.host_s.getSolrFieldName());
ReversibleScoreMap<String> stats = scores.get(CollectionSchema.host_s.getSolrFieldName());
for (final String host: stats) {
if (this.pattern != null && !this.pattern.matcher(host).matches()) continue;

@ -574,7 +574,7 @@ public final class HTTPDFileHandler {
servletProperties templatePatterns = null;
Date targetDate;
if ((targetClass != null) && (path.endsWith("png"))) {
if ((targetClass != null) && ((path.endsWith("png") || path.endsWith("gif")))) {
// call an image-servlet to produce an on-the-fly - generated image
Object img = null;
requestHeader.put(HeaderFramework.CONNECTION_PROP_CLIENTIP, (String) conProp.get(HeaderFramework.CONNECTION_PROP_CLIENTIP));

@ -2,10 +2,6 @@
* AnimationGIF
* Copyright 2010 by Michael Christen
* First released 20.11.2010 at http://yacy.net
*
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -49,7 +45,10 @@ import javax.imageio.stream.MemoryCacheImageOutputStream;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/*
* for a GIF Image Metadata Format Specification, see:
* http://docs.oracle.com/javase/6/docs/api/javax/imageio/metadata/doc-files/gif_metadata.html
*/
public class AnimationGIF {
private final static String formatName = "javax_imageio_gif_image_1.0";
@ -57,6 +56,8 @@ public class AnimationGIF {
private final static String aeNodeName = "ApplicationExtension";
private final static String gceNodeName = "GraphicControlExtension";
private final static String delayNodeName = "delayTime";
private final static String transparencyFlagNodeName = "transparentColorFlag";
private final static String transparencyIndexNodeName = "transparentColorIndex";
private int counter, loops;
private IIOMetadata iiom;
@ -86,10 +87,11 @@ public class AnimationGIF {
/**
* add an image to the animation
* @param image the image
* @param duration the frame time of the image in milliseconds
* @param delayMillis the frame time of the image in milliseconds
* @param transparencyColorIndex the index of the transparent color, -1 if not used
* @throws IOException
*/
public void addImage(RenderedImage image, int duration) throws IOException {
public void addImage(RenderedImage image, int delayMillis, int transparencyColorIndex) throws IOException {
if (this.counter == 0) {
iiom = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(image), iwp);
writer.prepareWriteSequence(writer.getDefaultStreamMetadata(iwp));
@ -97,14 +99,14 @@ public class AnimationGIF {
if (this.counter == 0 && loops >= 0) {
IIOMetadata imageMetadata2 = writer.getDefaultImageMetadata(ImageTypeSpecifier.createFromRenderedImage(image), iwp);
try {
setDelay(imageMetadata2, duration);
setMetadata(imageMetadata2, delayMillis, transparencyColorIndex);
setLoops(imageMetadata2, this.loops);
writer.writeToSequence(new IIOImage(image, null, imageMetadata2), iwp);
} catch (IIOInvalidTreeException e) {
throw new IOException(e.getMessage());
}
} else try {
setDelay(iiom, duration);
setMetadata(iiom, delayMillis, transparencyColorIndex);
writer.writeToSequence(new IIOImage(image, null, iiom), iwp);
} catch (IIOInvalidTreeException e) {
throw new IOException(e.getMessage());
@ -128,7 +130,7 @@ public class AnimationGIF {
return baos.toByteArray();
}
private static void setDelay(IIOMetadata metaData, int delay) throws IIOInvalidTreeException {
private static void setMetadata(IIOMetadata metaData, int delayMillis, int transparencyColorIndex) throws IIOInvalidTreeException {
Node tree = metaData.getAsTree(formatName);
NodeList nodeList = tree.getChildNodes();
Node gceNode = null;
@ -142,7 +144,21 @@ public class AnimationGIF {
delayNode = tree.getOwnerDocument().createAttribute(delayNodeName);
gceNode.appendChild(delayNode);
}
delayNode.setNodeValue(Integer.valueOf(delay / 10).toString());
delayNode.setNodeValue(Integer.valueOf(delayMillis / 10).toString());
if (transparencyColorIndex >= 0) {
Node transparencyFlagNode = gceNode.getAttributes().getNamedItem(transparencyFlagNodeName);
if (transparencyFlagNode == null) {
transparencyFlagNode = tree.getOwnerDocument().createAttribute(transparencyFlagNodeName);
gceNode.appendChild(transparencyFlagNode);
}
transparencyFlagNode.setNodeValue("TRUE");
Node transparencyIndexNode = gceNode.getAttributes().getNamedItem(transparencyIndexNodeName);
if (transparencyIndexNode == null) {
transparencyIndexNode = tree.getOwnerDocument().createAttribute(transparencyIndexNodeName);
gceNode.appendChild(transparencyIndexNode);
}
transparencyIndexNode.setNodeValue(Integer.valueOf(transparencyColorIndex).toString());
}
metaData.setFromTree(formatName, tree);
}
@ -186,7 +202,7 @@ public class AnimationGIF {
AnimationGIF generator = new AnimationGIF(0);
try {
for (int i = 0; i < framescount; i++) {
generator.addImage(generateTestImage(320, 160, r, i * 2 * Math.PI / framescount), 10);
generator.addImage(generateTestImage(320, 160, r, i * 2 * Math.PI / framescount), 10, 0);
}
FileOutputStream fos = new FileOutputStream(new File("/tmp/giftest.gif"));
fos.write(generator.get());

@ -39,6 +39,7 @@ import java.awt.image.ComponentColorModel;
import java.awt.image.ComponentSampleModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.IndexColorModel;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
import java.io.BufferedOutputStream;
@ -46,6 +47,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Set;
import java.util.TreeSet;
import java.util.zip.CRC32;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
@ -88,12 +91,8 @@ public class RasterPlotter {
private final long backgroundCol;
private DrawMode defaultMode;
private byte[] frame;
public RasterPlotter(final int width, final int height, final DrawMode drawMode, final String backgroundColor) {
this(width, height, drawMode, Long.parseLong(backgroundColor, 16));
}
public RasterPlotter(final int width, final int height, final DrawMode drawMode, final long backgroundColor) {
public RasterPlotter(final int width, final int height, final long backgroundColor) {
this.cc = new int[3];
this.width = width;
this.height = height;
@ -101,6 +100,14 @@ public class RasterPlotter {
this.defaultColR = 0xFF;
this.defaultColG = 0xFF;
this.defaultColB = 0xFF;
}
public RasterPlotter(final int width, final int height, final DrawMode drawMode, final String backgroundColor) {
this(width, height, drawMode, Long.parseLong(backgroundColor, 16));
}
public RasterPlotter(final int width, final int height, final DrawMode drawMode, final long backgroundColor) {
this(width, height, backgroundColor);
this.defaultMode = drawMode;
try {
// we need our own frame buffer to get a very, very fast transformation to png because we can omit the PixedGrabber, which is up to 800 times slower
@ -139,8 +146,11 @@ public class RasterPlotter {
if (this.frame == null) {
final Graphics2D gr = this.image.createGraphics();
gr.setBackground(new Color(bgR, bgG, bgB));
Color c = new Color(bgR, bgG, bgB);
gr.setBackground(c);
gr.clearRect(0, 0, this.width, this.height);
gr.setColor(c);
gr.fillRect(0, 0, this.width, this.height);
} else {
int p = 0;
for (int i = 0; i < width; i++) {
@ -799,6 +809,47 @@ public class RasterPlotter {
m.line(80, 0, 80, 300, 100);
}
public BufferedImage toIndexed() {
Set<Integer> colors = new TreeSet<Integer>();
int[] c = new int[3];
for (int y = this.getHeight() - 1; y >= 0; y--) {
for (int x = this.getWidth() - 1; x >= 0; x--) {
c = getPixel(x, y, c);
colors.add((c[0]<<16)|(c[1]<<8)|c[2]);
}
}
int[] cmap = new int[colors.size()];
int i = 0;
for (Integer cc: colors) {
cmap[i++] = cc.intValue();
if (i > 255) break;
}
int bitCount = 1;
while ((colors.size() - 1) >> bitCount != 0) bitCount *= 2;
IndexColorModel cm = new IndexColorModel(bitCount, colors.size(), cmap, 0, DataBuffer.TYPE_BYTE, null);
/*
byte [] data = null;
int bytesPerRow = this.getWidth()/8 + (this.getWidth()%8!=0?1:0);
data = new byte[this.getHeight() * bytesPerRow];
DataBuffer db = new DataBufferByte(data, data.length);
WritableRaster wr = Raster.createPackedRaster(db, this.getWidth(), this.getHeight(), 1, null);
BufferedImage dest = new BufferedImage(cm, wr, false, null);
*/
BufferedImage dest = new BufferedImage(this.getWidth(), this.getHeight(), cm.getPixelSize() < 8 ? BufferedImage.TYPE_BYTE_BINARY : BufferedImage.TYPE_BYTE_INDEXED, cm);
dest.createGraphics().drawImage(this.getImage(), 0, 0, null);
return dest;
}
public static BufferedImage convertToIndexed(BufferedImage src) {
BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);
dest.createGraphics().drawImage(src,0,0, null);
return dest;
}
public static ByteBuffer exportImage(final BufferedImage image, final String targetExt) {
// generate an byte array from the given image
final ByteBuffer baos = new ByteBuffer();

Loading…
Cancel
Save