Sprite compression (Generation I): Difference between revisions

From Glitch City Wiki
Jump to navigation Jump to search
Content added Content deleted
mNo edit summary
mNo edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{incomplete|needs proper analysis. The official method may also have been in the source code}}
{{incomplete|needs proper analysis. The official method may also have been in the source code}}


'''Sprite compression''' is the means in Generation I for where pure graphics data is compressed into a Pokémon or Trainer sprite. The sprite is decompressed again using [[Sprite decompression (Generation I)|the sprite decompression routine]]. While the source compressor code is not in the ROMs; there are a few rules for a compressed sprite:
'''Sprite compression''' is the means in Generation I for where pure graphics data is compressed into a Pokémon or Trainer sprite. The sprite is decompressed again using [[Sprite decompression (Generation I)|the sprite decompression routine]] and allocates use of SRAM bank 0/"unbanked" SRAM. While the source compressor code is not in the ROMs; there are a few rules for a compressed sprite:


*The image to compress is usually a maximum of 56x56 pixels. Other Pokémon sprites can be 32x32, 40x40 or 48x48.
*The image to compress is usually a maximum of 56x56 pixels. Other Pokémon sprites can be 32x32, 40x40 or 48x48.
Line 7: Line 7:
*Backsprites are internally 32x32 pixels (0x44). Usually, these backsprites also have a little white space at the bottom (hidden by the battle menu).
*Backsprites are internally 32x32 pixels (0x44). Usually, these backsprites also have a little white space at the bottom (hidden by the battle menu).
*White space occupies smaller sprites to add up to 56x56.
*White space occupies smaller sprites to add up to 56x56.
*Unofficially, a .2bpp file can be converted into a compressed Pokémon sprite using the tool pkmncompress, and a .PNG into a compatible .2bpp file using rgbds. "Sprite import tools for RBY" can be downloaded within Evie's Google Sites backup [https://drive.google.com/drive/folders/1DAVPYay9sAuXwi4qXbDQfPU2sIDI_mXH?usp=sharing here] (based on the previous work of the GB Dev and Skeetendo communities).
*Unofficially, a .2bpp file can be converted into a compressed Pokémon sprite using tools (see external links) (based on the previous work of the GB Dev and Skeetendo communities).
*It is possible for the sprite to be flipped for a non-00 value in memory address 0xD0AA ([[Pokémon Red and Blue]]) or 0xD0A9 ([[Pokémon Yellow]]). The [[inverse sprites glitch]] corrupts these memory addresses, possibly leading to glitched sprites.


Unintended compressed sprites with dimensions of 0 are known for their memory overflows, such as Yellow [[MissingNo.]]'s sprite (treated as dimensions of 256, or (256/8)=32).
Unintended compressed sprites with dimensions of 0 are known for their memory overflows, such as Yellow [[MissingNo.]]'s sprite (treated as dimensions of 256, or (256/8)=32).
Line 14: Line 15:


<pre>
<pre>
00000000000000000100010206050506000000000000000019041D02CA15946B0000000000000000B7400EF131DEFD9200000000000000004000C020F010F010
5100FF001D00000001000102060105021000FE00D805080019041D02CA15946B0000A200ED100000B7400EF131DEF9920000000055000000400080201804040007000102060109000201010000000000730D37086B145CA3CDF753EF2FD7B1CE2FD0FD0211018C00C59EFB8E8E5FDF0E04000400000448807C5040303040C0200000000000000000000000000000000066DD87FFEF5DAD7EBB7CDC3FB17F3DFE570CEF00D500FF00E91741BE2CD7F30C7000A04020C0C080C000E08040C0E0C000000000000000000000000000000000F17F3DFADE7D3CFFEF7F26FF32FD3EFF22DDAFF06FF105FB3BD542BF25DF37C860C000E0A060C020806000E060E000E0
07040506020301010201010000000000F30DF708EB145CA3CDF753EF2FD7B1CE2FD0FD0211018C00C59EFB8E8E5FDF0E7090709070907090705050303040C020
0000000000000000000000000000000066DD87FFEF5DAD7EBB7CDC3FB17F3DFE570CEF00D500FF00E91741BE2CD7F30C7000A04020C0C080C000E08040C0E0C0
00000000000000000000000000000000F17F3DFADE7D3CFFEF7F26FF32FD3EFF22DDAFF06FF105FB3BD542BF25DF37C860C000E0A060C020806000E060E000E0
</pre>
</pre>


Line 20: Line 24:


<pre>
<pre>
00000000000000000100010206050506|000000000000000019041D02CA15946B|0000000000000000B7400EF131DEFD92|00000000000000004000C020F010F010
5100FF001D0000000100010206010502|1000FE00D805080019041D02CA15946B|0000A200ED100000B7400EF131DEF992|00000000550000004000802018040400
07000102060109000201010000000000|730D37086B145CA3CDF753EF2FD7B1CE|2FD0FD0211018C00C59EFB8E8E5FDF0E|04000400000448807C5040303040C020
07040506020301010201010000000000|F30DF708EB145CA3CDF753EF2FD7B1CE|2FD0FD0211018C00C59EFB8E8E5FDF0E|7090709070907090705050303040C020
00000000000000000000000000000000|66DD87FFEF5DAD7EBB7CDC3FB17F3DFE|570CEF00D500FF00E91741BE2CD7F30C|7000A04020C0C080C000E08040C0E0C0
00000000000000000000000000000000|66DD87FFEF5DAD7EBB7CDC3FB17F3DFE|570CEF00D500FF00E91741BE2CD7F30C|7000A04020C0C080C000E08040C0E0C0
00000000000000000000000000000000|F17F3DFADE7D3CFFEF7F26FF32FD3EFF|22DDAFF06FF105FB3BD542BF25DF37C8|60C000E0A060C020806000E060E000E0
00000000000000000000000000000000|F17F3DFADE7D3CFFEF7F26FF32FD3EFF|22DDAFF06FF105FB3BD542BF25DF37C8|60C000E0A060C020806000E060E000E0
Line 29: Line 33:


<pre>
<pre>
00000000000000000100010206050506070405060203010102010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019041D02CA15946BF30DF708EB145CA3CDF753EF2FD7B1CE66DD87FFEF5DAD7EBB7CDC3FB17F3DFEF17F3DFADE7D3CFFEF7F26FF32FD3EFF0000000000000000B7400EF131DEFD922FD0FD0211018C00C59EFB8E8E5FDF0E570CEF00D500FF00E91741BE2CD7F30C22DDAFF06FF105FB3BD542BF25DF37C800000000000000004000C020F010F0107090709070907090705050303040C0207000A04020C0C080C000E08040C0E0C060C000E0A060C020806000E060E000E0
5100FF001D00000001000102060105020700010206010900020101000000000000000000000000000000000000000000000000000000000000000000000000001000FE00D805080019041D02CA15946B730D37086B145CA3CDF753EF2FD7B1CE66DD87FFEF5DAD7EBB7CDC3FB17F3DFEF17F3DFADE7D3CFFEF7F26FF32FD3EFF0000A200ED100000B7400EF131DEF9922FD0FD0211018C00C59EFB8E8E5FDF0E570CEF00D500FF00E91741BE2CD7F30C22DDAFF06FF105FB3BD542BF25DF37C80000000055000000400080201804040004000400000448807C5040303040C0207000A04020C0C080C000E08040C0E0C060C000E0A060C020806000E060E000E0
</pre>
</pre>


Line 35: Line 39:


<pre>
<pre>
44BE1D54ECF6653AA4642AA541999A8B51707B0C63743EF0EE324CEFB0A21C36143C8CA6048970A8522212E0DC84329B0C8EE2A0A260A230E0A71CA5C341418942C1B3187DD0C5BB082EC62B555EB0A22A5D54BAAAA3D3DF4AD54849CF45533BD55DDD44AE550C1734173D1AA082D21048CC5642470C1C1321408261C12B07444168464A2861FB97A09861434F4D9095026B5AC182110AF959557863DB2150654AAAE820B487B2A09BC11E80
44BE9B70D04EA91B0AA9506666A2D45C1EC318D5043EF0EE324C70BEC28870D850F232206048970A852221250837210CA6C323B86182898288C3829C72970D0506250B06CC626D0C5BB082EC62B2FAC288A97552D210A3A62239AB9DEE9DFE42A0C72BA0FFFBA72791E8385B37FF777EE82BFFFFFE844C0A47DFFFF7742861A458C83FDFC3E17F77E0E8587EF84BEFFFFB7FE161F5E83AB3FFEBDF8E0FDE1C8DBFDFFFD8487FF8EAFBDFFD4D8A0C560BBEEC17FF628C957DD0C1505410A46AB6732770</pre>
</pre>


(Can be applied with [[arbitrary sprites]] or ROM hacking)
(Can be applied with [[arbitrary sprites]] or ROM hacking)


[[File:Sprite compression sample.png|thumb|left|160px|Sample image loaded using [[arbitrary sprites]] ([[GlitchDex/Y:230|9ゥ (E6)]] with default palette); exported drawing of Torchic from Game Boy Camera]]
[[File:Sprite compression sample.png|thumb|left|160px|Sample image loaded using [[arbitrary sprites]] ([[GlitchDex/Y:230|9ゥ (E6)]] with default palette); exported drawing of Torchic from Game Boy Camera]]
{{clr}}
==External links==
*[https://rgmechex.com/tech/gen1decompress.html Retro Game Mechanics Explained's tool to compress and decompress sprites online (supports PNGs)]
*"Sprite import tools for RBY" can be downloaded within Evie's Google Sites backup [https://drive.google.com/drive/folders/1DAVPYay9sAuXwi4qXbDQfPU2sIDI_mXH?usp=sharing here]
[[Category:Generation I mechanics]]
[[Category:Generation I mechanics]]

Latest revision as of 19:35, 9 April 2024

This article is incomplete. Please feel free to add any missing information about the subject. It is missing: needs proper analysis. The official method may also have been in the source code.

Sprite compression is the means in Generation I for where pure graphics data is compressed into a Pokémon or Trainer sprite. The sprite is decompressed again using the sprite decompression routine and allocates use of SRAM bank 0/"unbanked" SRAM. While the source compressor code is not in the ROMs; there are a few rules for a compressed sprite:

  • The image to compress is usually a maximum of 56x56 pixels. Other Pokémon sprites can be 32x32, 40x40 or 48x48.
  • Each nybble of the starting offset to the compressed sprite is dimensions/8. Front sprites can be of various sizes; a 56x56 sprite is represented as 0x77, a 48x48 one as 0x66, a 40x40 one as 0x55, a 32x32 as 0x44.
  • Backsprites are internally 32x32 pixels (0x44). Usually, these backsprites also have a little white space at the bottom (hidden by the battle menu).
  • White space occupies smaller sprites to add up to 56x56.
  • Unofficially, a .2bpp file can be converted into a compressed Pokémon sprite using tools (see external links) (based on the previous work of the GB Dev and Skeetendo communities).
  • It is possible for the sprite to be flipped for a non-00 value in memory address 0xD0AA (Pokémon Red and Blue) or 0xD0A9 (Pokémon Yellow). The inverse sprites glitch corrupts these memory addresses, possibly leading to glitched sprites.

Unintended compressed sprites with dimensions of 0 are known for their memory overflows, such as Yellow MissingNo.'s sprite (treated as dimensions of 256, or (256/8)=32).

If copying individual rows from a VRAM viewer, it may be necessary to rearrange the bytes; i.e. in this sample image for a 56x56 (0x44) sprite:

00000000000000000100010206050506000000000000000019041D02CA15946B0000000000000000B7400EF131DEFD9200000000000000004000C020F010F010
07040506020301010201010000000000F30DF708EB145CA3CDF753EF2FD7B1CE2FD0FD0211018C00C59EFB8E8E5FDF0E7090709070907090705050303040C020
0000000000000000000000000000000066DD87FFEF5DAD7EBB7CDC3FB17F3DFE570CEF00D500FF00E91741BE2CD7F30C7000A04020C0C080C000E08040C0E0C0
00000000000000000000000000000000F17F3DFADE7D3CFFEF7F26FF32FD3EFF22DDAFF06FF105FB3BD542BF25DF37C860C000E0A060C020806000E060E000E0

Split:

00000000000000000100010206050506|000000000000000019041D02CA15946B|0000000000000000B7400EF131DEFD92|00000000000000004000C020F010F010
07040506020301010201010000000000|F30DF708EB145CA3CDF753EF2FD7B1CE|2FD0FD0211018C00C59EFB8E8E5FDF0E|7090709070907090705050303040C020
00000000000000000000000000000000|66DD87FFEF5DAD7EBB7CDC3FB17F3DFE|570CEF00D500FF00E91741BE2CD7F30C|7000A04020C0C080C000E08040C0E0C0
00000000000000000000000000000000|F17F3DFADE7D3CFFEF7F26FF32FD3EFF|22DDAFF06FF105FB3BD542BF25DF37C8|60C000E0A060C020806000E060E000E0

Rearrange (left-most columns top-bottom; next set of columns to the right, repeat, and unsplit):

00000000000000000100010206050506070405060203010102010100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019041D02CA15946BF30DF708EB145CA3CDF753EF2FD7B1CE66DD87FFEF5DAD7EBB7CDC3FB17F3DFEF17F3DFADE7D3CFFEF7F26FF32FD3EFF0000000000000000B7400EF131DEFD922FD0FD0211018C00C59EFB8E8E5FDF0E570CEF00D500FF00E91741BE2CD7F30C22DDAFF06FF105FB3BD542BF25DF37C800000000000000004000C020F010F0107090709070907090705050303040C0207000A04020C0C080C000E08040C0E0C060C000E0A060C020806000E060E000E0

Processing through pkmncompress gives:

44BE1D54ECF6653AA4642AA541999A8B51707B0C63743EF0EE324CEFB0A21C36143C8CA6048970A8522212E0DC84329B0C8EE2A0A260A230E0A71CA5C341418942C1B3187DD0C5BB082EC62B555EB0A22A5D54BAAAA3D3DF4AD54849CF45533BD55DDD44AE550C1734173D1AA082D21048CC5642470C1C1321408261C12B07444168464A2861FB97A09861434F4D9095026B5AC182110AF959557863DB2150654AAAE820B487B2A09BC11E80

(Can be applied with arbitrary sprites or ROM hacking)

Sample image loaded using arbitrary sprites (9ゥ (E6) with default palette); exported drawing of Torchic from Game Boy Camera


External links