Skip to content

Commit

Permalink
image scaling works, buggy when using full images so using thumbnails…
Browse files Browse the repository at this point in the history
… for now

modified the UI to be make space for the new slider and make the sliders more intuitive(i think)
  • Loading branch information
rubaiz committed Dec 6, 2007
1 parent 8387ee9 commit 41a2662
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 142 deletions.
1 change: 1 addition & 0 deletions src/image/FlickrImageFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public String getImageURL(String text) {
PhotoList pl = pi.search(sp, 1, 1);
if (!pl.isEmpty()) {
return ((Photo) pl.get(0)).getThumbnailUrl();
//return ((Photo) pl.get(0)).getUrl();
}
} catch (Exception e) {
System.out.println(e);
Expand Down
10 changes: 10 additions & 0 deletions src/powerreader/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ public class ConfigurationManager {
// Word focus level by default
static private int m_focusLevel = 3;
static private int m_detailLevel = 0;
static private int m_imageScale=3;

private TransformGroup m_mainTransformGroup = null;

private String fileName = null;

private JSlider m_zoomSlider = null;

static {
m_instance = new ConfigurationManager();

Expand Down Expand Up @@ -245,4 +247,12 @@ static public int getDetailLevel() {
static public void setDetailLevel(int level) {
m_detailLevel = level;
}

static public void setImageScale(int scale) {
m_imageScale = scale;
}

static int getImageScale() {
return m_imageScale;
}
}
77 changes: 54 additions & 23 deletions src/powerreader/Pick.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
//for image
import com.sun.j3d.utils.image.TextureLoader;
import image.ImageFetcher;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.MouseAdapter;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -133,29 +137,7 @@ else if(ConfigurationManager.getFocusLevel() == RawTextParser.LEVEL_DOCUMENT_ID)
Player.playOne();

// Get image
if(ConfigurationManager.showImages()) {
// clear out any existing images from the player
Player.removeImages();
ImageFetcher f = ConfigurationManager.getImageFetcher();
BufferedImage img = f.getImage(pickedText);
if (img != null) {
TextureLoader imageT = new TextureLoader(img,c3D);
Raster imageObj = new Raster(new Point3f(0, 0,1f),
Raster.RASTER_COLOR, 0, 0, imageT.getImage().getWidth(), imageT.getImage().getHeight(),
imageT.getImage(), null);
Shape3D shape = new Shape3D(imageObj);
imageObj.setCapability(Raster.ALLOW_IMAGE_WRITE);
BranchGroup node = new BranchGroup();

node.setCapability(BranchGroup.ALLOW_DETACH);

node.addChild(shape);
lastPicked = tObj.getTheTextTransformGroup();
lastPicked.addChild(node);

lastAttached =node;
}
}
displayImage(pickedText, tObj);
}
// dictionary meaning
if(mouseAction == ConfigurationManager.ACTION_DEFINE) {
Expand All @@ -171,6 +153,55 @@ else if(ConfigurationManager.getFocusLevel() == RawTextParser.LEVEL_DOCUMENT_ID)
ex.printStackTrace();
}
}

private void displayImage(final String pickedText, final TextObject3d tObj) {

if(ConfigurationManager.showImages()) {
// clear out any existing images from the player
Player.removeImages();
ImageFetcher f = ConfigurationManager.getImageFetcher();

BufferedImage bimg = f.getImage(pickedText);

if (bimg != null) {
//scale image
//Image img = bimg.getScaledInstance(ConfigurationManager.getImageScale()*100,-1,Image.SCALE_DEFAULT);

double scale = (ConfigurationManager.getImageScale()+1)*100/bimg.getWidth();
AffineTransform tx = new AffineTransform();
tx.scale(scale, scale);
BufferedImage img = bimg; // copying default image, in case scaling doesont work
try {
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
img = op.filter(bimg, null);
System.out.println("Scaled [w: " + bimg.getWidth() + " , h:"+ bimg.getHeight() +" ] to scale factor: " + ConfigurationManager.getImageScale());
} catch(Exception e) {
System.out.println("Error scaling [w: " + bimg.getWidth() + " , h:"+ bimg.getHeight() +" ] to scale factor: " + ConfigurationManager.getImageScale());
System.out.println(e);
}

//render image
TextureLoader imageT = new TextureLoader(img);
Raster imageObj = new Raster(new Point3f(0, -0.1f ,1.0f),
Raster.RASTER_COLOR, 0, 0, imageT.getImage().getWidth(), imageT.getImage().getHeight(),
imageT.getImage(), null);
Shape3D shape = new Shape3D(imageObj);
imageObj.setCapability(Raster.ALLOW_IMAGE_WRITE);
BranchGroup node = new BranchGroup();

node.setCapability(BranchGroup.ALLOW_DETACH);

node.addChild(shape);


lastPicked = tObj.getTheTextTransformGroup();
lastPicked.addChild(node);

//track the image so that it can be removed
lastAttached =node;
}
}
}

public void mouseWheelMoved(MouseWheelEvent e) {
ConfigurationManager.current_z += e.getWheelRotation()/-2.5f;
Expand Down
23 changes: 21 additions & 2 deletions src/powerreader/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

package powerreader;

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -179,8 +181,25 @@ public void run() {
Pick.removeImages();

ImageFetcher f = ConfigurationManager.getImageFetcher();
BufferedImage img = f.getImage(currentObj.getValue());
if (img != null) {
BufferedImage bimg = f.getImage(currentObj.getValue());
if (bimg != null) {
//scale image
//Image img = bimg.getScaledInstance(ConfigurationManager.getImageScale()*100,-1,Image.SCALE_DEFAULT);

double scale = (ConfigurationManager.getImageScale()+1)*100/bimg.getWidth();
AffineTransform tx = new AffineTransform();
tx.scale(scale, scale);
BufferedImage img = bimg; // copying default image, in case scaling doesont work
try {
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
img = op.filter(bimg, null);
System.out.println("Scaled [w: " + bimg.getWidth() + " , h:"+ bimg.getHeight() +" ] to scale factor: " + ConfigurationManager.getImageScale());
} catch(Exception e) {
System.out.println("Error scaling [w: " + bimg.getWidth() + " , h:"+ bimg.getHeight() +" ] to scale factor: " + ConfigurationManager.getImageScale());
System.out.println(e);
}

//render image
TextureLoader imageT = new TextureLoader(img);
Raster imageObj = new Raster(new Point3f(0, -0.5f,1f),
Raster.RASTER_COLOR, 0, 0, imageT.getImage().getWidth(), imageT.getImage().getHeight(),
Expand Down
Loading

0 comments on commit 41a2662

Please sign in to comment.