Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / How to speed up this pixelate routine?

Author
Message
roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 8th May 2010 05:43
As part of my first real project, I would like to create a pixelization routine as a transition from one level to the next. By pixelization, I mean I would like the image on the screen to get more and more blocky, then change the image to a blocky version of the image I want to transition to (same level of blockiness), then reverse the process to gradually sharpen the new image until it's the correct resolution. I don't know how else to accomplish this except using the POINT command to find the color of the current pixel and then change it based on a set of rules, but the end routine is very slow. Any ideas how to modify my algorithm?

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 8th May 2010 13:22 Edited at: 8th May 2010 13:23
Most obvious is that you have far too many reads of the bitmap, and far too many writes too.

Try this - it's approximately 3 time faster than your routine on my system:


I also tried using a memblock to avoid the reads to video memory, but it only really makes a difference at lower pixelation levels - at these higher levels, it's not really worth the effort.

roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 9th May 2010 09:15
Thanks, IanM! That method should definitely speed things up! I'll give it a try.
roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 10th May 2010 07:32
IanM, I found with your code I had to add one line and modify another to make it work:



The BOX command didn't seem to use the color information to color the box. I have another question, however. Obviously, the code for a step of 5 is half as fast as a step of 10, so I feel this method will always be a flawed way of creating a kind of animated transition between scenes. Am I going about this the wrong way? Should I use a movie file instead for a transition, or should there be a way to do this with code?
roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 10th May 2010 08:39
Wow. I just tried to make an AVI movie for the transition between images I wanted, and the resulting AVI even at 320x240 resolution encoded in DivX was 40.5MB for only a 1 second movie! But, the resulting effect works for what I need.

My question now is whether this is the correct solution or not? I have no idea if a 40MB movie for a simple scene transition is reasonable for a 1 second scene transition. Is this solution common for simple effects that are too cpu intensive to do with code?
roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 10th May 2010 20:34 Edited at: 10th May 2010 20:43
Ok, I'm an idiot. I made the AVI with images with various degrees of pixelization I did in the GIMP, but relied on the AVI building program to add the delay (and all the overhead). I only had 12 images total, so I just tried loading those images directly into DBPro and just copied each of those to the screen with a 100ms delay. That worked like a charm. Don't know why I didn't think of that to begin with. Thanks for your help, IanM!

Final code (image files are named "gog01.jpg" to "gog12.jpg"):
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 10th May 2010 22:38
If you were going to pre-render the images anyway, why did speed matter? Anyway, glad you solved your problem

roswell1329
14
Years of Service
User Offline
Joined: 12th Apr 2010
Location:
Posted: 10th May 2010 23:54
Oddly, it flat out didn't occur to me until this little exercise was complete.

I guess when you're playing with a hammer everything looks like a nail.

Login to post a reply

Server time is: 2024-11-24 15:38:45
Your offset time is: 2024-11-24 15:38:45