One important consideration is that the UExporter/UFactory class you add needs to get loaded, either because the dll file it is implemented in was already loader, or by using some autoloading out of int files approach. I included the autoloading code in the UCC.cpp of my [url=http://www.oldunreal.com/cgi-bin/yabb2/YaBB.pl?num=1445541914]HP1 PubSrc[/url] if you want to take a look at it. Smirftsch added the autoloading of UFactories/UExporters to 227j some time ago too.
Anyway, here you go:
Code: Select all
// Imports Palette in Adobe Color Table file format.
class HTK_API UPaletteFactoryACT : public UFactory
{
DECLARE_HTK_CLASS(UPaletteFactoryACT,UFactory,0)
// Constructors.
UPaletteFactoryACT();
void StaticConstructor();
// UFactory interfacce.
UObject* FactoryCreateBinary( UClass* Class, UObject* InParent, FName Name, DWORD Flags, UObject* Context, const TCHAR* Type, const BYTE*& Buffer, const BYTE* BufferEnd, FFeedbackContext* Warn );
};
// Exports Palette to Adobe Color Table file format.
class HTK_API UPaletteExporterACT : public UExporter
{
DECLARE_HTK_CLASS(UPaletteExporterACT,UExporter,0)
// Constructors.
UPaletteExporterACT();
void StaticConstructor();
// UExporter interface.
UBOOL ExportBinary( UObject* Object, const TCHAR* Type, FArchive& Ar, FFeedbackContext* Warn );
};
Code: Select all
/*=============================================================================
UPaletteFactoryACT.cpp: Imports a Palette in Adobe Color Table format.
Copyright 2016 Sebastian Kaufel. All Rights Reserved.
Revision history:
* Created by Sebastian Kaufel
References:
* http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_pgfId-1070626
Notes:
* They missed the "8 bytes" part in the documentation.
* Format is RGB only.
=============================================================================*/
#include "HTK.h"
/*-----------------------------------------------------------------------------
Defines.
-----------------------------------------------------------------------------*/
#define ACT_FILE_SIZE 768
/*-----------------------------------------------------------------------------
Implementation.
-----------------------------------------------------------------------------*/
IMPLEMENT_CLASS(UPaletteFactoryACT);
/*-----------------------------------------------------------------------------
Constructors.
-----------------------------------------------------------------------------*/
UPaletteFactoryACT::UPaletteFactoryACT()
{
guard(UPaletteFactoryACT::UPaletteFactoryACT);
unguard;
}
void UPaletteFactoryACT::StaticConstructor()
{
guard(UPaletteFactoryACT::StaticConstructor);
SupportedClass = UPalette::StaticClass();
AutoPriority = 0;
bCreateNew = 0;
bText = 0;
new(Formats)FString(TEXT("act;Adobe Color Table"));
unguard;
}
/*-----------------------------------------------------------------------------
UFactory interface.
-----------------------------------------------------------------------------*/
UObject* UPaletteFactoryACT::FactoryCreateBinary( UClass* Class, UObject* InParent, FName Name, DWORD Flags, UObject* Context, const TCHAR* Type, const BYTE*& Buffer, const BYTE* BufferEnd, FFeedbackContext* Warn )
{
guard(UPaletteFactoryACT::FactoryCreateBinary);
size_t Size = BufferEnd-Buffer;
if ( Size==ACT_FILE_SIZE )
{
UPalette* Palette = new(InParent,Name,Flags) UPalette;
Palette->Colors.Empty();
Palette->Colors.AddZeroed( NUM_PAL_COLORS );
for ( INT i=0; i<NUM_PAL_COLORS; i++ )
Palette->Colors(i) = FColor(Buffer[i*3],Buffer[i*3+1],Buffer[i*3+2],255);
return Palette;
}
// Don't import if size mismatches, but put out a warning.
else
{
Warn->Logf( NAME_Warning, TEXT("Adobe Color Table file is %i bytes, should be %i bytes. Skipping Import."), Size, ACT_FILE_SIZE );
return NULL;
}
unguard;
}
/*-----------------------------------------------------------------------------
The End.
-----------------------------------------------------------------------------*/
Code: Select all
/*=============================================================================
UPaletteExporterACT.cpp: Exports Palette to Adobe Color Table format.
Copyright 2016 Sebastian Kaufel. All Rights Reserved.
Revision history:
* Created by Sebastian Kaufel
References:
* http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_pgfId-1070626
Notes:
* They missed the "8 bytes" part in the documentation.
* Format is RGB only.
=============================================================================*/
#include "HTK.h"
/*-----------------------------------------------------------------------------
Implementation.
-----------------------------------------------------------------------------*/
IMPLEMENT_CLASS(UPaletteExporterACT);
/*-----------------------------------------------------------------------------
Constructors.
-----------------------------------------------------------------------------*/
UPaletteExporterACT::UPaletteExporterACT()
{
guard(UPaletteExporterACT::UPaletteExporterACT);
unguard;
}
void UPaletteExporterACT::StaticConstructor()
{
guard(UPaletteExporterACT::StaticConstructor);
// Set Supported Class.
SupportedClass = UPalette::StaticClass();
// Set Binary Mode.
bText = 0;
new(Formats) FString(TEXT("ACT"));
unguard;
}
/*-----------------------------------------------------------------------------
UExporter interface.
-----------------------------------------------------------------------------*/
UBOOL UPaletteExporterACT::ExportBinary( UObject* Object, const TCHAR* Type, FArchive& Ar, FFeedbackContext* Warn )
{
guard(UPaletteExporterACT::ExportBinary);
UPalette* Palette = Cast<UPalette>( Object );
if ( Palette )
{
if ( Palette->Colors.Num()!=NUM_PAL_COLORS )
Warn->Logf( NAME_Warning, TEXT("Found %i Palette Colors, should be %i."), Palette->Colors.Num(), NUM_PAL_COLORS );
// Write Palette Contents.
INT Index;
for ( Index=0; Index<Min(Palette->Colors.Num(),256); Index++ )
Ar.Serialize( &Palette->Colors(Index), 3 );
// Write Black until end of ACT.
DWORD Black=0;
for ( Index; Index<256; Index++ )
Ar.Serialize( &Black, 3 );
return 1;
}
return 0;
unguard;
}
/*-----------------------------------------------------------------------------
The End.
-----------------------------------------------------------------------------*/
Code: Select all
[Public]
Object=(Name=HTK.PaletteFactoryACT,Class=Class,MetaClass=Core.Factory)
Object=(Name=HTK.PaletteExporterACT,Class=Class,MetaClass=Core.Exporter)
- The "Type" parameter in UFactory::FactoryCreateBinary/UExporter::ExportBinary contains the file extension.
- For text files you would set UFactory::bText/UExporter::bText to 1 inside the StaticContructor and implement the UFactory::FactoryCreateText/UExporter::ExportText interface.