Slow down compression in purebasic?

Everything else that doesn't fall into one of the other PB categories.
User avatar
oakvalley
User
User
Posts: 77
Joined: Sun Aug 08, 2004 6:34 pm
Location: Norway
Contact:

Re: Slow down compression in purebasic?

Post by oakvalley »

[quote="graph100"]Well, well,
[url]http://www.purebasic.fr/english/viewtop ... 12&t=38606[/url]

In this topic you can find a compression algoryhme, so maybe, you can use it, and slow this as you want (I think this is the simpliest way) :mrgreen:[/quote]

That is soooo over my head :-)
Regards Stone Oakvalley
Currently @ PB 5.70
Thorium
Addict
Addict
Posts: 1314
Joined: Sat Aug 15, 2009 6:59 pm

Re: Slow down compression in purebasic?

Post by Thorium »

oakvalley wrote: along with the need for point command which in the loop is hard to slow down at least with standard purebasic commands and in which end even using other smart ways of doing the point command in API way
There is no need for point and also no need for a even slower API point.
The fast way would be to use DrawingBuffer() to get the pointer to the image data and access it directly.
oakvalley wrote: still would to be run in a loop where I cannot slow down the loop beyond the minimum of 1 ms during each run. Is there time and space for requesting a nanosecond delay in the next version of Purebasic?
No, there is nothing like that. At least not on windows. The trick is to put a counter in and delay only every 10. or 100. or 1000. or so iteration.

But again we speak about 2% CPU load. It's acualy a lot of work for realy nothing what you try to do. That 2% does not mean another process does not have that 2%.
User avatar
graph100
Enthusiast
Enthusiast
Posts: 115
Joined: Tue Aug 10, 2010 3:17 pm

Re: Slow down compression in purebasic?

Post by graph100 »

Thorium wrote:There is no need for point and also no need for a even slower API point.
The fast way would be to use DrawingBuffer() to get the pointer to the image data and access it directly.
I totally agree with these 2 points :mrgreen: The fact is, I've broken my computer, so it's not usable and I had to code this quikly, without thinking through it all. I've made my point in using the point function and all the rest, it's ugly :x
Thorium wrote:The trick is to put a counter in and delay only every 10. or 100. or 1000. or so iteration.
I agree to this one too. In my code, I have just tryed to design some quick compression algorythme without even doing some research on the web... My point was : to create a code doing the job requested (compresse an image) to make the opportunity to slow this code down.

First you design the code to run the fastest way it's possible, and then you can slow it down. With this thinking, you can reduce the unecessary operation to a minimum.
Thorium wrote:But again we speak about 2% CPU load. It's acualy a lot of work for realy nothing what you try to do. That 2% does not mean another process does not have that 2%.
I agree that a use of 2% when the computer is doing nothing, only mean that window allow the code to run faster because IT can.
But, I also like this challenge, because it's an unusual way of thinking :D and it might be fun to code this :)
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed ;))
Thorium
Addict
Addict
Posts: 1314
Joined: Sat Aug 15, 2009 6:59 pm

Re: Slow down compression in purebasic?

Post by Thorium »

graph100 wrote:
Thorium wrote:But again we speak about 2% CPU load. It's acualy a lot of work for realy nothing what you try to do. That 2% does not mean another process does not have that 2%.
I agree that a use of 2% when the computer is doing nothing, only mean that window allow the code to run faster because IT can.
But, I also like this challenge, because it's an unusual way of thinking :D and it might be fun to code this :)
There is nothing wrong with a good challenge. :)
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: Slow down compression in purebasic?

Post by Foz »

This is also a useful exercise for myself, when using an 11 year old laptop where speed, cores, memory, weight and screen size were a thing of the future. :)

It makes multitasking a serious challenge!
User avatar
oakvalley
User
User
Posts: 77
Joined: Sun Aug 08, 2004 6:34 pm
Location: Norway
Contact:

Re: Slow down compression in purebasic?

Post by oakvalley »

[quote="Foz"]This is also a useful exercise for myself, when using an 11 year old laptop where speed, cores, memory, weight and screen size were a thing of the future. :)

It makes multitasking a serious challenge![/quote]

Yes, I agree! Working with old computers just up's the stakes to a reasonable challenge. Like my Billboard, I want it to work from Win95 to Win7. Basically, because I have some Win95/ME running from time to time in small computer nerdy projects using embedded pc's and such coolness.

I'm not sure when my Billboard software is done, but I'll let you know.
Regards Stone Oakvalley
Currently @ PB 5.70
User avatar
graph100
Enthusiast
Enthusiast
Posts: 115
Joined: Tue Aug 10, 2010 3:17 pm

Re: Slow down compression in purebasic?

Post by graph100 »

as somebody answered in an old topic, here a code of maestro to convert bmp file to 256 colors, the code is easy to use and you can change it to a 16colors convertion.
http://www.purebasic.fr/english/viewtop ... 12&t=35627

I dunno if it work on win95, because it use some api, but I think it might work pretty well. The code does not eat a lot of cpu time, (there's nothing on my cpu load viewer, with an old computer)

You should put an eye onto this :)
Here a piece of code that work with the code of maestro.

Code: Select all

#dist_max = 442

IncludeFile "_librairie_code_saveimageto8bitcolor_netmaestro.pbi"

Procedure DesktopSnapShot(img, coef.l = 6)
	Ecran_Largeur = GetSystemMetrics_(#SM_CXSCREEN)
	Ecran_Hauteur = GetSystemMetrics_(#SM_CYSCREEN)
	
	DC = GetDC_(0)
	
	CreateImage(img, Ecran_Largeur, Ecran_Hauteur)
	
	Dessin = StartDrawing(ImageOutput(img))
	
	If Dessin
		BitBlt_(Dessin, 0, 0, Ecran_Largeur, Ecran_Hauteur, DC, 0, 0, #SRCPAINT | $40000000)
		
		StopDrawing()
	EndIf
	
	ReleaseDC_(0, DC)
	
	ResizeImage(img, Ecran_Largeur / coef, Ecran_Hauteur / coef, #PB_Image_Raw)
	
	ProcedureReturn img
EndProcedure


If OpenWindow(0, 0, 0, 500, 500, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
	ImageGadget(0, 0, 0, WindowWidth(0), WindowHeight(0), 0)
	
EndIf

snap = 1

DesktopSnapShot(snap)


i = ImageTo8bit(ImageID(snap), 2) 


SetGadgetState(0, i)


Save8bitImage(i, "test.bmp") 


Repeat
	event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow

End
I use the #PB_Image_Raw in the resizeimage function, quicker than before :)
_________________________________________________
My Website : CeriseCode (Warning : perpetual changes & not completed ;))
Post Reply