Permalink
Browse files

PCK Compression Mode 1 fully supported

  • Loading branch information...
pmprog committed Jul 15, 2014
1 parent 7f28084 commit 9c96e89fe74ff69f320ba96ad6f8b6bf7f0fff34
@@ -48,11 +48,6 @@ void Cursor::EventOccured( Event* e )
cursorx = e->Data.Mouse.X;
cursory = e->Data.Mouse.Y;
}
if( e->Type == EVENT_MOUSE_DOWN )
{
CurrentType = (CursorType)(((int)CurrentType + 1) % images.size());
}
}
void Cursor::Render()
@@ -44,3 +44,28 @@ void Palette::SetColour(int Index, Colour* Col)
colours[Index].b = Col->b;
}
void Palette::DumpPalette( std::string Filename )
{
ALLEGRO_BITMAP* b = al_create_bitmap( 16, 16 );
ALLEGRO_LOCKED_REGION* r = al_lock_bitmap( b, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, 0 );
int c = 0;
for( int y = 0; y < 16; y++ )
{
for( int x = 0; x < 16; x++ )
{
Colour* c1_rowptr = (Colour*)(&((char*)r->data)[ (y * r->pitch) + (x * 4) ]);
Colour* c1_palcol = GetColour( c );
c1_rowptr->a = c1_palcol->a;
c1_rowptr->r = c1_palcol->r;
c1_rowptr->g = c1_palcol->g;
c1_rowptr->b = c1_palcol->b;
c++;
}
}
al_unlock_bitmap( b );
al_save_bitmap( Filename.c_str(), b );
al_destroy_bitmap( b );
}
@@ -22,5 +22,7 @@ class Palette
Colour* GetColour(int Index);
void SetColour(int Index, Colour* Col);
void DumpPalette( std::string Filename );
};
View
@@ -3,6 +3,8 @@
PCK::PCK( std::string PckFilename, std::string TabFilename, bool ContainsTerrain, Palette* ColourPalette )
{
Memory* tmp;
ALLEGRO_FILE* pck = al_fopen( PckFilename.c_str(), "rb" );
ALLEGRO_FILE* tab = al_fopen( TabFilename.c_str(), "rb" );
@@ -12,24 +14,24 @@ PCK::PCK( std::string PckFilename, std::string TabFilename, bool ContainsTerrain
ALLEGRO_BITMAP* bitmap;
ALLEGRO_LOCKED_REGION* region;
int c1_regionlocation;
int32_t c1_pixelstoskip;
int c1_startcol;
int c1_pixelsinrecord;
int c1_reserved;
int c1_pxcount2;
PCKCompression1Header c1_header;
for( int i = 0; i < al_fsize( tab ) / 4; i++ )
{
unsigned int offset = al_fread32le( tab );
al_fseek( pck, offset, ALLEGRO_SEEK_SET );
offset *= 4;
// Terrain blocks
if( terrain )
{
offset *= 4;
}
al_fseek( pck, offset, ALLEGRO_SEEK_SET );
// Read each "angle"
for( int tidx = 1; tidx <= (terrain ? 4 : 1); tidx++ )
{
@@ -41,29 +43,36 @@ PCK::PCK( std::string PckFilename, std::string TabFilename, bool ContainsTerrain
break;
case 1:
bitmap = al_create_bitmap( 640, 480 );
// No compression
bitmap = al_create_bitmap( imgheader.RightMostPixel - imgheader.LeftMostPixel, imgheader.BottomMostPixel - imgheader.TopMostPixel );
region = al_lock_bitmap( bitmap, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, 0 );
c1_regionlocation = 0;
c1_pixelstoskip = al_fread32le( pck );
while( c1_pixelstoskip != -1 )
{
c1_regionlocation = ((c1_pixelstoskip / 640) * region->pitch) + (c1_pixelstoskip % 640);
c1_startcol = al_fgetc( pck );
c1_pixelsinrecord = al_fgetc( pck );
c1_reserved = al_fgetc( pck );
c1_pxcount2 = al_fgetc( pck );
al_fread( pck, &c1_header, sizeof( PCKCompression1Header ) );
int c1_y = (c1_pixelstoskip / 640) - imgheader.TopMostPixel;
for( int c1_x = 0; c1_x < c1_pixelsinrecord; c1_x++ )
for( int c1_x = 0; c1_x < c1_header.PixelsInRow - c1_header.PaddingInRow; c1_x++ )
{
Colour* c1_rowptr = (Colour*)(&((char*)region->data)[ c1_regionlocation + (c1_x * 4) ]);
Colour* c1_palcol = ColourPalette->GetColour( al_fgetc( pck ) );
c1_rowptr->a = c1_palcol->a;
c1_rowptr->r = c1_palcol->r;
c1_rowptr->g = c1_palcol->g;
c1_rowptr->b = c1_palcol->b;
if( (c1_header.ColumnToStartAt + c1_x - imgheader.LeftMostPixel) < imgheader.RightMostPixel - imgheader.LeftMostPixel )
{
int dataptr = (c1_y * region->pitch) + ((c1_header.ColumnToStartAt + c1_x - imgheader.LeftMostPixel) * 4);
Colour* c1_rowptr = (Colour*)(&((char*)region->data)[ dataptr ]);
Colour* c1_palcol = ColourPalette->GetColour( al_fgetc( pck ) );
c1_rowptr->a = c1_palcol->a;
c1_rowptr->r = c1_palcol->r;
c1_rowptr->g = c1_palcol->g;
c1_rowptr->b = c1_palcol->b;
} else {
// Pretend to process data
al_fgetc( pck );
}
}
tmp = new Memory(c1_header.PaddingInRow);
al_fread( pck, tmp->GetData(), c1_header.PaddingInRow );
delete tmp;
c1_pixelstoskip = al_fread32le( pck );
}
@@ -76,9 +85,15 @@ PCK::PCK( std::string PckFilename, std::string TabFilename, bool ContainsTerrain
break;
case 3:
// Divide by 0 should indicate we've tried to load a Mode 3 compressed image
imgheader.Reserved2 = 0;
imgheader.Reserved1 = 2 / imgheader.Reserved2;
break;
case 128:
// Divide by 0 should indicate we've tried to load a Mode 128 compressed image
imgheader.Reserved2 = 0;
imgheader.Reserved1 = 2 / imgheader.Reserved2;
break;
default:
View
@@ -17,6 +17,15 @@ typedef struct PCKImageHeader
int16_t BottomMostPixel;
} PCKImageHeader;
typedef struct PCKCompression1Header
{
// int16_t SkipPixels; -- Read seperately to get eof record
char ColumnToStartAt;
char PixelsInRow;
char Reserved1;
char PaddingInRow;
} PCKCompression1Header;
class PCK
{
View
@@ -15,16 +15,17 @@ MainMenu::MainMenu()
FRAMEWORK->Display_SetTarget();
al_destroy_bitmap( titlesbackground );
//fontpalette = new Palette( "UFODATA/PAL_02.DAT" );
fontpalette = new Palette( "TACDATA/TACTICAL.PAL" );
fontpalette = new Palette( "UFODATA/PAL_02.DAT" );
//fontpalette = new Palette( "TACDATA/TACTICAL.PAL" );
largefont = new ApocalypseFont( ApocalypseFont::LargeFont, new Palette( "UFODATA/PAL_06.DAT" ) );
smallfont = new ApocalypseFont( ApocalypseFont::SmallFont, fontpalette );
currentlanguage = new Language( "EN-GB" );
buttonclick = new RawSound( "STRATEGC/INTRFACE/BUTTON1.RAW" );
musicplayer = new Music( 25 );
mousecursor = new Cursor( fontpalette );
testpck = new PCK( "data/UFODATA/ICONS.PCK", "data/UFODATA/ICONS.TAB", false, fontpalette );
testpck = new PCK( "data/UFODATA/VEHICLE.PCK", "data/UFODATA/VEHICLE.TAB", false, fontpalette );
//testpck = new PCK( "data/MAPS/05RESCUE/MAPUNITS/FEATURE.PCK", "data/MAPS/05RESCUE/MAPUNITS/FEATURE.TAB", false, fontpalette );
}
MainMenu::~MainMenu()
@@ -110,9 +111,9 @@ void MainMenu::Render()
mousecursor->Render();
if( testpck->GetImageCount() > 0 )
for( int x = 0; x < testpck->GetImageCount(); x++ )
{
testpck->RenderImage( 1, 0, 0 );
testpck->RenderImage( x, (x * 40) % 640, ((x * 40) / 640) * 40 );
}
}
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.

0 comments on commit 9c96e89

Please sign in to comment.