Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
23 May, 2013, 01:15:16 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Sprite Compression -  (Read 990 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
meishe91
Super Ninja
Members
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 02 May, 2013, 23:54:14
Date Registered: 05 March, 2010, 05:39:48
Posts: 2965


Topic starter
Total Post Ratings: +102

View Profile WWW
« on: 03 October, 2010, 02:31:21 »
+1

So recently MRide asked for sprites for his Imagination Quest game and I helped with a way of storing them/recalling them. This got me thinking about different ways of doing this. So I thought I would show you guys what I have come up with, but if you guys have any other ways please feel free to share your methods/routines.

Note: My routines are listed according to speed, fastest to slowest (decompression), and by chance size (compressed variable) too, largest to smallest. These also should be as optimized as they can be but I'm sure someone (*cough*nemo*cough* Tongue) could find something I missed. Also, last thing, all "Es" and "Ls" are the scientific notation E and list token L.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1→D
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,B
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
AnsE2-E2+A
If K=AnsE4
Then
Ans+.1→LP(D
Else
K+Ans→LP(D
End
D+1→D
End
End
End


1
2
3
4
5
6
7
8
9
10
For(A,1,dim(LP
LP(A
If fPart(Ans
Then
.01iPart(Ans
Pxl-On(E2fPart(Ans),iPart(Ans
Else
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
End
End


1
2
3
4
5
6
7
8
9
10
11
12
13
14
1→D
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,B
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
K+BE2-E2+A→LQ(D
D+1→D
End
End
End


1
2
3
4
For(A,1,dim(LQ
LQ(A
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
End


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"_Str3
{0,1→L1
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,B
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
{0,K+BE2-E2+A→L
LineReg(ax+b) Y1
Equ►String(Y1,Str4
sub(Str4,1,length(Str4)-3→Str4
If 7=length(Str4
Str3+"0→Str3
If 6=length(Str4
Str3+"00→Str3
Str3+Str4→Str3
End
End
End
sub(Ans,2,length(Ans)-1→Str3


1
2
3
4
5
For(A,1,length(Str3
expr(sub(Str3,A,8
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
A+7→A
End


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{0,1→L1
"_→Str1
For(A,Y,Y+H-1
For(B,X,X+W-1
If pxl-Test(A,b
Then
BE6+AE4→K
Repeat not(pxl-Test(A,B
B+1→B
End
BE2-E2+A→L
If K=AnsE4
Then
Str1+"+→Str1
Else
Str1+"-→Str1
End
{0,K(K≠LE4)+L→L2
LinReg(ax+b) Y1
Equ►String(Y1,Str2
sub(Str2,1,length(Str2)-3→Str2
If 2=length(Ans
Str1+"00→Str1
If max(length(Str2)={3,7
Str1+"0→Str1
Str1+Str2→Str1
End
End
End
sub(Ans,2,length(Ans)-1→Str1


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"expr(sub(Str1,A+1,Ans→u
For(A,1,length(Str1
If sub(Str1,A,1)="+
Then
4
.01u
Pxl-On(E2fPart(Ans),iPart(Ans
A+4→A
Else
8
u
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
A+8→A
End
End

Note:
The way to use the compression routines is to do Width→W:Height→H:Upper-Left X-Coordinate→X:Upper-Left Y-Coordinate→Y:prgmRoutine or something like that. The decompression routines can just be run (assuming you've compressed already).

Like I said, this is open for other people to show their own routines for compressing/decompressing and sprite. I hope someone finds these useful Smiley
« Last Edit: 03 October, 2010, 02:41:07 by meishe91 » Logged





For the 51st time, that is not my card! (Magic Joke)
nemo
LV9 Veteran (Next: 1337)
*********
Offline Offline

Last Login: 04 April, 2013, 01:12:57
Date Registered: 16 May, 2010, 03:55:30
Posts: 1198

Total Post Ratings: +83

View Profile
« Reply #1 on: 03 October, 2010, 02:38:44 »
0

AnsE2-E2+A

can't that just be Ans+A?

right... oops. for a second i thought that Ans would be less than 10.. don't know why. but hey. i'll find something else.. just give me a second.
i had to break away from my schoolwork *just* so i could find something to optimize  Grin oh, and your last String decompression code block is nested within the compression code block. these look neat, i'll check them out more thoroughly later
« Last Edit: 03 October, 2010, 02:40:28 by nemo » Logged


ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Yesterday at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #2 on: 03 October, 2010, 02:42:26 »
0

Looks neat.  I'm sure these are impressive.  Nice job! Grin
Logged

Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: 19 May, 2013, 19:18:47
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7813


Total Post Ratings: +706

View Profile WWW
« Reply #3 on: 03 October, 2010, 02:44:18 »
0

Nice! Lots of compression there Smiley
Logged




meishe91
Super Ninja
Members
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 02 May, 2013, 23:54:14
Date Registered: 05 March, 2010, 05:39:48
Posts: 2965


Topic starter
Total Post Ratings: +102

View Profile WWW
« Reply #4 on: 03 October, 2010, 02:46:17 »
0

Thanks guys Smiley That last decompression routine I think would only be good for smaller sprites. It can take a while to decompress unfortunately, but it is the smallest when compressed. (Darn you size at the risk of speed)
* Meishe91 shakes fist angrily in the air

AnsE2-E2+A

can't that just be Ans+A?

right... oops. for a second i thought that Ans would be less than 10.. don't know why. but hey. i'll find something else.. just give me a second.
i had to break away from my schoolwork *just* so i could find something to optimize  Grin oh, and your last String decompression code block is nested within the compression code block. these look neat, i'll check them out more thoroughly later

Ya, I was about to say it can't be just that. I'm sure you will Tongue

Also, thanks! I could not figure out why that "[/code][/code]" kept showing up at the bottom. I'm not sure how I missed that...I'm usually good about that.
« Last Edit: 03 October, 2010, 02:59:16 by meishe91 » Logged





For the 51st time, that is not my card! (Magic Joke)
nemo
LV9 Veteran (Next: 1337)
*********
Offline Offline

Last Login: 04 April, 2013, 01:12:57
Date Registered: 16 May, 2010, 03:55:30
Posts: 1198

Total Post Ratings: +83

View Profile
« Reply #5 on: 03 October, 2010, 02:46:37 »
0


1
2
Line(iPart(E2fPart(Ans/E8)),-iPart(E2fPart(Ans/E6)),iPart(E2fPart(Ans/E4)),-iPart(E2fPart(Ans/E2
to..

1
2
3
seq(iPart(E2fPart(Ans/10^(X))),X,2,8,2  //the token 10^(
Line(Ans(4),-Ans(3),Ans(2),-Ans(1
definitely a size optimization.. you'll probably take a hit on speed.
« Last Edit: 03 October, 2010, 02:52:19 by nemo » Logged


meishe91
Super Ninja
Members
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 02 May, 2013, 23:54:14
Date Registered: 05 March, 2010, 05:39:48
Posts: 2965


Topic starter
Total Post Ratings: +102

View Profile WWW
« Reply #6 on: 03 October, 2010, 02:56:42 »
0

Ah, ya. I didn't think about using seq( at all, mainly because I never really use it >.> But ya, that could work. Only thing though is with decompressions you might need to have them as fast as you can. But ya, that is an option Smiley Thanks.
Logged





For the 51st time, that is not my card! (Magic Joke)
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: Yesterday at 03:10:30
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5687


Total Post Ratings: +360

View Profile
« Reply #7 on: 03 October, 2010, 03:48:15 »
0

I try not to use seq( as it's extremely slow. Smiley  It's really useful when you don't need speed, though. Grin
Logged

DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 00:15:19
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50221


Total Post Ratings: +2615

View Profile WWW
« Reply #8 on: 03 October, 2010, 10:55:39 »
0

Nice stuff meishe!
Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
meishe91
Super Ninja
Members
LV11 Super Veteran (Next: 3000)
***********
Offline Offline

Gender: Male
Last Login: 02 May, 2013, 23:54:14
Date Registered: 05 March, 2010, 05:39:48
Posts: 2965


Topic starter
Total Post Ratings: +102

View Profile WWW
« Reply #9 on: 03 October, 2010, 11:23:41 »
0

Thank ya Smiley Took about a day to create the other three and debug them and all, then maybe an hour going through trying to optimize them as much as I could, which seemed to be good besides nemo's seq( tip (just had to find something, didn't you Wink). Then posted Smiley
Logged





For the 51st time, that is not my card! (Magic Joke)
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 00:15:19
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50221


Total Post Ratings: +2615

View Profile WWW
« Reply #10 on: 03 October, 2010, 19:02:07 »
0

Yeah Seq is good for compression sometimes but in some cases it is not very efficient for speed. In ROL3 I had a decompression routine for loading saved files, and it took about 3 seconds to decompress 70-80 lists elements. For Illusiat 13's 100 items, it takes 6 seconds. ROL3 decompressing is hard-coded while Illusiat 13 uses seq(). ROL decompressing program was about 600-700 bytes, if I remember, though.
« Last Edit: 03 October, 2010, 19:02:39 by DJ Omnimaga » Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.205 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.