Convert images.cpp to actual images

Also remove some dead code.
This commit is contained in:
Tamás Bálint Misius 2022-12-25 09:23:38 +01:00
parent 6e9b9cd861
commit bb6c371aa8
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2
13 changed files with 31 additions and 232 deletions

View File

@ -1,89 +0,0 @@
#pragma once
const char *const fireFragment = "#version 120\n\
uniform sampler2D fireAlpha;\
void main () {\
vec4 texColor = texture2D(fireAlpha, gl_PointCoord);\
gl_FragColor = vec4(gl_Color.rgb, texColor.a*gl_Color.a);\
}";
const char *const fireVertex = "#version 120\n\
void main(void)\
{\
gl_Position = ftransform();;\
gl_FrontColor = gl_Color;\
}";
const char *const lensFragment = "#version 120\n\
uniform sampler2D pTex;\
uniform sampler2D tfX;\
uniform sampler2D tfY;\
uniform float xres;\
uniform float yres;\
void main () {\
vec4 transformX = texture2D(tfX, vec2(gl_TexCoord[0].s, -gl_TexCoord[0].t));\
vec4 transformY = -texture2D(tfY, vec2(gl_TexCoord[0].s, -gl_TexCoord[0].t));\
transformX.r /= xres;\
transformY.g /= yres;\
vec4 texColor = vec4(\
texture2D(pTex, gl_TexCoord[0].st-vec2(transformX.r*0.75, transformY.g*0.75)).r,\
texture2D(pTex, gl_TexCoord[0].st-vec2(transformX.r*0.875, transformY.g*0.875)).g,\
texture2D(pTex, gl_TexCoord[0].st-vec2(transformX.r, transformY.g)).b,\
1.0\
);\
gl_FragColor = texColor;\
}";
const char *const lensVertex = "#version 120\n\
void main(void)\
{\
gl_TexCoord[0] = gl_MultiTexCoord0;\
gl_Position = ftransform();;\
gl_FrontColor = gl_Color;\
}";
const char *const airVFragment = "#version 120\n\
uniform sampler2D airX;\
uniform sampler2D airY;\
uniform sampler2D airP;\
void main () {\
vec4 texX = texture2D(airX, gl_TexCoord[0].st);\
vec4 texY = texture2D(airY, gl_TexCoord[0].st);\
vec4 texP = texture2D(airP, gl_TexCoord[0].st);\
gl_FragColor = vec4(abs(texX.r)/2.0, texP.b/2.0, abs(texY.g)/2.0, 1.0);\
}";
const char *const airVVertex = "#version 120\n\
void main(void)\
{\
gl_TexCoord[0] = gl_MultiTexCoord0;\
gl_Position = ftransform();;\
gl_FrontColor = gl_Color;\
}";
const char *const airPFragment = "#version 120\n\
uniform sampler2D airX;\
uniform sampler2D airY;\
uniform sampler2D airP;\
void main () {\
vec4 texP = texture2D(airP, gl_TexCoord[0].st);\
gl_FragColor = vec4(max(texP.b/2.0, 0), 0, abs(min(texP.b/2.0, 0)), 1.0);\
}";
const char *const airPVertex = "#version 120\n\
void main(void)\
{\
gl_TexCoord[0] = gl_MultiTexCoord0;\
gl_Position = ftransform();;\
gl_FrontColor = gl_Color;\
}";
const char *const airCFragment = "#version 120\n\
uniform sampler2D airX;\
uniform sampler2D airY;\
uniform sampler2D airP;\
void main () {\
vec4 texX = texture2D(airX, gl_TexCoord[0].st);\
vec4 texY = texture2D(airY, gl_TexCoord[0].st);\
vec4 texP = texture2D(airP, gl_TexCoord[0].st);\
gl_FragColor = vec4(max(texP.b/2.0, 0), 0, abs(min(texP.b/2.0, 0)), 1.0) + vec4(abs(texX.r)/8.0, abs(texX.r)/8.0, abs(texX.r)/8.0, 1.0) + vec4(abs(texY.g)/8.0, abs(texY.g)/8.0, abs(texY.g)/8.0, 1.0);\
}";
const char *const airCVertex = "#version 120\n\
void main(void)\
{\
gl_TexCoord[0] = gl_MultiTexCoord0;\
gl_Position = ftransform();;\
gl_FrontColor = gl_Color;\
}";

File diff suppressed because one or more lines are too long

View File

@ -1,23 +0,0 @@
/**
* Powder Toy - Images
*
* Copyright (c) 2008 - 2010 Stanislaw Skowronek.
* Copyright (c) 2010 Simon Robertshaw.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
extern const unsigned char save_to_server_image[];
extern const unsigned char save_to_disk_image[];

View File

@ -1,5 +1,4 @@
data_files += files( data_files += files(
'hmap.cpp', 'hmap.cpp',
'images.cpp',
) )
data_files += to_array.process('font.bz2', extra_args: 'compressed_font_data') data_files += to_array.process('font.bz2', extra_args: 'compressed_font_data')

View File

@ -84,3 +84,6 @@ elif host_platform == 'linux'
configuration: conf_data, configuration: conf_data,
) )
endif endif
data_files += to_array.process('save_local.png', extra_args: 'save_local_png')
data_files += to_array.process('save_online.png', extra_args: 'save_online_png')

BIN
resources/save_local.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

BIN
resources/save_online.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

View File

@ -406,43 +406,6 @@ pixel *Graphics::resample_img(pixel *src, int sw, int sh, int rw, int rh)
#endif #endif
} }
pixel *Graphics::rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f)
{
int i,j,x,y,w,h,r,g,b,c;
pixel p, *q;
w = (sw+f-1)/f;
h = (sh+f-1)/f;
q = (pixel *)malloc(w*h*PIXELSIZE);
for (y=0; y<h; y++)
for (x=0; x<w; x++)
{
r = g = b = c = 0;
for (j=0; j<f; j++)
for (i=0; i<f; i++)
if (x*f+i<sw && y*f+j<sh)
{
p = src[(y*f+j)*sw + (x*f+i)];
if (p)
{
r += PIXR(p);
g += PIXG(p);
b += PIXB(p);
c ++;
}
}
if (c>1)
{
r = (r+c/2)/c;
g = (g+c/2)/c;
b = (b+c/2)/c;
}
q[y*w+x] = PIXRGB(r, g, b);
}
*qw = w;
*qh = h;
return q;
}
int Graphics::textwidth(const String &str) int Graphics::textwidth(const String &str)
{ {
int x = 0; int x = 0;
@ -812,59 +775,22 @@ void Graphics::draw_icon(int x, int y, Icon icon, unsigned char alpha, bool inve
} }
} }
void Graphics::draw_rgba_image(const unsigned char *data_, int x, int y, float alpha) void Graphics::draw_rgba_image(const pixel *data, int w, int h, int x, int y, float alpha)
{ {
unsigned char w, h; for (int j = 0; j < h; j++)
int i, j;
unsigned char r, g, b, a;
unsigned char *data = (unsigned char*)data_;
if (!data) return;
w = *(data++)&0xFF;
h = *(data++)&0xFF;
for (j=0; j<h; j++)
{ {
for (i=0; i<w; i++) for (int i = 0; i < w; i++)
{ {
r = *(data++)&0xFF; auto rgba = *(data++);
g = *(data++)&0xFF; auto a = (rgba >> 24) & 0xFF;
b = *(data++)&0xFF; auto r = (rgba >> 16) & 0xFF;
a = *(data++)&0xFF; auto g = (rgba >> 8) & 0xFF;
auto b = (rgba ) & 0xFF;
addpixel(x+i, y+j, r, g, b, (int)(a*alpha)); addpixel(x+i, y+j, r, g, b, (int)(a*alpha));
} }
} }
} }
pixel *Graphics::render_packed_rgb(void *image, int width, int height, int cmp_size)
{
unsigned char *tmp;
pixel *res;
int i;
tmp = (unsigned char *)malloc(width*height*3);
if (!tmp)
return NULL;
res = (pixel *)malloc(width*height*PIXELSIZE);
if (!res)
{
free(tmp);
return NULL;
}
i = width*height*3;
if (BZ2_bzBuffToBuffDecompress((char *)tmp, (unsigned *)&i, (char *)image, cmp_size, 0, 0))
{
free(res);
free(tmp);
return NULL;
}
for (i=0; i<width*height; i++)
res[i] = PIXRGB(tmp[3*i], tmp[3*i+1], tmp[3*i+2]);
free(tmp);
return res;
}
VideoBuffer Graphics::DumpFrame() VideoBuffer Graphics::DumpFrame()
{ {
VideoBuffer newBuffer(WINDOWW, WINDOWH); VideoBuffer newBuffer(WINDOWW, WINDOWH);

View File

@ -86,8 +86,6 @@ public:
//PTIF methods //PTIF methods
static pixel *resample_img_nn(pixel *src, int sw, int sh, int rw, int rh); static pixel *resample_img_nn(pixel *src, int sw, int sh, int rw, int rh);
static pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh); static pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh);
static pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f);
static pixel *render_packed_rgb(void *image, int width, int height, int cmp_size);
//Font/text metrics //Font/text metrics
static int CharWidth(String::value_type c); static int CharWidth(String::value_type c);
@ -125,7 +123,7 @@ public:
void draw_image(const pixel *img, int x, int y, int w, int h, int a); void draw_image(const pixel *img, int x, int y, int w, int h, int a);
void draw_image(const VideoBuffer * vidBuf, int x, int y, int a); void draw_image(const VideoBuffer * vidBuf, int x, int y, int a);
void draw_rgba_image(const unsigned char *data, int x, int y, float alpha); void draw_rgba_image(const pixel *data, int w, int h, int x, int y, float alpha);
Graphics(); Graphics();
~Graphics(); ~Graphics();

View File

@ -1,7 +1,5 @@
#include "LocalSaveActivity.h" #include "LocalSaveActivity.h"
#include "images.h"
#include "client/Client.h" #include "client/Client.h"
#include "client/GameSave.h" #include "client/GameSave.h"
#include "client/ThumbnailRendererTask.h" #include "client/ThumbnailRendererTask.h"
@ -15,12 +13,16 @@
#include "gui/interface/Label.h" #include "gui/interface/Label.h"
#include "gui/interface/Textbox.h" #include "gui/interface/Textbox.h"
#include "save_local.png.h"
LocalSaveActivity::LocalSaveActivity(SaveFile save, OnSaved onSaved_) : LocalSaveActivity::LocalSaveActivity(SaveFile save, OnSaved onSaved_) :
WindowActivity(ui::Point(-1, -1), ui::Point(220, 200)), WindowActivity(ui::Point(-1, -1), ui::Point(220, 200)),
save(save), save(save),
thumbnailRenderer(nullptr), thumbnailRenderer(nullptr),
onSaved(onSaved_) onSaved(onSaved_)
{ {
PngDataToPixels(save_to_disk_image, save_to_disk_imageW, save_to_disk_imageH, reinterpret_cast<const char *>(save_local_png), save_local_png_size, false);
ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), "Save to computer:"); ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), "Save to computer:");
titleLabel->SetTextColour(style::Colour::InformationTitle); titleLabel->SetTextColour(style::Colour::InformationTitle);
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
@ -131,7 +133,7 @@ void LocalSaveActivity::saveWrite(ByteString finalFilename)
void LocalSaveActivity::OnDraw() void LocalSaveActivity::OnDraw()
{ {
Graphics * g = GetGraphics(); Graphics * g = GetGraphics();
g->draw_rgba_image(save_to_disk_image, 0, 0, 0.7f); g->draw_rgba_image(&save_to_disk_image[0], save_to_disk_imageW, save_to_disk_imageH, 0, 0, 0.7f);
g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3); g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);

View File

@ -2,9 +2,11 @@
#include "Activity.h" #include "Activity.h"
#include "client/SaveFile.h" #include "client/SaveFile.h"
#include "graphics/Pixel.h"
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <vector>
namespace ui namespace ui
{ {
@ -18,6 +20,8 @@ class ThumbnailRendererTask;
class LocalSaveActivity: public WindowActivity class LocalSaveActivity: public WindowActivity
{ {
using OnSaved = std::function<void (SaveFile *)>; using OnSaved = std::function<void (SaveFile *)>;
std::vector<pixel> save_to_disk_image;
int save_to_disk_imageW, save_to_disk_imageH;
SaveFile save; SaveFile save;
ThumbnailRendererTask *thumbnailRenderer; ThumbnailRendererTask *thumbnailRenderer;

View File

@ -19,7 +19,7 @@
#include "gui/Style.h" #include "gui/Style.h"
#include "images.h" #include "save_online.png.h"
class SaveUploadTask: public Task class SaveUploadTask: public Task
{ {
@ -61,6 +61,8 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, OnUploaded onUploaded_) :
onUploaded(onUploaded_), onUploaded(onUploaded_),
saveUploadTask(NULL) saveUploadTask(NULL)
{ {
PngDataToPixels(save_to_server_image, save_to_server_imageW, save_to_server_imageH, reinterpret_cast<const char *>(save_online_png), save_online_png_size, false);
titleLabel = new ui::Label(ui::Point(4, 5), ui::Point((Size.X/2)-8, 16), ""); titleLabel = new ui::Label(ui::Point(4, 5), ui::Point((Size.X/2)-8, 16), "");
titleLabel->SetTextColour(style::Colour::InformationTitle); titleLabel->SetTextColour(style::Colour::InformationTitle);
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
@ -157,6 +159,8 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, OnUploaded o
onUploaded(onUploaded_), onUploaded(onUploaded_),
saveUploadTask(NULL) saveUploadTask(NULL)
{ {
PngDataToPixels(save_to_server_image, save_to_server_imageW, save_to_server_imageH, reinterpret_cast<const char *>(save_online_png), save_online_png_size, false);
ui::Label * titleLabel = new ui::Label(ui::Point(0, 0), Size, "Saving to server..."); ui::Label * titleLabel = new ui::Label(ui::Point(0, 0), Size, "Saving to server...");
titleLabel->SetTextColour(style::Colour::InformationTitle); titleLabel->SetTextColour(style::Colour::InformationTitle);
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
@ -370,7 +374,7 @@ void ServerSaveActivity::OnTick(float dt)
void ServerSaveActivity::OnDraw() void ServerSaveActivity::OnDraw()
{ {
Graphics * g = GetGraphics(); Graphics * g = GetGraphics();
g->draw_rgba_image(save_to_server_image, -10, 0, 0.7f); g->draw_rgba_image(&save_to_server_image[0], save_to_server_imageW, save_to_server_imageH, -10, 0, 0.7f);
g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3); g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255); g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);

View File

@ -3,9 +3,11 @@
#include "Activity.h" #include "Activity.h"
#include "client/SaveInfo.h" #include "client/SaveInfo.h"
#include "tasks/TaskListener.h" #include "tasks/TaskListener.h"
#include "graphics/Pixel.h"
#include <memory> #include <memory>
#include <functional> #include <functional>
#include <vector>
namespace ui namespace ui
{ {
@ -20,7 +22,8 @@ class VideoBuffer;
class ServerSaveActivity: public WindowActivity, public TaskListener class ServerSaveActivity: public WindowActivity, public TaskListener
{ {
using OnUploaded = std::function<void (SaveInfo &)>; using OnUploaded = std::function<void (SaveInfo &)>;
std::vector<pixel> save_to_server_image;
int save_to_server_imageW, save_to_server_imageH;
public: public:
ServerSaveActivity(SaveInfo save, OnUploaded onUploaded); ServerSaveActivity(SaveInfo save, OnUploaded onUploaded);