mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-21 23:45:20 +02:00
Nicer resize method for VideoBuffer, fix Local and Server save previews
This commit is contained in:
@@ -50,21 +50,31 @@ void VideoBuffer::Resize(float factor, bool resample)
|
|||||||
Resize(newWidth, newHeight);
|
Resize(newWidth, newHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoBuffer::Resize(int width, int height, bool resample)
|
void VideoBuffer::Resize(int width, int height, bool resample, bool fixedRatio)
|
||||||
{
|
{
|
||||||
int newWidth = width;
|
int newWidth = width;
|
||||||
int newHeight = height;
|
int newHeight = height;
|
||||||
pixel * newBuffer;
|
pixel * newBuffer;
|
||||||
if(newHeight == -1 && newWidth == -1)
|
if(newHeight == -1 && newWidth == -1)
|
||||||
return;
|
return;
|
||||||
|
if(newHeight == -1 || newWidth == -1)
|
||||||
|
{
|
||||||
if(newHeight == -1)
|
if(newHeight == -1)
|
||||||
{
|
|
||||||
newHeight = ((float)Height)*((float)newWidth/(float)Width);
|
newHeight = ((float)Height)*((float)newWidth/(float)Width);
|
||||||
}
|
|
||||||
if(newWidth == -1)
|
if(newWidth == -1)
|
||||||
{
|
|
||||||
newWidth = ((float)Width)*((float)newHeight/(float)Height);
|
newWidth = ((float)Width)*((float)newHeight/(float)Height);
|
||||||
}
|
}
|
||||||
|
else if(fixedRatio)
|
||||||
|
{
|
||||||
|
//Force proportions
|
||||||
|
float scaleFactor = 1.0f;
|
||||||
|
if(Height > newHeight)
|
||||||
|
scaleFactor = ((float)newHeight)/((float)Height);
|
||||||
|
if(Width > newWidth)
|
||||||
|
scaleFactor = ((float)newWidth)/((float)Width);
|
||||||
|
newWidth = ((float)Width)*scaleFactor;
|
||||||
|
newHeight = ((float)Height)*scaleFactor;
|
||||||
|
}
|
||||||
if(resample)
|
if(resample)
|
||||||
newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight);
|
newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight);
|
||||||
else
|
else
|
||||||
|
@@ -113,7 +113,7 @@ public:
|
|||||||
VideoBuffer(pixel * buffer, int width, int height);
|
VideoBuffer(pixel * buffer, int width, int height);
|
||||||
VideoBuffer(int width, int height);
|
VideoBuffer(int width, int height);
|
||||||
void Resize(float factor, bool resample = false);
|
void Resize(float factor, bool resample = false);
|
||||||
void Resize(int width, int height, bool resample = false);
|
void Resize(int width, int height, bool resample = false, bool fixedRatio = true);
|
||||||
TPT_INLINE void BlendPixel(int x, int y, int r, int g, int b, int a)
|
TPT_INLINE void BlendPixel(int x, int y, int r, int g, int b, int a)
|
||||||
{
|
{
|
||||||
#ifdef PIX32OGL
|
#ifdef PIX32OGL
|
||||||
|
@@ -128,12 +128,18 @@ void LocalSaveActivity::OnDraw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalSaveActivity::OnRequestReady(void * imagePtr)
|
void LocalSaveActivity::OnResponseReady(void * imagePtr)
|
||||||
{
|
{
|
||||||
this->thumbnail = (VideoBuffer*)imagePtr;
|
if(thumbnail)
|
||||||
|
delete thumbnail;
|
||||||
|
thumbnail = (VideoBuffer*)imagePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalSaveActivity::~LocalSaveActivity()
|
LocalSaveActivity::~LocalSaveActivity()
|
||||||
{
|
{
|
||||||
|
RequestBroker::Ref().DetachRequestListener(this);
|
||||||
|
if(thumbnail)
|
||||||
|
delete thumbnail;
|
||||||
|
if(callback)
|
||||||
|
delete callback;
|
||||||
}
|
}
|
@@ -34,6 +34,6 @@ public:
|
|||||||
void saveWrite(std::string finalFilename);
|
void saveWrite(std::string finalFilename);
|
||||||
virtual void Save();
|
virtual void Save();
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual void OnRequestReady(void * imagePtr);
|
virtual void OnResponseReady(void * imagePtr);
|
||||||
virtual ~LocalSaveActivity();
|
virtual ~LocalSaveActivity();
|
||||||
};
|
};
|
@@ -249,15 +249,20 @@ void ServerSaveActivity::OnDraw()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSaveActivity::OnRequestReady(void * imagePtr)
|
void ServerSaveActivity::OnResponseReady(void * imagePtr)
|
||||||
{
|
{
|
||||||
this->thumbnail = (VideoBuffer *)imagePtr;
|
if(thumbnail)
|
||||||
|
delete thumbnail;
|
||||||
|
thumbnail = (VideoBuffer *)imagePtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerSaveActivity::~ServerSaveActivity()
|
ServerSaveActivity::~ServerSaveActivity()
|
||||||
{
|
{
|
||||||
|
RequestBroker::Ref().DetachRequestListener(this);
|
||||||
if(saveUploadTask)
|
if(saveUploadTask)
|
||||||
delete saveUploadTask;
|
delete saveUploadTask;
|
||||||
if(callback)
|
if(callback)
|
||||||
delete callback;
|
delete callback;
|
||||||
|
if(thumbnail)
|
||||||
|
delete thumbnail;
|
||||||
}
|
}
|
@@ -29,7 +29,7 @@ public:
|
|||||||
virtual void Save();
|
virtual void Save();
|
||||||
virtual void Exit();
|
virtual void Exit();
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual void OnRequestReady(void * imagePtr);
|
virtual void OnResponseReady(void * imagePtr);
|
||||||
virtual void OnTick(float dt);
|
virtual void OnTick(float dt);
|
||||||
virtual ~ServerSaveActivity();
|
virtual ~ServerSaveActivity();
|
||||||
protected:
|
protected:
|
||||||
|
Reference in New Issue
Block a user