Skip to content

Commit

Permalink
Merge pull request #166 from kanurag94/png-xpf
Browse files Browse the repository at this point in the history
Save xpf data in png chunk
  • Loading branch information
kovzol authored Jun 13, 2020
2 parents 2e84065 + 1f562d5 commit 7db4ab3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/include/misc-f.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
struct image;

const char *writepng(xio_constpath filename, const struct image *image);
const char *readpng(xio_constpath filename);
void XaoS_srandom(unsigned int x);
long int XaoS_random(void);
char *mystrdup(const char *);
Expand Down
1 change: 1 addition & 0 deletions src/include/ui_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ void uih_playtutorial(struct uih_context *c, const char *name);
void uih_loadfile(struct uih_context *uih, xio_constpath d);
void uih_playfile(struct uih_context *c, xio_constpath d);
void uih_loadexample(struct uih_context *c);
void uih_loadpngfile(struct uih_context *c, xio_constpath d);
void uih_savepngfile(struct uih_context *c, xio_constpath d);
void uih_saveposfile(struct uih_context *c, xio_constpath d);
char *uih_savepostostr(struct uih_context *c);
Expand Down
10 changes: 8 additions & 2 deletions src/ui-hlp/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const char *const uih_colornames[] = {"white", "black", "red", NULL};
* Zoltan Kovacs <[email protected]>, 2003-01-05
*/

#define MAX_MENUDIALOGS_I18N 100
#define MAX_MENUDIALOGS_I18N 102
#define Register(variable) variable = &menudialogs_i18n[no_menudialogs_i18n]
static menudialog menudialogs_i18n[MAX_MENUDIALOGS_I18N];
// static int no_menudialogs_i18n;
Expand All @@ -76,7 +76,7 @@ static menudialog *uih_perturbationdialog, *uih_juliadialog,
*uih_filterdialog, *uih_shiftdialog, *uih_speeddialog, *printdialog,
*uih_bailoutdialog, *uih_threaddialog, *saveanimdialog, *uih_juliamodedialog,
*uih_textposdialog, *uih_fastmodedialog, *uih_timedialog, *uih_numdialog,
*uih_fpdialog, *palettedialog, *uih_cyclingdialog
*uih_fpdialog, *palettedialog, *uih_cyclingdialog, *loadimgdialog
#ifdef USE_SFFE
,
*uih_sffedialog, *uih_sffeinitdialog
Expand Down Expand Up @@ -172,6 +172,10 @@ void uih_registermenudialogs_i18n(void)
DIALOGIFILE_I(TR("Dialog", "Filename:"), "anim*.xaf");
NULL_I();

Register(loadimgdialog);
DIALOGIFILE_I(TR("Dialog", "Filename:"), "fract*.png");
NULL_I();

Register(saveimgdialog);
DIALOGOFILE_I(TR("Dialog", "Filename:"), "fract*.png");
NULL_I();
Expand Down Expand Up @@ -983,6 +987,8 @@ void uih_registermenus_i18n(void)
MENUFLAG_INTERRUPT | MENUFLAG_NOPLAY, uih_playfile,
playdialog);
MENUSEPARATOR_I("file");
MENUDIALOG_I("file", NULL, TR("Menu", "Open image"), "loadimg",
MENUFLAG_INTERRUPT, uih_loadpngfile, loadimgdialog);
MENUDIALOG_I("file", NULL, TR("Menu", "Save image"), "saveimg", 0,
uih_savepngfile, saveimgdialog);
MENUDIALOG_I("file", NULL, TR("Menu", "Render"), "renderanim", UI,
Expand Down
23 changes: 23 additions & 0 deletions src/ui-hlp/ui_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,28 @@ void uih_loadexample(struct uih_context *c)
}
}

void uih_loadpngfile(struct uih_context *c, xio_constpath d)
{
xio_file f;
f = xio_ropen(d);
if (f == NULL) {
uih_error(c, strerror(errno));
return;
}
const char *s = readpng(d);
if(s != NULL) {
uih_error(c, TR("Error", "Could not open Image"));
return;
}
uih_loadfile(c, ".xaos_temp.xpf");
if(c->errstring == NULL) {
char s[256];
sprintf(s, TR("Message", "File %s loaded."), d);
uih_message(c, s);
}
return;
}

void uih_savepngfile(struct uih_context *c, xio_constpath d)
{
const char *s;
Expand All @@ -636,6 +658,7 @@ void uih_savepngfile(struct uih_context *c, xio_constpath d)
return;
}
c->errstring = NULL;
uih_saveposfile(c, ".xaos_temp.xpf");
s = uih_save(c, d);
if (s != NULL)
uih_error(c, s);
Expand Down
30 changes: 30 additions & 0 deletions src/ui/image_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,43 @@ int xtextcharw(struct image */*image*/, void *font, const char c)
return metrics.width(c);
}

// Saves image as png with xpf chunk data
const char *writepng(xio_constpath filename, const struct image *image)
{
QImage *qimage = reinterpret_cast<QImage **>(image->data)[image->currimage];
QFile f(".xaos_temp.xpf");
if(!f.open(QFile::ReadOnly |
QFile::Text))
{
qDebug()<<"Could not open the file for reading";
}
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)
{
QImageReader reader(filename);
const QImage xaos_image = reader.read();
QString xpf_chunk = xaos_image.text("Metadata");
QFile f(".xaos_temp.xpf");
if(!f.open(QFile::WriteOnly |
QFile::Text))
{
qDebug() << " Could not open the file for writing";
}
QTextStream in(&f);
in<<xpf_chunk;
f.close();
return NULL;
}

static void freeImage(struct image *img)
{
QImage **data = (QImage **)(img->data);
Expand Down

0 comments on commit 7db4ab3

Please sign in to comment.