Created
February 6, 2018 11:42
-
-
Save petru23/e9e94d540e3334b9ae0c5baf97652800 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "GifFactory.h" | |
#include <stdlib.h> | |
#define STB_IMAGE_IMPLEMENTATION | |
#include "stb_image.h" | |
UGifFactory::UGifFactory() | |
{ | |
bEditorImport = true; | |
SupportedClass = UTexture2D::StaticClass(); | |
Formats.Add(FString("gif;Graphics Interchange Format")); | |
} | |
UObject *UGifFactory::FactoryCreateFile | |
( | |
UClass *InClass, | |
UObject *InParent, | |
FName InName, | |
EObjectFlags Flags, | |
const FString &Filename, | |
const TCHAR *Parms, | |
FFeedbackContext *Warn, | |
bool &bOutOperationCanceled | |
) | |
{ | |
int32 Width, Height, Comp; | |
unsigned char *file = stbi_load(TCHAR_TO_ANSI(*Filename), &Width, &Height, &Comp, 3); | |
int32 ColorsLength = Height * Width * 3; | |
TArray<FColor> Colors; | |
Colors.Reserve(Height * Width); | |
for (int i = 0; i < ColorsLength; i++) | |
{ | |
uint8 R = (uint8)file[i]; | |
uint8 G = (uint8)file[i + 1]; | |
uint8 B = (uint8)file[i + 2]; | |
FColor PixelColor(R, G, B); | |
Colors.Add(PixelColor); | |
} | |
FCreateTexture2DParameters Params; | |
UTexture2D *NewTexture = FImageUtils::CreateTexture2D(Width, Height, Colors, InParent, InName.ToString(), Flags | RF_Transactional, Params); | |
return NewTexture; | |
} | |
FText UGifFactory::GetDisplayName() const | |
{ | |
return FText::FromString(TEXT("Gif Image")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment