You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by je...@apache.org on 2012/02/08 12:28:10 UTC
svn commit: r1241870 - in
/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util:
content/fractal/ repository/
Author: jens
Date: Wed Feb 8 11:28:09 2012
New Revision: 1241870
URL: http://svn.apache.org/viewvc?rev=1241870&view=rev
Log:
Improve image quality
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalCalculator.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalCalculator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalCalculator.java?rev=1241870&r1=1241869&r2=1241870&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalCalculator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalCalculator.java Wed Feb 8 11:28:09 2012
@@ -26,6 +26,7 @@ import java.awt.image.BufferedImage;
final class FractalCalculator {
private int[] colorMap;
+ protected int[][] noIterations;
private double delta;
private double iRangeMax;
private double iRangeMin;
@@ -61,34 +62,44 @@ final class FractalCalculator {
}
}
- public BufferedImage calcFractal() {
+ public int[][] calcFractal() {
+ noIterations = new int[ imageWidth ][ imageHeight ];
+
+ // For each pixel...
+ for (int x = 0; x < imageWidth; x++) {
+ for (int y = 0; y < imageHeight; y++) {
+ double zR = rRangeMin + x * delta;
+ double zI = iRangeMin + (imageHeight - y) * delta;
+
+ // Is the point inside the set?
+ if (useJulia)
+ noIterations[x][y] = testPointJuliaSet(zR, zI, maxIterations);
+ else
+ noIterations[x][y] = testPointMandelbrot(zR, zI, maxIterations);
+ }
+ }
+ return noIterations;
+ }
+
+ public BufferedImage mapItersToColors(int[][] iterations) {
// Assign a color to every pixel ( x , y ) in the Image, corresponding
// to
// one point, z, in the imaginary plane ( zr, zi ).
- BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR);
+ BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_3BYTE_BGR );
// For each pixel...
for (int x = 0; x < imageWidth; x++) {
for (int y = 0; y < imageHeight; y++) {
- int color = getColor(x, y);
+ int color = getColor(iterations[x][y]);
image.setRGB(x, y, color);
}
}
return image;
}
- private int getColor(int x, int y) {
+ protected int getColor(int numIterations) {
int c = Color.black.getRGB();
- double zR = rRangeMin + x * delta;
- double zI = iRangeMin + (imageHeight - y) * delta;
-
- // Is the point inside the set?
- int numIterations;
- if (useJulia)
- numIterations = testPointJuliaSet(zR, zI, maxIterations);
- else
- numIterations = testPointMandelbrot(zR, zI, maxIterations);
if (numIterations != 0) {
// The point is outside the set. It gets a color based on the number
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.java?rev=1241870&r1=1241869&r2=1241870&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/content/fractal/FractalGenerator.java Wed Feb 8 11:28:09 2012
@@ -101,7 +101,7 @@ public class FractalGenerator {
Random ran = new Random();
color = colorSchemes[ran.nextInt(colorSchemes.length)];
- parts = ran.nextInt(30)+3;
+ parts = ran.nextInt(13)+3;
LOG.debug("Parts: " + parts);
maxIterations = DEFAULT_MAX_ITERATIONS;
LOG.debug("Original rect " + ": (" + rect.getRMin() + "r," + rect.getRMax() +
@@ -128,6 +128,7 @@ public class FractalGenerator {
double i1New = rect.getIMax() - (rect.getHeight() * newRowTile / parts);
double i2New = rect.getIMax() - (rect.getHeight() * (newRowTile+1) / parts);
rect.set(r1New, r2New, i1New, i2New);
+ randomizeRect(rect);
LOG.debug("Done generating fractals.");
return bos;
@@ -168,9 +169,9 @@ public class FractalGenerator {
calculator = new FractalCalculator(rect, maxIterations, imageWidth, imageHeight, getCurrentColorMap(),
juliaPoint);
- BufferedImage image = calculator.calcFractal();
-
- findNewRect(image);
+ int[][] iterations = calculator.calcFractal();
+ BufferedImage image = calculator.mapItersToColors(iterations);
+ findNewRect(image, iterations);
// fast method to write to a file with default options
// ImageIO.write((BufferedImage)(image), "jpg", new File("fractal-" + counter++ + ".jpg"));
@@ -436,18 +437,18 @@ public class FractalGenerator {
}
- private void findNewRect(BufferedImage image) {
+ private void findNewRect(BufferedImage image, int[][] iterations) {
int newWidth = image.getWidth() / parts;
int newHeight = image.getHeight() / parts;
int i=0, j=0;
int noTiles = (image.getWidth() / newWidth) * (image.getHeight() / newHeight); // equals parts but be aware of rounding errors!;
- double[][] stdDev = new double [noTiles] [3];
+ double[] stdDev = new double [noTiles];
for (int y = 0; y+newHeight <= image.getHeight(); y+=newHeight) {
for (int x = 0; x+newWidth <= image.getWidth(); x+=newWidth) {
Rectangle subRect = new Rectangle(x, y, newWidth, newHeight);
- calcStdDev(image, subRect, stdDev[i*parts+j]);
+ stdDev[i*parts+j] = calcStdDev(iterations, subRect);
++j;
}
++i;
@@ -458,50 +459,32 @@ public class FractalGenerator {
double max = 0;
int index = 0;
for (i=0; i<noTiles; i++) {
- double avg = (stdDev[i][0] + stdDev[i][1] +stdDev[i][2]) / 3;
- if (avg > max) {
+ if (stdDev[i] > max) {
index = i;
- max = avg;
+ max = stdDev[i];
}
}
newRowTile = index / parts;
newColTile = index % parts;
}
- private void calcStdDev(BufferedImage image, Rectangle rect, double[] stdDev) {
+ private double calcStdDev(int[][] iterations, Rectangle rect) {
- int sumR = 0, sumG = 0, sumB = 0;
- long sumSR = 0, sumSG = 0, sumSB = 0;
+ int sum=0;
+ long sumSquare=0;
for (int x = rect.x; x < rect.x+rect.width; x+=1) {
for (int y = rect.y; y < rect.y+rect.height; y+=1) {
- int pixel = image.getRGB(x, y);
- byte r, g, b, alpha;
-
- alpha = (byte) (pixel >>> 24);
- r = (byte) (pixel >>> 16);
- g = (byte) (pixel >>> 8);
- b = (byte) pixel;
- int red = r & 0xFF;
- int green = g & 0xFF;
- int blue = b & 0xFF;
- sumR +=red;
- sumG += green;
- sumB += blue;
- sumSR +=red*red;
- sumSG += green*green;
- sumSB += blue*blue;
+ int iters = iterations[x][y];
+ sum +=iters;
+ sumSquare +=iters*iters;
}
}
int count = rect.width * rect.height;
double mean = 0.0;
- mean = sumR / count;
- stdDev[0] = Math.sqrt(sumSR/count - (mean * mean));
- mean = sumG / count;
- stdDev[1] = Math.sqrt(Math.sqrt(sumSG/count - (mean * mean)));
- mean = sumB / count;
- stdDev[2] = Math.sqrt(Math.sqrt(sumSB/count - (mean * mean)));
+ mean = sum / count;
+ return Math.sqrt(sumSquare/count - (mean * mean));
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java?rev=1241870&r1=1241869&r2=1241870&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java Wed Feb 8 11:28:09 2012
@@ -19,6 +19,8 @@
package org.apache.chemistry.opencmis.util.repository;
import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -33,6 +35,7 @@ import joptsimple.OptionSpec;
import org.apache.chemistry.opencmis.client.bindings.CmisBindingFactory;
import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
@@ -64,6 +67,7 @@ public class ObjGenApp {
private static final String ROOTFOLDER = "RootFolder";
private static final String THREADS = "Threads";
private static final String CONTENT_KIND = "ContentKind";
+ private static final String FILE_NAME_PATTERN = "FileName";
// private static final String FILE = "File";
private static final String BINDING_ATOM = "AtomPub";
@@ -89,6 +93,7 @@ public class ObjGenApp {
OptionSpec<Integer> fThreads;
OptionSpec<String> fFileName;
OptionSpec<String> fContentKindStr;
+ OptionSpec<String> fFileNamePattern;
public static void main(String[] args) {
@@ -135,6 +140,8 @@ public class ObjGenApp {
// fFileName = parser.accepts(FILE).withRequiredArg().ofType(String.class).describedAs("Input File");
fContentKindStr = parser.accepts(CONTENT_KIND).withOptionalArg().ofType(String.class).defaultsTo("lorem/text")
.describedAs("kind of content: static/text, lorem/text, lorem/html, fractal/jpeg");
+ fFileNamePattern = parser.accepts(FILE_NAME_PATTERN).withOptionalArg().ofType(String.class).defaultsTo("ContentData-%03d.bin")
+ .describedAs("file name pattern to be used with CreateFiles action");
OptionSet options = parser.parse(args);
@@ -172,7 +179,10 @@ public class ObjGenApp {
usage(parser);
}
- if (options.valueOf(fCmd).equals("FillRepository")) {
+ if (null == options.valueOf(fCmd)) {
+ System.out.println("No command given.");
+ usage(parser);
+ } else if (options.valueOf(fCmd).equals("FillRepository")) {
fillRepository(options);
} else if (options.valueOf(fCmd).equals("CreateDocument")) {
createSingleDocument(options);
@@ -182,6 +192,8 @@ public class ObjGenApp {
repositoryInfo(options);
// } else if (options.valueOf(fCmd).equals("CreateTypes")) {
// createTypes(options);
+ } else if (options.valueOf(fCmd).equals("CreateFiles")) {
+ createFiles(options);
} else if (options.valueOf(fCmd).equals("GetUrl")) {
getUrl(getConfiguredUrl());
} else {
@@ -212,7 +224,7 @@ public class ObjGenApp {
System.out.println("Usage:");
parser.printHelpOn(System.out);
System.out.println();
- System.out.println("Command is one of [CreateDocument, CreateFolder, FillRepository, RepositoryInfo]");
+ System.out.println("Command is one of [CreateDocument, CreateFolder, FillRepository, RepositoryInfo, CreateFiles]");
System.out.println("JVM system properties: " + PROP_ATOMPUB_URL + ", " + PROP_WS_URL);
System.out.println();
System.out.println("Example: ");
@@ -443,6 +455,72 @@ public class ObjGenApp {
callRepoInfo(options.valueOf(fRepoId), options.valueOf(fCount));
}
+ private void createFiles(OptionSet options) {
+ ContentStream contentStream = null;
+ String fileNamePattern = options.valueOf(fFileNamePattern);
+ int count = options.valueOf(fCount);
+ int contentSize = options.valueOf(fContentSize);
+
+ System.out.println("Creating local files with content: ");
+ System.out.println("Kind: " + options.valueOf(fDocsPerFolder));
+ System.out.println("Number of files: " + count);
+ System.out.println("File name pattern: " + fileNamePattern);
+ System.out.println("Kind of content: " + options.valueOf(fContentKindStr));
+ System.out.println("Size of content (text only): " + contentSize);
+
+ ObjectGenerator objGen = new ObjectGenerator(null, null, null, null, null, fContentKind);
+ objGen.setContentSizeInKB(contentSize);
+
+ InputStream is = null;
+ FileOutputStream os = null;
+
+ try {
+ for (int i=0; i<count; i++) {
+ String fileName = String.format(fileNamePattern, i);
+ System.out.println("Generating file: " + fileName);
+ if (contentSize > 0) {
+ switch (fContentKind) {
+ case StaticText:
+ contentStream = objGen.createContentStaticText();
+ break;
+ case LoremIpsumText:
+ contentStream = objGen.createContentLoremIpsumText();
+ break;
+ case LoremIpsumHtml:
+ contentStream = objGen.createContentLoremIpsumHtml();
+ break;
+ case ImageFractalJpeg:
+ contentStream = objGen.createContentFractalimageJpeg();
+ break;
+ }
+ }
+
+ // write to a file:
+ is = contentStream.getStream();
+ os = new FileOutputStream (fileName);
+ byte[] b = new byte[64 * 1024];
+ int read;
+ while ((read = is.read(b)) != -1)
+ os.write(b, 0, read);
+ is.close();
+ is = null;
+ os.close();
+ os = null;
+ }
+ } catch (Exception e) {
+ System.err.println("Error generating file: " + e);
+ e.printStackTrace();
+ } finally {
+ try {
+ if (null != is)
+ is.close();
+ if (null != os)
+ os.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+
private CmisBinding getBinding() {
if (binding == null) {
if (fUsingAtom) {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java?rev=1241870&r1=1241869&r2=1241870&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjectGenerator.java Wed Feb 8 11:28:09 2012
@@ -147,7 +147,7 @@ public class ObjectGenerator {
/**
* generator for images
*/
- private FractalGenerator fractalGenerator;
+ private FractalGenerator fractalGenerator = null;
public ObjectGenerator(BindingsObjectFactory factory, NavigationService navSvc, ObjectService objSvc,
RepositoryService repSvc, String repositoryId, CONTENT_KIND contentKind) {
@@ -171,7 +171,6 @@ public class ObjectGenerator {
fTopLevelDocsCreated = new ArrayList<String>();
fTopLevelFoldersCreated = new ArrayList<String>();
fContentKind = contentKind;
- fractalGenerator = new FractalGenerator();
}
public void setNumberOfDocumentsToCreatePerFolder(int noDocumentsToCreate) {
@@ -511,7 +510,7 @@ public class ObjectGenerator {
}
}
- private ContentStream createContentLoremIpsumHtml() {
+ public ContentStream createContentLoremIpsumHtml() {
ContentStreamImpl content = new ContentStreamImpl();
content.setFileName("data.html");
content.setMimeType("text/html");
@@ -523,7 +522,7 @@ public class ObjectGenerator {
return content;
}
- private ContentStream createContentLoremIpsumText() {
+ public ContentStream createContentLoremIpsumText() {
ContentStreamImpl content = new ContentStreamImpl();
content.setFileName("data.txt");
content.setMimeType("text/plain");
@@ -535,7 +534,7 @@ public class ObjectGenerator {
return content;
}
- private ContentStream createContentStaticText() {
+ public ContentStream createContentStaticText() {
ContentStreamImpl content = new ContentStreamImpl();
content.setFileName("data.txt");
content.setMimeType("text/plain");
@@ -558,7 +557,10 @@ public class ObjectGenerator {
return content;
}
- private ContentStream createContentFractalimageJpeg() {
+ public ContentStream createContentFractalimageJpeg() {
+ if (null == fractalGenerator)
+ fractalGenerator = new FractalGenerator();
+
ContentStreamImpl content = null;
try {