From: Daryl V. H. <dva...@sf...> - 2005-07-23 00:46:17
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> It sounds like it is the JDK 5, on my Linux box (using a 200MHz processor and Java v1.4.2_08) it took about 7 seconds on a 1024x768 image.<br> <br> As an update on my main Windows computer, the shop didn't find anything wrong with it. <span class="moz-smiley-s2"><span> :-( </span></span><br> Must need to re-install Windows.<br> <br> This time, I'm going to install Windows <i>and</i> Linux on it (Keeping my slow one, of course).<br> <br> Daryl.<br> <br> Toby Donaldson wrote: <blockquote cite="mid...@sf..." type="cite">Hi, <br> <br> Can anyone help me to figure out why the code below is so slow? It converts and image to grayscale pixel by pixel, but when I've run it (on two different computers --- Windows and Mac OS X), it takes 20 or more seconds to process a medium sized image. I would have expected it take less than a second or so. <br> <br> The bit-twiddling code should be quite efficient, since such operations are (hopefully) converted to single assembly-language instructions. <br> <br> I've been using JDK 5.0 (aka 1.5), so maybe that's causing the problem? <br> <br> Toby <br> -- <br> Dr. Toby Donaldson <br> School of Computing Science <br> Simon Fraser University (Surrey) <br> <br> <br> <br> public static void dprint(String s) { <br> System.out.println(s + " " + (new Date())); <br> } <br> <br> public static void test4(String fname) { <br> try { <br> dprint("Creating buffered image:"); <br> BufferedImage img = ImageIO.read(new File(fname)); <br> dprint(".. done"); <br> final int width = img.getWidth(); <br> final int height = img.getHeight(); <br> dprint("Starting grayscale conversion:"); <br> for (int i = 0; i < width; i++) { <br> for (int j = 0; j < height; j++) { <br> int rgb = img.getRGB(i, j); <br> int b = (rgb & 0x000000FF); <br> int g = (rgb & 0x0000FF00) >> 8; <br> int r = (rgb & 0x00FF0000) >> 16; <br> <br> int lum = (int) ((r + g + b) / 3.0); <br> int alpha = rgb & 0xFF000000; <br> int red = lum << 16; <br> int green = lum << 8; <br> int blue = lum; <br> int newARGB = alpha | red | green | blue; <br> <br> img.setRGB(i, j, newARGB); <br> } <br> } <br> dprint("... done"); <br> } catch (IOException e) { <br> e.printStackTrace(); <br> } <br> } <br> <br> <br> <br> <br> <br> ------------------------------------------------------- <br> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies <br> from IBM. Find simple to follow Roadmaps, straightforward articles, <br> informative Webcasts and more! Get everything you need to get up to <br> speed, fast. <a class="moz-txt-link-freetext" href="http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click">http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click</a> <br> _______________________________________________ <br> csjava-developer mailing list <br> <a class="moz-txt-link-abbreviated" href="mailto:csj...@li...">csj...@li...</a> <br> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/csjava-developer">https://lists.sourceforge.net/lists/listinfo/csjava-developer</a> <br> <br> <br> </blockquote> <br> </body> </html> |