Screenshot smoothening

Page 1/3
| 2 | 3

By [D-Tail]

Ascended (8232)

[D-Tail]'s picture

22-06-2004, 21:49

Hi all!
I've got a little issue here: I often make screenshots from games running in NLMSX. Now, the problem is the dimensions of those images are 544*424. That's not a problem, on {emulated}screen 5 it will use pixel doubling. Now, for displaying those shots on a website, I made myself a PHP script. It's about 50 to 60 lines in size, and you'll see the results below (pictures are copyrighted by Umax Smile):

wwwhome.cs.utwente.nl/~herkafm/lw-banner.png
This is the original version.
wwwhome.cs.utwente.nl/~herkafm/lw-banner-a.png
This is the image after passing my script.

So far, so good: the script accepts any image format (except BMP, since PHP hasn't a real support for it) and creates the antialiased version on-the-fly. Now, we're finally at the point where I can state my problem:

if I use this script on a "really big" :P picture (say, 544*424), the execution time of the script is about one minute per picture on my Intel Pentium III! I think that could be done faster: even a Turbo R with NBASIC and vpeek/vpoke actions can do this faster ;).

For getting the pixel colors:
for each pixel, I use twelve times imagecolorat() on the original image to get an estimated (smoothing) new color for the new image.

For setting the new pixel:
for each pixel to set, I use imagesetpixel(), with the specified color obtained by imagecolorallocate().

Is there anyone around who can give me the solution to this speed issue (except of buying a new wintel brick, for which I don't have money left (hey, I gotta buy an OPL4 someday :P))?

Ta in advance ;)

Login or register to post comments

By [D-Tail]

Ascended (8232)

[D-Tail]'s picture

22-06-2004, 21:53

For law and order Tongue: in my previous post, I used two static images (instead of generating the anti-aliased on-the-fly), for:

  • I don't have GD support at the University (where I stored the images, my own web server isn't 24/7 online)
  • I try to prevent the loading times of MRC increasing (although MRC is one of the fastest sites around Smile)

By Arjan

Paladin (714)

Arjan's picture

22-06-2004, 21:55

imho, the anti-aliased picture is less clear than the original Tongue

I don't know jack about PHP, but can't you retrieve multiple pixels at once?

By Vincent van Dam

Hero (513)

Vincent van Dam's picture

22-06-2004, 22:01

I can recommend taking a look at www.imagemagick.org which is a very powerfull set of tools for working with images. It also has PHP support, but I don't have experience in using it in combination with PHP.

By Thom

Hero (583)

Thom's picture

22-06-2004, 22:06

Why don't you use BlueMSX with its fancy filters to get nice smooth pics?

By [D-Tail]

Ascended (8232)

[D-Tail]'s picture

22-06-2004, 22:10

Why don't you use BlueMSX with its fancy filters to get nice smooth pics?
Hurm.... I just like to use the anti aliasing more broadly. It's not just meant for smoothening screenies, but it can be anything (font smoothening, etc.). Furthermore, blueMSX doesn't run nicely when I've the filters enabled Sad

By [D-Tail]

Ascended (8232)

[D-Tail]'s picture

22-06-2004, 22:11

I don't know jack about PHP, but can't you retrieve multiple pixels at once?
Well, that's what I was trying to say: are there better ways (functions) to read pixels, or maybe indeed that imagemagick?

I'll give it a shot.

By [D-Tail]

Ascended (8232)

[D-Tail]'s picture

22-06-2004, 22:20

I can recommend taking a look at www.imagemagick.org which is a very powerfull set of tools for working with images. It also has PHP support, but I don't have experience in using it in combination with PHP.
Now I've seen it: I must admit it's quite the powerful toolset... And as well it should be! The package is about 28MB!! :(
The page claims it has native PHP support but I can't find it anywhere in the API... :(

[edit]Moreover, it seems like HELL to install it on a windows machine. Well, I'll give it a try, though I don't know how exactly. I've read some FAQs, and somebody said something about Imagemagick version 5.5.7 and PHP Imagick version 0.98. Have a decent read :) HERE :). But I wonder why one would need both packages...[/edit]

By Arjan

Paladin (714)

Arjan's picture

22-06-2004, 22:27

maybe you can read a few lines at once and store the pixeldata in arrays?
pixels are probably more often too, so you can reuse them instead of getting them from the image all the time Smile

but as Vincent says, you might be able to use imagemagick, and there are probably other tools which can do what you want.

By Vincent van Dam

Hero (513)

Vincent van Dam's picture

22-06-2004, 22:28

On the site the php module claims to have some examples in an examples directory.
If you have the basic toolset installed you can also run:

convert -antialias image-in.gif image-out.gif

If you don't get it to work with the libraries you can always do a system to the convert utility and built something around that.

By [D-Tail]

Ascended (8232)

[D-Tail]'s picture

22-06-2004, 22:42

Another result of the script (also copyrighted by Umax Wink):

wwwhome.cs.utwente.nl/~herkafm/lw-title.png
The original image.
wwwhome.cs.utwente.nl/~herkafm/lw-title-a.png
The anti aliased image. Thus far, this is my most precious one, since it cost PHP/GD about one-and-a-half minute to generate it :(...

maybe you can read a few lines at once and store the pixeldata in arrays?
pixels are probably more often too, so you can reuse them instead of getting them from the image all the time :)

What do you mean by reusing them, Arjan? By the way, I use .PNG pictures as input, so there isn't any pallette involved. Hence, any pixel can have any color, and the blending color has to be defined with imagecolorallocate(). And you would really like to have arrays with a length of about 512*3 bytes for one line?! (.PNG is truecolor, 24bpp...)

True, the currently used script uses about 1MB of memory for a 640*480*24bpp picture. But I don't think using arrays is a suggestion. AFAIK, GD doesn't have a proper built in anti alias function (which could make use of e.g. DirectX or openGL, depending on the system's configuration).

[still downloading imagemagick... :(]

[edit]It seems the IM PHP extension for windows has to be configured manually. Shouldn't be a problem, but I don't know where to start. The *nux script is yet available though... I'll see what options I have.[/edit]

Page 1/3
| 2 | 3