1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
\r
2 /* GdkPixbuf library - Win32 GDI+ Pixbuf Loader
\r
4 * Copyright (C) 2008 Dominic Lachowicz
\r
5 * Copyright (C) 2008 Alberto Ruiz
\r
7 * Authors: Dominic Lachowicz <domlachowicz@gmail.com>
\r
8 * Alberto Ruiz <aruiz@gnome.org>
\r
10 * This library is free software; you can redistribute it and/or
\r
11 * modify it under the terms of the GNU Lesser General Public
\r
12 * License as published by the Free Software Foundation; either
\r
13 * version 2 of the License, or (at your option) any later version.
\r
15 * This library is distributed in the hope that it will be useful,
\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
18 * Lesser General Public License for more * You should have received a copy of the GNU Lesser General Public
\r
19 * License along with this library; if not, write to the
\r
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
\r
21 * Boston, MA 02111-1307, USA.
\r
25 #include "io-gdip-utils.h"
\r
27 DEFINE_GUID(EncoderCompression, 0xe09d739d,0xccd4,0x44ee,0x8e,0xba,0x3f,0xbf,0x8b,0xe4,0xfc,0x58);
\r
30 gdk_pixbuf__gdip_image_save_PNG_to_callback (GdkPixbufSaveFunc save_func,
\r
37 EncoderParameters encoder_params;
\r
38 LONG compression = 5;
\r
40 if (keys && *keys) {
\r
41 gchar **kiter = keys;
\r
42 gchar **viter = values;
\r
45 if (strncmp (*kiter, "tEXt::", 6) == 0) {
\r
46 /* TODO: support exif data and the like */
\r
48 else if (strcmp (*kiter, "compression") == 0) {
\r
49 char *endptr = NULL;
\r
50 compression = strtol (*viter, &endptr, 10);
\r
52 if (endptr == *viter) {
\r
55 GDK_PIXBUF_ERROR_BAD_OPTION,
\r
56 _("PNG compression level must be a value between 0 and 9; value '%s' could not be parsed."),
\r
60 if (compression < 0 || compression > 9) {
\r
61 /* This is a user-visible error;
\r
62 * lets people skip the range-checking
\r
67 GDK_PIXBUF_ERROR_BAD_OPTION,
\r
68 _("PNG compression level must be a value between 0 and 9; value '%d' is not allowed."),
\r
73 g_warning ("Unrecognized parameter (%s) passed to PNG saver.", *kiter);
\r
81 encoder_params.Count = 1;
\r
82 encoder_params.Parameter[0].Guid = EncoderCompression;
\r
83 encoder_params.Parameter[0].Type = EncoderParameterValueTypeLong;
\r
84 encoder_params.Parameter[0].NumberOfValues = 1;
\r
85 encoder_params.Parameter[0].Value = &compression;
\r
87 return gdip_save_pixbuf (pixbuf, L"image/png", &encoder_params, save_func, user_data, error);
\r
91 gdk_pixbuf__gdip_image_save_PNG (FILE *f,
\r
97 return gdk_pixbuf__gdip_image_save_PNG_to_callback (gdip_save_to_file_callback, f, pixbuf, keys, values, error);
\r
100 #ifndef INCLUDE_gdip_png
\r
101 #define MODULE_ENTRY(function) G_MODULE_EXPORT void function
\r
103 #define MODULE_ENTRY(function) void _gdk_pixbuf__gdip_png_ ## function
\r
106 MODULE_ENTRY (fill_vtable) (GdkPixbufModule *module)
\r
108 gdip_fill_vtable (module);
\r
110 module->save_to_callback = gdk_pixbuf__gdip_image_save_PNG_to_callback;
\r
111 module->save = gdk_pixbuf__gdip_image_save_PNG; /* for gtk < 2.14, you need to implement both. otherwise gdk-pixbuf-queryloaders fails */
\r
114 MODULE_ENTRY (fill_info) (GdkPixbufFormat *info)
\r
116 static GdkPixbufModulePattern signature[] = {
\r
117 { "\x89PNG\r\n\x1a\x0a", NULL, 100 }, /* PNG */
\r
121 static gchar *mime_types[] = {
\r
126 static gchar *extensions[] = {
\r
131 info->name = "png";
\r
132 info->signature = signature;
\r
133 info->description = _("The PNG image format");
\r
134 info->mime_types = mime_types;
\r
135 info->extensions = extensions;
\r
136 info->flags = GDK_PIXBUF_FORMAT_WRITABLE | GDK_PIXBUF_FORMAT_THREADSAFE;
\r
137 info->license = "LGPL";
\r