Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not use temporarily an XPF file when saving/loading from a PNG #180

Merged
merged 1 commit into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/include/misc-f.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "config.h"
struct image;

const char *writepng(xio_constpath filename, const struct image *image);
const char *readpng(xio_constpath filename);
const char *writepng(xio_constpath filename, const struct image *image, xio_file xpf_data);
const char* readpng(xio_constpath filename);
void XaoS_srandom(unsigned int x);
long int XaoS_random(void);
char *mystrdup(const char *);
Expand Down
2 changes: 1 addition & 1 deletion src/include/ui_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ void uih_autopilot_off(uih_context *c);

/*misc functions */
int uih_update(uih_context *c, int mousex, int mousey, int mousebuttons);
const char *uih_save(struct uih_context *c, xio_constpath filename);
const char *uih_save(struct uih_context *c, xio_constpath filename, xio_file xpf_data);
void uih_tbreak(uih_context *c);
double uih_displayed(uih_context *c);
void uih_do_fractal(uih_context *c);
Expand Down
2 changes: 1 addition & 1 deletion src/ui-hlp/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ int uih_renderanimation(struct uih_context *gc1, const char *basename,
curframe.angle = uih->fcontext->angle;
curframe.name = s;
curframe.newimage = newimage;
writepng(s, uih->image);
writepng(s, uih->image, NULL);
uih_displayed(uih);
lastframenum = framenum;
} else {
Expand Down
26 changes: 9 additions & 17 deletions src/ui-hlp/ui_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,17 +628,13 @@ void uih_loadpngfile(struct uih_context *c, xio_constpath d)
uih_error(c, strerror(errno));
return;
}
const char *s = readpng(d);
if(s != NULL) {
const char* xpf_chunk = readpng(d);
if(xpf_chunk == NULL) {
uih_error(c, TR("Error", "Could not open image"));
return;
}
int pathlength = strlen(d) + 16;
static char* filepath;
filepath = (char* )malloc(pathlength * sizeof (char));
strcpy(filepath, xio_getdirectory(d));
strcat(filepath, ".xaos_temp.xpf");
uih_loadfile(c, filepath);
xio_file xpf_data = xio_strropen(xpf_chunk);
uih_load(c, xpf_data, d);
if(c->errstring == NULL) {
char s[256];
sprintf(s, TR("Message", "File %s loaded."), d);
Expand All @@ -663,13 +659,9 @@ void uih_savepngfile(struct uih_context *c, xio_constpath d)
return;
}
c->errstring = NULL;
int pathlength = strlen(d) + 16;
static char* filepath;
filepath = (char* )malloc(pathlength * sizeof (char));
strcpy(filepath, xio_getdirectory(d));
strcat(filepath, ".xaos_temp.xpf");
uih_saveposfile(c, filepath);
s = uih_save(c, d);
xio_file xpf_data = xio_strwopen();
uih_save_position(c, xpf_data, UIH_SAVEPOS);
s = uih_save(c, d, xpf_data);
if (s != NULL)
uih_error(c, s);
if (c->errstring == NULL) {
Expand Down Expand Up @@ -786,13 +778,13 @@ void uih_saveanimfile(struct uih_context *c, xio_constpath d)
uih_updatemenus(c, "record");
}

const char *uih_save(struct uih_context *c, xio_constpath filename)
const char *uih_save(struct uih_context *c, xio_constpath filename, xio_file xpf_data)
{
const char *r;
uih_cycling_stop(c);
uih_stoptimers(c);
uih_clearwindows(c);
r = writepng(filename, c->queue->saveimage);
r = writepng(filename, c->queue->saveimage, xpf_data);
uih_cycling_continue(c);
uih_resumetimers(c);
return (r);
Expand Down
47 changes: 10 additions & 37 deletions src/ui/image_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "filter.h"
#include "grlib.h"
#include "xio.h"
#include "misc-f.h"

static QFont getFont(void *font) {
if (font)
Expand Down Expand Up @@ -62,55 +63,27 @@ int xtextcharw(struct image */*image*/, void *font, const char c)
}

// Saves image as png with xpf chunk data
const char *writepng(xio_constpath filename, const struct image *image)
const char *writepng(xio_constpath filename, const struct image *image, xio_file xpf_data)
{
QImage *qimage = reinterpret_cast<QImage **>(image->data)[image->currimage];
int pathlength = strlen(filename) + 16;
static char* filepath;
filepath = (char* )malloc(pathlength * sizeof (char));
strcpy(filepath, xio_getdirectory(filename));
strcat(filepath, ".xaos_temp.xpf");
QFile f(filepath);
if(!f.open(QFile::ReadOnly |
QFile::Text))
{
qDebug()<<"Could not open the file for reading";
qDebug()<<"Image will be created without xpf data";
if(xpf_data != NULL){
QString xpf_chunk = xio_getstring(xpf_data);
qimage->setText("Metadata", xpf_chunk);
}
QTextStream in(&f);
QString xpf_chunk = in.readAll();
f.close();
f.remove();
qimage->setText("Metadata", xpf_chunk);
qimage->save(filename);
return NULL;
}

// Reads png image and xpf associated data
const char *readpng(xio_constpath filename)
const char* readpng(xio_constpath filename)
{
QImageReader reader(filename);
const QImage xaos_image = reader.read();
QString xpf_chunk = xaos_image.text("Metadata");
if(xpf_chunk.isNull() || xpf_chunk.isEmpty()) {
return "Not valid image";
}
int pathlength = strlen(filename) + 16;
static char* filepath;
filepath = (char* )malloc(pathlength * sizeof (char));
strcpy(filepath, xio_getdirectory(filename));
strcat(filepath, ".xaos_temp.xpf");
QFile f(filepath);
if(!f.open(QFile::WriteOnly |
QFile::Text))
{
qDebug() << " Could not open the file for writing";
return "No file or permission";
}
QTextStream in(&f);
in<<xpf_chunk;
f.close();
return NULL;
const char *xpf_data = NULL;
if(xpf_chunk != NULL or !xpf_chunk.isEmpty())
xpf_data = mystrdup(xpf_chunk.toStdString().c_str());
return xpf_data;
}

static void freeImage(struct image *img)
Expand Down