Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1272 → Rev 1274

/PhotoAlbum/trunk/src/ak/photoalbum/images/jiu/JiuResizer.java
12,7 → 12,6
import net.sourceforge.jiu.data.BilevelImage;
import net.sourceforge.jiu.data.Gray8Image;
import net.sourceforge.jiu.data.MemoryRGB24Image;
import net.sourceforge.jiu.data.Palette;
import net.sourceforge.jiu.data.Paletted8Image;
import net.sourceforge.jiu.data.PixelImage;
import net.sourceforge.jiu.data.RGB24Image;
36,11 → 35,10
FILTER_TYPE_MITCHELL 3.6 7.1
*/
 
protected Logger logger;
private static final Logger logger = Logger.getLogger(JiuResizer.class);
 
public JiuResizer()
{
this.logger = Logger.getLogger(this.getClass());
}
 
public BufferedImage resize(Image origin, int newWidth, int newHeight)
64,7 → 62,7
return convertToAwtImage(resample.getOutputImage(), DEFAULT_ALPHA);
}
catch(Exception ex) {
ex.printStackTrace();
logger.warn("Cannot resize image", ex);
 
throw new RuntimeException(ex.getMessage());
}
/PhotoAlbum/trunk/src/ak/photoalbum/images/Thumbnailer.java
8,7 → 8,6
import java.io.FileFilter;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
41,7 → 40,8
protected static final int CACHED_NOT_MODIFIED = 1;
protected static final int CACHED_WRITTEN = 2;
 
protected Logger logger;
private static final Logger logger = Logger.getLogger(Thumbnailer.class);
 
protected ImageResizer resizer;
protected int smallWidth = DEFAULT_SMALL_WIDTH;
protected int smallHeight = DEFAULT_SMALL_HEIGHT;
65,7 → 65,6
 
public Thumbnailer()
{
this.logger = Logger.getLogger(this.getClass());
}
 
public String getMime()
140,15 → 139,15
in = new FileInputStream(origin);
ii.setInput(in);
 
if(!ii.check()) {
if(ii.check()) {
res[0] = ii.getWidth();
res[1] = ii.getHeight();
}
else{
logger.warn("not supported format of " + origin.getCanonicalPath());
res[0] = 0;
res[1] = 0;
}
else{
res[0] = ii.getWidth();
res[1] = ii.getHeight();
}
}
finally {
if(in != null) in.close();
373,15 → 372,15
"unknown type of cached " + file.getCanonicalPath());
}
 
if(origin != null && cache != null) {
loadCacheInfo(file, origin, cache);
}
else {
if(origin == null || cache == null) {
file.delete();
 
if(logger.isDebugEnabled())
logger.debug("deleted (unknown origin)");
}
else {
loadCacheInfo(file, origin, cache);
}
}
 
protected void loadCacheInfo(File file, File origin, Map cache)
553,145 → 552,154
return true; // image written
}
 
synchronized protected BufferedImage createThumbnail(File imageFile,
protected BufferedImage createThumbnail(File imageFile,
int width, int height)
throws IOException
{
if(logger.isDebugEnabled())
logger.debug("create thumbnail " + imageFile.getCanonicalPath());
// FIXME make several instances parallel if we have sevelar processors
synchronized(this) {
if(logger.isDebugEnabled())
logger.debug("create thumbnail " + imageFile.getCanonicalPath());
 
Image image = loadImage(imageFile.getCanonicalPath());
// = ImageIO.read(imageFile);
int[] sizes;
Image image = loadImage(imageFile.getCanonicalPath());
// = ImageIO.read(imageFile);
int[] sizes;
 
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
 
return null;
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
width, height);
logger.debug("resize to " + sizes[0] + "x" + sizes[1]);
return null;
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
width, height);
logger.debug("resize to " + sizes[0] + "x" + sizes[1]);
 
return resizer.resize(image, sizes[0], sizes[1]);
return resizer.resize(image, sizes[0], sizes[1]);
}
}
}
 
synchronized protected BufferedImage createThumbnailNative(File dir, File cacheFile,
protected BufferedImage createThumbnailNative(File dir, File cacheFile,
File imageFile, int width, int height)
throws IOException
{
if(logger.isDebugEnabled())
logger.debug("create thumbnail2 " + imageFile.getCanonicalPath() + " to "
+ cacheFile.getCanonicalPath());
// FIXME make several instances parallel if we have sevelar processors
synchronized(this) {
if(logger.isDebugEnabled())
logger.debug("create thumbnail2 " + imageFile.getCanonicalPath() + " to "
+ cacheFile.getCanonicalPath());
 
dir.mkdirs();
dir.mkdirs();
 
// FIMXE: 1) make util path (and params?) configurable
Process process = Runtime.getRuntime().exec(new String[] {
"/usr/local/bin/convert",
"-size", width + "x" + height,
"-thumbnail", width + "x" + height,
imageFile.getCanonicalPath(),
cacheFile.getCanonicalPath()
});
// FIXME: 1) make util path (and params?) configurable
Process process = Runtime.getRuntime().exec(new String[] {
"/usr/local/bin/convert",
"-size", width + "x" + height,
"-thumbnail", width + "x" + height,
imageFile.getCanonicalPath(),
cacheFile.getCanonicalPath()
});
 
// FIXME make it finner
BufferedReader in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while((line = in.readLine()) != null) {
System.out.println("EXEC: " + line);
}
// FIXME make it finner
BufferedReader in = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String line;
while((line = in.readLine()) != null) {
logger.info("EXEC: " + line);
}
 
try {
int res = process.waitFor();
try {
int res = process.waitFor();
 
if(logger.isDebugEnabled())
logger.debug("process exited with result " + res);
}
catch(InterruptedException ex) {
logger.debug("process interrupted");
}
if(logger.isDebugEnabled())
logger.debug("process exited with result " + res);
}
catch(InterruptedException ex) {
logger.debug("process interrupted");
}
 
return null;
return null;
}
}
 
synchronized protected BufferedImage createDirThumbnail(File dir)
protected BufferedImage createDirThumbnail(File dir)
throws IOException
{
long timeStart = System.currentTimeMillis();
// FIXME make several instances parallel if we have sevelar processors
synchronized(this) {
long timeStart = System.currentTimeMillis();
 
if(logger.isDebugEnabled())
logger.debug("create dir thumbnail " + dir.getCanonicalPath());
if(logger.isDebugEnabled())
logger.debug("create dir thumbnail " + dir.getCanonicalPath());
 
Image template = loadImage(dirTemplate.getCanonicalPath());
BufferedImage dirThumbnail;
Graphics graphics;
int count;
File[] firstFiles;
Image template = loadImage(dirTemplate.getCanonicalPath());
BufferedImage dirThumbnail;
Graphics graphics;
int count;
File[] firstFiles;
 
if(template == null) { // not supported format
logger.warn("unsupported format for template or operation interrupted");
if(template == null) { // not supported format
logger.warn("unsupported format for template or operation interrupted");
 
return null;
}
return null;
}
 
dirThumbnail = createBufferedImage(template);
dirThumbnail = createBufferedImage(template);
 
graphics = dirThumbnail.getGraphics();
count = dirThumbnailPositions.length;
firstFiles = new File[count];
count = getFirstFiles(dir, count, firstFiles, 0);
graphics = dirThumbnail.getGraphics();
count = dirThumbnailPositions.length;
firstFiles = new File[count];
count = getFirstFiles(dir, count, firstFiles, 0);
 
for(int i = 0; i < count; i++) {
Image image;
BufferedImage thumbnail = null;
int[] sizes;
for(int i = 0; i < count; i++) {
Image image;
BufferedImage thumbnail = null;
int[] sizes;
 
if(nativeMode) {
File cacheFileDir = getCacheFileDir(firstFiles[i]);
File cacheFile = getCacheFile(cacheFileDir, firstFiles[i], DIR_PART_SUFFIX);
createThumbnailNative(cacheFileDir, cacheFile, firstFiles[i],
dirThumbnailPositions[i].getWidth(), dirThumbnailPositions[i].getHeight());
image = loadImage(cacheFile.getCanonicalPath());
thumbnail = createBufferedImage(image);
}
else {
image = loadImage(firstFiles[i].getCanonicalPath());
}
if(nativeMode) {
File cacheFileDir = getCacheFileDir(firstFiles[i]);
File cacheFile = getCacheFile(cacheFileDir, firstFiles[i], DIR_PART_SUFFIX);
createThumbnailNative(cacheFileDir, cacheFile, firstFiles[i],
dirThumbnailPositions[i].getWidth(), dirThumbnailPositions[i].getHeight());
image = loadImage(cacheFile.getCanonicalPath());
thumbnail = createBufferedImage(image);
}
else {
image = loadImage(firstFiles[i].getCanonicalPath());
}
 
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
if(image == null) { // not supported format
logger.warn("unsupported format for origin or operation interrupted");
 
return null;
return null;
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
dirThumbnailPositions[i].getWidth(),
dirThumbnailPositions[i].getHeight());
}
 
if(!nativeMode) {
thumbnail = resizer.resize(image, sizes[0], sizes[1]);
}
 
graphics.drawImage(thumbnail,
getXPosition(dirThumbnailPositions[i].getX(),
dirThumbnailPositions[i].getWidth(), sizes[0],
dirThumbnailPositions[i].getHorAlign()),
getYPosition(dirThumbnailPositions[i].getY(),
dirThumbnailPositions[i].getHeight(), sizes[1],
dirThumbnailPositions[i].getVertAlign()),
null);
}
else {
sizes = calcSizes(image.getWidth(null), image.getHeight(null),
dirThumbnailPositions[i].getWidth(),
dirThumbnailPositions[i].getHeight());
}
 
if(!nativeMode) {
thumbnail = resizer.resize(image, sizes[0], sizes[1]);
if(logger.isDebugEnabled()) {
logger.debug("dir thumbnail created in "
+ (System.currentTimeMillis() - timeStart) + " ms");
}
 
graphics.drawImage(thumbnail,
getXPosition(dirThumbnailPositions[i].getX(),
dirThumbnailPositions[i].getWidth(), sizes[0],
dirThumbnailPositions[i].getHorAlign()),
getYPosition(dirThumbnailPositions[i].getY(),
dirThumbnailPositions[i].getHeight(), sizes[1],
dirThumbnailPositions[i].getVertAlign()),
null);
return dirThumbnail;
}
 
if(logger.isDebugEnabled()) {
logger.debug("dir thumbnail created in "
+ (System.currentTimeMillis() - timeStart) + " ms");
}
 
return dirThumbnail;
}
 
protected Image loadImage(String fileName)
795,8 → 803,9
Arrays.sort(children, fileNameComparatorRev);
 
for(int i = 0; i < children.length && pos < count; i++) {
if(children[i].isDirectory())
; //pos = getFirstFiles(children[i], count, files, pos);
if(children[i].isDirectory()) {
//pos = getFirstFiles(children[i], count, files, pos);
}
else {
files[pos++] = children[i];
}