2011-05-14 20:11:36 +00:00
|
|
|
#include <fonts.h>
|
|
|
|
#include <render.h>
|
|
|
|
|
|
|
|
// Local function: Get next nibble.
|
2011-08-03 16:37:41 +00:00
|
|
|
static int ctr=0; // offset for next nibble
|
|
|
|
static int hilo=0; // 0= high nibble next, 1=low nibble next
|
2011-05-18 15:51:03 +00:00
|
|
|
const uint8_t * data;
|
2011-08-03 16:37:41 +00:00
|
|
|
static char gnn(){ // Get next nibble
|
2011-05-14 20:11:36 +00:00
|
|
|
static int byte;
|
|
|
|
int val;
|
2011-05-23 00:35:02 +00:00
|
|
|
if(hilo==1)
|
|
|
|
ctr++;
|
2011-05-14 20:11:36 +00:00
|
|
|
hilo=1-hilo;
|
|
|
|
if(hilo==1){
|
2011-07-23 12:30:20 +00:00
|
|
|
if(efont.type==FONT_EXTERNAL){
|
|
|
|
byte=_getFontData(GET_DATA,0);
|
|
|
|
}else{
|
|
|
|
byte=data[ctr];
|
|
|
|
};
|
2011-05-14 20:11:36 +00:00
|
|
|
val=byte>>4;
|
|
|
|
}else{
|
|
|
|
val=byte&0x0f;
|
|
|
|
};
|
|
|
|
return val;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Local function: Unpack "long run".
|
2011-05-14 22:38:09 +00:00
|
|
|
int upl(int off){
|
2011-05-14 20:11:36 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
while((retval=gnn())==0){
|
|
|
|
off++;
|
|
|
|
};
|
|
|
|
while(off-->0){
|
|
|
|
retval=retval<<4;
|
|
|
|
retval+=gnn();
|
|
|
|
};
|
|
|
|
return retval;
|
|
|
|
};
|
|
|
|
|
2011-05-18 15:51:03 +00:00
|
|
|
|
|
|
|
uint8_t * pk_decode(const uint8_t * ldata,int * len){
|
2011-05-22 15:17:48 +00:00
|
|
|
ctr=0;hilo=0;
|
2011-05-18 15:51:03 +00:00
|
|
|
data=ldata;
|
|
|
|
int length=*len; // Length of character bytestream
|
|
|
|
int height; // Height of character in bytes
|
|
|
|
int hoff; // bit position for non-integer heights
|
2011-07-23 12:30:20 +00:00
|
|
|
uint8_t * bufptr=charBuf; // Output buffer for decoded character
|
2011-05-18 15:51:03 +00:00
|
|
|
|
|
|
|
height=(font->u8Height-1)/8+1;
|
|
|
|
hoff=font->u8Height%8;
|
|
|
|
|
2011-05-14 22:38:09 +00:00
|
|
|
#define DYN (12) // Decoder parameter: Fixed value for now.
|
2011-05-14 20:11:36 +00:00
|
|
|
int repeat=0; // Decoder internal: repeat colum?
|
|
|
|
int curbit=0; // Decoder internal: current bit (1 or 0)
|
2011-05-14 22:38:09 +00:00
|
|
|
int pos=0; // Decoder internal: current bit position (0..7)
|
2011-05-14 20:11:36 +00:00
|
|
|
int nyb; // Decoder internal: current nibble / value
|
|
|
|
|
2011-07-23 12:30:20 +00:00
|
|
|
if(efont.type==FONT_EXTERNAL){
|
|
|
|
if(_getFontData(PEEK_DATA,0)>>4 == 14){ // Char starts with 1-bits.
|
|
|
|
gnn();
|
|
|
|
curbit=1;
|
|
|
|
};
|
|
|
|
}else{
|
|
|
|
if(data[ctr]>>4 == 14){ // Char starts with 1-bits.
|
|
|
|
gnn();
|
|
|
|
curbit=1;
|
|
|
|
};
|
|
|
|
};
|
2011-05-15 22:15:39 +00:00
|
|
|
|
2011-05-14 20:11:36 +00:00
|
|
|
while(ctr<length){ /* Iterate the whole input stream */
|
|
|
|
|
|
|
|
/* Get next encoded nibble and decode */
|
|
|
|
nyb=gnn();
|
|
|
|
|
|
|
|
if(nyb==15){
|
|
|
|
repeat++;
|
|
|
|
continue;
|
|
|
|
}else if(nyb==14){
|
|
|
|
nyb=upl(0);
|
|
|
|
nyb+=1;
|
|
|
|
repeat+=nyb;
|
|
|
|
continue;
|
2011-05-14 22:38:09 +00:00
|
|
|
}else if(nyb>DYN){
|
|
|
|
nyb=(16*(nyb-DYN-1))+gnn()+DYN+1;
|
2011-05-14 20:11:36 +00:00
|
|
|
}else if(nyb==0){
|
|
|
|
nyb=upl(1);
|
2011-05-14 22:38:09 +00:00
|
|
|
nyb+=(16*(13-DYN)+DYN)-16;
|
2011-05-14 20:11:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Generate & output bits */
|
|
|
|
|
|
|
|
while(nyb-->0){
|
2011-05-14 22:38:09 +00:00
|
|
|
if(pos==0) // Clear each byte before we start.
|
2011-05-14 20:15:30 +00:00
|
|
|
*bufptr=0;
|
2011-05-14 20:11:36 +00:00
|
|
|
if(curbit==1){
|
|
|
|
*bufptr|=1<<(7-pos);
|
|
|
|
};
|
|
|
|
pos++;
|
2011-07-23 12:30:20 +00:00
|
|
|
if(((bufptr-charBuf)%height)==(height-1) && (pos==hoff)){
|
2011-05-14 20:15:30 +00:00
|
|
|
// Finish incomplete last byte per column
|
|
|
|
pos=8;
|
|
|
|
};
|
|
|
|
|
2011-05-14 20:11:36 +00:00
|
|
|
if(pos==8){
|
|
|
|
bufptr++;
|
2011-07-23 12:30:20 +00:00
|
|
|
if((bufptr-charBuf)%height==0){ // End of column?
|
2011-05-14 20:11:36 +00:00
|
|
|
while(repeat>0){
|
|
|
|
for(int y=0;y<height;y++){
|
2011-05-22 18:32:23 +00:00
|
|
|
bufptr[0]=bufptr[-height];
|
2011-05-14 20:11:36 +00:00
|
|
|
bufptr++;
|
|
|
|
};
|
|
|
|
repeat--;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
pos=0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
curbit=1-curbit;
|
|
|
|
};
|
|
|
|
|
2011-07-23 12:30:20 +00:00
|
|
|
*len=(bufptr-charBuf)/height; // return size of output buffer.
|
|
|
|
return charBuf;
|
2011-05-14 20:11:36 +00:00
|
|
|
};
|