Tag:
070324_tilesaver.gif

High-resolution images from Processing using tiling (1.6% / 20%)

A while back I posted about rendering very high-resolution images from Processing using a tiling technique. I had implemented a working version of a solution first described by "surelyyoujest", but didn’t have time to post a clean version of the code. (I did however post ImageStitcher.pde, which is code for stitching these tiled images back together.) But after a long delay, here is finally the more useful bit of code.

The code works by panning the camera over the original viewport area, subdividing the image into tiles. This way, OpenGL’s limitations on maximum resolution can be circumvented. As long as enough memory is allocated, the images created can be very big indeed. The images shown above are from a 15360 x 15360 pixel image, shown at 1.6% and 20% respectively. With 1.5 GB assigned to Java I have so far successfully saved 20k x 20k images. That’s large enough to print 2×2 meter prints at 260 DPI.

What follows is the aTileSaver class and a simple demo application. I will post a more complex example soon.

Update: I’ve changed a few minor details in the code. Make note of the version number if you have download it already. This code is likely to change..

Source code - aTileSaver.pde

Read the rest of this entry »

25 Comments »

No, I’m not talking about Christmas ornaments. I just came up with a quick hack to turn off the window frame from inside Processing. See this thread on the Processing forums to know why this is useful.

When running in the IDE the sketch runs as an applet, so it can’t use the “–present” command line switches available to applications because init() is called instead of main(). My hack simply overrides the default init(), sets the frame to be undecorated and then calls the regular PApplet.init().

Update: Setting the location of the window needs to happen in setup(), not init().

import processing.opengl.*;

void setup(){
  size(400,400,OPENGL);
  background(0);
  frame.setLocation(0,0); // needs to be in setup(), not init()
}

void draw(){
  stroke(255);
  line(0,0,200,200);
}  

public void init() {
  frame.setUndecorated(true); // works.

  // call PApplet.init() to take care of business
  super.init();
}

4 Comments »

I know I mentioned putting together a image tiling Processing library, but so far I haven’t had time. To start at the wrong end, here’s the image stitching code for putting together the tiles once they’ve been generated. Hopefully that will be of use to some people.

Note that you might run into memory problems if you use huge tiles. Processing 0119 has a new “Set maximum memory” preference that easily takes care of this problem (see File > Preferences).

See the Processing forums for some sample code creating tiles, posted by user “surelyyoujest”.

Update: I’ve put together a proper class for this tiling technique. Have a look at aTileSaver.pde.

Source code - ImageStitcher.pde

Read the rest of this entry »

1 Comment »

This is a simple variant to the built-in saveStrings() method in Processing. It allows you to write strings to a GZIP compressed file instead of a plain text file. Very useful when writing text-based data files that add up to a few megabytes.

Source code - saveStringsGZIP.pde
// saveStringsGZIP.pde
// Marius Watz - http://workshop.evolutionzone.com
//
// Code for saving an array of strings to a GZIP compressed file.
// Based on Processing's built-in saveStrings() method.

// Java classes needed for file I/O.
import java.io.*;
import java.util.zip.GZIPOutputStream;

void setup() {
  String [] s=new String[2000];
  for(int i=0; i< s.length; i++) s[i]=nf(i,50);
  saveStringsGZIP("test.txt",s);
}

// Based on code from processing.core.PApplet, by the Processing team.
public void saveStringsGZIP(String filename, String strings[]) {
  try {
    String location = savePath(filename+".gz");
    GZIPOutputStream fos =
      new GZIPOutputStream(new FileOutputStream(location));
    PrintWriter writer =
      new PrintWriter(new OutputStreamWriter(fos));
    for (int i = 0; i < strings.length; i++)
      if(strings[i]!=null) writer.println(strings[i]);
    writer.flush();
    fos.close();
  } catch (IOException e) {
    e.printStackTrace();
    throw new RuntimeException("saveStringsGZIP() failed: "
      + e.getMessage());
  }
}

No Comments »

Demo of high-res tiled image output: KugelTiled04 res demo

Update: I’ve finally found the time to write a proper class for this tiling technique. Have a look at aTileSaver.pde.

I’ve been able to generate huge raster files for print use from Processing, using the tiling trick first outlined on the Processing forums by user “surelyyoujest”. Using his code as a base, I got it working with OpenGL and proceeded to output some gigantic files. A quick hack using PImage allowed me to stitch the resulting tiles together in one huge image, which was then saved as a Targa file.

See the picture above for a demo. When viewed at its original size, the left half of this image shows the full picture at 10% (original res 10240 x 7680 px). The right half shows the whited-out section of the left image at 100%. The resolution is staggering.

This should clear the way for doing huge prints, without not having to worry about PDFs not showing 3D correctly (see previous post). I will post sample code for tile-based rendering and stitching as a library when I have time.

6 Comments »

I found a simple tutorial over on Java Practices that demonstrated the use of the system clipboard for transferring text between applications using copy / paste. I’m using it to copy color values from an improved version of SimpleColorPicker.pde.

The CopyPaste class described in the code can be dropped into any Processing sketch to provide access to the clipboard.

Source code - CopyPasteTool.pde

Read the rest of this entry »

4 Comments »

Here is the code for a simple Processing GUI utility for editing color palettes. It generates gradients given a start and end color. It will print palettes as hex strings and RGB triplets, change the “prefix” and “suffix” variables to turn the output into readymade code.

I whipped this up to make it easy to make decent color combos for a current project I'm working on. It could do with a few more features, like a 2D RGB color field to choose from and the ability to save and maybe even load files. It feeds into a color library I use, maybe I’ll make that available at some point to make it a bit more useful.

Source code - SimpleColorPicker.pde

Read the rest of this entry »

3 Comments »

This little code piece implements a Timer class which takes a duration and countdown, and returns a value in the range [0..1] depending on how much of the specified time has elapsed. The variable “fract” gives the state of the timer, with a value of 0 representing a state in which the timer has not started (i.e. still in countdown interval). A value of 1 means that the countdown is complete and the time specified as duration has elapsed. A fractional value represents how far into the time interval the program has reached.

This is useful for animation in absolute time, regardless of frame rate. The timer’s update() function must be called before using the value contained in the “fract” variable.

Source code - Timer.pde

Read the rest of this entry »

No Comments »

For many applications like saving images, PDFs, logs or temporary files one typically wants to use a set filename structure. One such typical structure is “Sketch-####.png”, where # denotes a single number. It is often convenient to not have to keep track of the numerical component, but just assuming that it will update automatically.

This hack describes a simple function which can be used to return the next valid filename in a sequence, so that you won’t have to worry about erasing files. It is very useful if you have a “snapshot” function for saving images of your work-in-progress.

Source code - getIncrementalFilename.pde

Read the rest of this entry »

No Comments »

Complex 3D output using PDF in Processing

Complex 3D output using PDF in Processing.

Sample code for PDF output of complex geometries from Processing, with a 3D shape using lines and polygons being written correctly to PDF. Uses beginRaw() / endRaw() and should probably be used with revision 0115 or later due to recent bug fixes.

Source code - pdf_complex.pde

Read the rest of this entry »

7 Comments »