summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/png.c
blob: 809de6a95aa03e34dc10f9928644e157f5061be2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/** \file png.c
 * PNG creation 
 */

/*  XTrackCad - Model Railroad CAD
 *  Copyright (C) 2015 Martin Fischer
 *
 *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#define GTK_DISABLE_SINGLE_INCLUDES
#define GDK_DISABLE_DEPRECATED
#define GTK_DISABLE_DEPRECATED
#define GSEAL_ENABLE

#include <gtk/gtk.h>
#include "gtkint.h"

#define BITMAPFILEFORMAT "png"

/**
* Export as bitmap file.
*
* \param d IN the drawing area ?
* \param fileName IN  fully qualified filename for the bitmap file.
* \return    TRUE on success, FALSE on error
*/

wBool_t wBitMapWriteFile(wDraw_p d, const char * fileName)
{
    GdkPixbuf *pixbuf;
    GError *error;
    gboolean res;
    pixbuf = gdk_pixbuf_get_from_drawable(NULL, (GdkWindow*)d->pixmap, NULL, 0, 0,
                                          0, 0, d->w, d->h);

    if (!pixbuf) {
        wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_get failed", "Ok", NULL);
        return FALSE;
    }

    error = NULL;
    res = gdk_pixbuf_save(pixbuf, fileName, BITMAPFILEFORMAT, &error, NULL);

    if (res == FALSE) {
        wNoticeEx(NT_ERROR, "WriteBitMap: pixbuf_save failed", "Ok", NULL);
        return FALSE;
    }

    g_object_ref_sink(pixbuf);
    g_object_unref(pixbuf);
    return TRUE;
}