Changes

4,895 bytes added ,  13:18, 21 August 2009
no edit summary
Line 1: Line 1:  +
Flipnotes animation files are normally stored on the SD card in the following folder:
 +
 +
/private/ds/app/4B475556/001 - European location
 +
 +
You can save your images in a user folder as long as it's on the same level as the 001 folder.  Clicking on the Choose Folder icon on the top of the View Flipnote / SD Card option gives you a list of normal folders, and you can swap to user folders by selecting the normal button again.  This could possibly be to overcome a limitation in one of the files (possibly the dirmemo2.lst file).
 +
 +
==File Header==
 
{| class="wikitable"
 
{| class="wikitable"
 
|- style="background-color: #ddd;"
 
|- style="background-color: #ddd;"
Line 76: Line 83:  
| 1536
 
| 1536
 
| Preview Bitmap (4 bits/pixel).
 
| Preview Bitmap (4 bits/pixel).
|-
  −
|0x06A0
  −
| 8 + ( 4 * Number of frames)
  −
| Animation Sequence Header
   
|}
 
|}
   Line 188: Line 191:     
==Animation Data Section==
 
==Animation Data Section==
 +
The animation section starts at offset 0x06A0, with a header section.
 +
 +
===Animation Sequence Header===
 +
{| class="wikitable"
 +
|- style="background-color: #ddd;"
 +
! Start
 +
! Length
 +
! Description
 +
|-
 +
| 0000
 +
| 4
 +
| Size of the offset table
 +
|-
 +
| 0004
 +
| 4
 +
| Unknown
 +
|-
 +
| 0008
 +
| 4 * number of frames
 +
| A list of offsets to the frames in the order to play them.
 +
|}
 +
 +
The offsets are all relative to the end of the offset list, and the frames are not stored in any specific format in the file, so you have to read this table for the next offset as I've seen the list point to a frame at 00023572 and the next frame was at 00000000.
 +
 +
===Animation Frame===
 +
{| class="wikitable"
 +
|- style="background-color: #ddd;"
 +
! Start
 +
! Length
 +
! Description
 +
|-
 +
| 0000
 +
| 1
 +
| Pen and Paper information
 +
|-
 +
| 0001
 +
| 48
 +
| Layer 1 line encoding
 +
|-
 +
| 0031
 +
| 48
 +
| Layer 2 line encoding
 +
|-
 +
| 0061
 +
| ?
 +
| The frame data stored layer 1 then layer 2
 +
|}
 +
 +
The pen and paper byte at the start is encoded as follows:
 +
 +
[[Image:paperpeninfo.png]]
 +
 +
The paper bit indicates what color the paper is - 0 for black and 1 for white.
 +
 +
The Layer 1 pen and Layer 2 pen information is as follows:
 +
 +
{| class="wikitable"
 +
|- style="background-color: #ddd;"
 +
! Number
 +
! Meaning
 +
|-
 +
| 0
 +
| Not used
 +
|-
 +
| 1
 +
| Invert Paper (black on white or white on black)
 +
|-
 +
| 2
 +
| Red
 +
|-
 +
| 3
 +
| Blue
 +
|}
 +
 +
Line encoding is compacted from the 192 lines on the screen down to 48 bytes per layer, each byte within the layer encoding section is stored as 2 bits per line, and 4 lines to the byte.  The lines are stored in the same order as the bits in the byte, i.e. line 0 uses bit 0-1, line 1 uses bit 2-3, line 2 uses bit 4-5, line 3 uses bit 6-7.  The value for the line encoding determins how many bytes you need to read at a minimum:
 +
 +
{| class="wikitable"
 +
|- style="background-color: #ddd;"
 +
! Number
 +
! Meaning
 +
|-
 +
| 0
 +
| Skip this line - there is no data for this line
 +
|-
 +
| 1
 +
| Coded line
 +
|-
 +
| 2
 +
| Inverted coded line
 +
|-
 +
| 3
 +
| Raw line data
 +
|}
 +
 +
Before I explain how to read the line data you must understand that the way flipnote works is in layers, each layer is a bit map of on or off, with on being the pen colour, and off being the paper colour.
 +
 +
The coded and inverted coded lines are stored with a 4 byte header that is used to indicate how many extra bytes to read, and what part of the line they represent.  Each byte after the first 4 is then read in a reverse order, i.e. pixel 0 of 8 is bit 0, etc.  To understand this you first take the 256 pixels of the line, and divide it by 8 to give 32, this is the maximum number of bytes a line encoding will ever use, and it's also the number of bits in 4 bytes.  The first 8 pixels of the line are used only when the bit 0x80000000 is set in the initial 4 bytes.
 +
 +
For example the line is encoded as type 1, and the bytes that's stored is 80 00 00 00 20.
 +
 +
The first 4 bytes is indicating that there is 1 byte effacted in this line, and that it's the first 8 pixels in the line.  The next byte is read and once it's expanded the 6'th byte of the line is set to the pen colour.  If on the other hand the line was encoded with type 2, that one pixel would be the paper colour and every other pixel would be the pen colour.
 +
 +
Here's some code to show how to decode the line:
 +
 +
<source lang="c">
 +
u32 decodeLine( u8 *outB, u8 *inB, u32 useByte, u8 paper, u8 pen, u8 invflag )
 +
{
 +
u32 offset = 0;
 +
u16 x = 0, i;
 +
u8 data;
 +
 +
if( useByte == 0 ) // Set the full line to the current paper colour
 +
memset( outB, paper, 256 );
 +
else // Bytes in this line, read and deal with them
 +
{
 +
while( useByte != 0 )
 +
{
 +
if( ( useByte & 0x80000000 ) == 0x80000000 )
 +
{
 +
// This byte exists...
 +
data = inB[ offset++ ];
 +
 +
for( i = 0; i < 8; i ++ )
 +
{
 +
if( ( data & 0x01 ) == 0x01 )
 +
outB[ x ] = invflag == 0 ? pen : paper;
 +
else
 +
outB[ x ] = invflag == 0 ? paper : pen;
 +
 +
x ++;
 +
 +
data >>= 1;
 +
}
 +
}
 +
else
 +
{
 +
memset( &outB[ x ], paper, 8 );
 +
x += 8;
 +
}
 +
 +
useByte <<= 1;
 +
}
 +
 +
if( x < 256 )
 +
memset( &outB[ x ], paper, 256 - x );
 +
}
 +
 +
return offset;
 +
}
 +
</source>
 +
 +
The outB and inB are pointers to pre-allocated memory blocks, the inB is a pointer to the file, and the outB is the output data block.  The useByte is the 4 bytes that is at the start of the line, if your reading a type 3 line (full raw data) just pass in 0xFFFFFFFF.  The pen and paper values are what was read from the pen and paper information block.
36

edits