Clean ntsc export bmp, WIP: import bmp

This commit is contained in:
michaelangel007 2015-01-10 12:14:38 -08:00
parent c286f7fc99
commit 9ffc6b7491

View File

@ -4964,10 +4964,10 @@ Update_t CmdNTSC (int nArgs)
} }
}; };
class Transpose4096x4to64x256 class Transpose4096x4
{ {
public: public:
static void transpose( size_t nSize, const uint8_t *pSrc, uint8_t *pDst ) static void transposeTo64x256( size_t nSize, const uint8_t *pSrc, uint8_t *pDst )
{ {
/* /*
Source layout = 4096x4 @ 32-bit Source layout = 4096x4 @ 32-bit
@ -5013,17 +5013,16 @@ Update_t CmdNTSC (int nArgs)
pDst += (64*nBPP); // move to next scan line pDst += (64*nBPP); // move to next scan line
} }
} }
}
/* static void transposeFrom64x256( size_t nSize, const uint8_t *pSrc, uint8_t *pDst )
for( int nPhase = 0; nPhase < 4; nPhase++ )
{ {
for( int x = 0; x < 1024; x++ ) for( int iPhase = 0; iPhase < 4; iPhase++ )
for( int y = 0; y < 4; y+= ) {
for( int y = 0; y < 256; y++ )
{ {
pSrc = pBeg + (nPhase * 4)
} }
} }
*/
} }
}; };
@ -5045,20 +5044,21 @@ Update_t CmdNTSC (int nArgs)
size_t nWrote = 0; size_t nWrote = 0;
uint8_t *pSwizzled = new uint8_t[ g_nChromaSize ]; uint8_t *pSwizzled = new uint8_t[ g_nChromaSize ];
// Write BMP
if( iFileType == TYPE_BMP ) if( iFileType == TYPE_BMP )
{ {
// need to save 32-bit bpp as 24-bit bpp // need to save 32-bit bpp as 24-bit bpp
// VideoSaveScreenShot() // VideoSaveScreenShot()
Swizzle32::swizzleRB( g_nChromaSize, (uint8_t*) pChromaTable, pSwizzled ); Transpose4096x4::transposeTo64x256( g_nChromaSize, (uint8_t*) pChromaTable, pSwizzled );
Transpose4096x4to64x256::transpose( g_nChromaSize, (uint8_t*) pChromaTable, pSwizzled ); Swizzle32::swizzleRB( g_nChromaSize, pSwizzled, pSwizzled ); // Note: Swizzle in-place!
// Write BMP header // Write BMP header
WinBmpHeader_t bmp, *pBmp = &bmp;
Video_SetBitmapHeader( pBmp, 64, 256, 32 );
fwrite( pBmp, sizeof( WinBmpHeader_t ), 1, pFile );
} }
else else
{ {
// Write RAW // RAW has no header
Swizzle32::swizzleRB( g_nChromaSize, (uint8_t*) pChromaTable, pSwizzled ); Swizzle32::swizzleRB( g_nChromaSize, (uint8_t*) pChromaTable, pSwizzled );
} }
@ -5082,9 +5082,13 @@ Update_t CmdNTSC (int nArgs)
else else
if (iParam == PARAM_LOAD) if (iParam == PARAM_LOAD)
{ {
char aStatusText[64] = "Loaded";
FILE *pFile = fopen( sPaletteFilePath, "rb" ); FILE *pFile = fopen( sPaletteFilePath, "rb" );
if( pFile ) if( pFile )
{ {
strcpy( aStatusText, "Loaded" );
// Get File Size // Get File Size
size_t nFileSize = _GetFileSize( pFile ); size_t nFileSize = _GetFileSize( pFile );
uint8_t *pSwizzled = new uint8_t[ g_nChromaSize ]; uint8_t *pSwizzled = new uint8_t[ g_nChromaSize ];
@ -5095,26 +5099,46 @@ Update_t CmdNTSC (int nArgs)
return ConsoleUpdate(); return ConsoleUpdate();
} }
if( iFileType == TYPE_BMP )
{
WinBmpHeader_t bmp, *pBmp = &bmp;
fread( pBmp, sizeof( WinBmpHeader_t ), 1, pFile );
fseek( pFile, pBmp->nOffsetData, SEEK_SET );
if( 0
|| (pBmp->nWidthPixels != 64 )
|| (pBmp->nHeightPixels != 256)
|| (pBmp->nBitsPerPixel != 32 )
|| (pBmp->nOffsetData > nFileSize)
)
{
strcpy( aStatusText, "Bitmap not 64x256@32" );
goto _error;
}
}
size_t nRead = fread( pSwizzled, g_nChromaSize, 1, pFile ); size_t nRead = fread( pSwizzled, g_nChromaSize, 1, pFile );
if( iFileType == TYPE_BMP ) if( iFileType == TYPE_BMP )
{ {
Transpose4096x4::transposeFrom64x256( g_nChromaSize, pSwizzled, (uint8_t*) pChromaTable );
Swizzle32::swizzleRB( g_nChromaSize, (uint8_t*)pChromaTable, (uint8_t*)pChromaTable ); // Note: Swizzle in-place!
} }
else // RAW else // RAW
{ {
Swizzle32::swizzleRB( g_nChromaSize, pSwizzled, (uint8_t*) pChromaTable ); Swizzle32::swizzleRB( g_nChromaSize, pSwizzled, (uint8_t*) pChromaTable );
} }
_error:
fclose( pFile ); fclose( pFile );
delete [] pSwizzled; delete [] pSwizzled;
ConsoleFilename::update( "Loaded" );
} }
else else
{ {
ConsoleFilename::update( "File: " ); strcpy( aStatusText, "File: " );
ConsoleBufferPush( TEXT( "Error couldn't open file for reading." ) ); ConsoleBufferPush( TEXT( "Error couldn't open file for reading." ) );
} }
ConsoleFilename::update( aStatusText );
} }
else else
return HelpLastCommand(); return HelpLastCommand();