Skip to content

Commit

Permalink
Support export png with no transparent background
Browse files Browse the repository at this point in the history
The whole export code will need to be improved.  I don't think we should
store export option in the image structure!
  • Loading branch information
guillaumechereau committed Jun 2, 2019
1 parent 0bf0a79 commit 1c26305
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/formats/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
static void export_as_png(const char *path, int w, int h)
{
uint8_t *buf;
int bpp = goxel.image->export_transparent_background ? 4 : 3;
w = w ?: goxel.image->export_width;
h = h ?: goxel.image->export_height;
path = path ?: noc_file_dialog_open(NOC_FILE_DIALOG_SAVE,
"png\0*.png\0", NULL, "untitled.png");
if (!path) return;
LOG_I("Exporting to file %s", path);
buf = calloc(w * h, 4);
goxel_render_to_buf(buf, w, h, 4);
img_write(buf, w, h, 4, path);
buf = calloc(w * h, bpp);
goxel_render_to_buf(buf, w, h, bpp);
img_write(buf, w, h, bpp, path);
free(buf);
}

Expand All @@ -54,6 +55,10 @@ static void export_gui(void) {
goxel.image->export_height = view_rect[3];
}
gui_group_end();

gui_checkbox("Transparent background",
&goxel.image->export_transparent_background,
NULL);
}

ACTION_REGISTER(export_as_png,
Expand Down
1 change: 1 addition & 0 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct image {
float box[4][4];

// For saving.
// XXX: I think those should be persistend data of export code instead.
char *path;
int export_width;
int export_height;
Expand Down

0 comments on commit 1c26305

Please sign in to comment.