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(EncoderQuality, 0x1d5be4b5,0xfa4a,0x452d,0x9c,0xdd,0x5d,0xb3,0x51,0x05,0xe7,0xeb);
\r
30 gdk_pixbuf__gdip_image_save_JPEG_to_callback (GdkPixbufSaveFunc save_func,
\r
37 EncoderParameters encoder_params;
\r
38 LONG quality = 75; /* default; must be between 0 and 100 */
\r
40 if (keys && *keys) {
\r
41 gchar **kiter = keys;
\r
42 gchar **viter = values;
\r
45 if (strcmp (*kiter, "quality") == 0) {
\r
46 char *endptr = NULL;
\r
47 quality = strtol (*viter, &endptr, 10);
\r
49 if (endptr == *viter) {
\r
52 GDK_PIXBUF_ERROR_BAD_OPTION,
\r
53 _("JPEG quality must be a value between 0 and 100; value '%s' could not be parsed."),
\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 _("JPEG quality must be a value between 0 and 100; value '%d' is not allowed."),
\r
74 g_warning ("Unrecognized parameter (%s) passed to JPEG saver.", *kiter);
\r
82 encoder_params.Count = 1;
\r
83 encoder_params.Parameter[0].Guid = EncoderQuality;
\r
84 encoder_params.Parameter[0].Type = EncoderParameterValueTypeLong;
\r
85 encoder_params.Parameter[0].NumberOfValues = 1;
\r
86 encoder_params.Parameter[0].Value = &quality;
\r
88 return gdip_save_pixbuf (pixbuf, L"image/jpeg", &encoder_params, save_func, user_data, error);
\r
92 gdk_pixbuf__gdip_image_save_JPEG (FILE *f,
\r
98 return gdk_pixbuf__gdip_image_save_JPEG_to_callback (gdip_save_to_file_callback, f, pixbuf, keys, values, error);
\r
101 #ifndef INCLUDE_gdiplus
\r
102 #define MODULE_ENTRY(function) G_MODULE_EXPORT void function
\r
104 #define MODULE_ENTRY(function) void _gdk_pixbuf__gdip_jpeg_ ## function
\r
107 MODULE_ENTRY (fill_vtable) (GdkPixbufModule *module)
\r
109 gdip_fill_vtable (module);
\r
111 module->save_to_callback = gdk_pixbuf__gdip_image_save_JPEG_to_callback;
\r
112 module->save = gdk_pixbuf__gdip_image_save_JPEG; /* for gtk < 2.14, you need to implement both. otherwise gdk-pixbuf-queryloaders fails */
\r
115 MODULE_ENTRY (fill_info) (GdkPixbufFormat *info)
\r
117 static GdkPixbufModulePattern signature[] = {
\r
118 { "\xff\xd8", NULL, 100 }, /* JPEG */
\r
122 static gchar *mime_types[] = {
\r
127 static gchar *extensions[] = {
\r
134 info->name = "jpeg";
\r
135 info->signature = signature;
\r
136 info->description = _("The JPEG image format");
\r
137 info->mime_types = mime_types;
\r
138 info->extensions = extensions;
\r
139 info->flags = GDK_PIXBUF_FORMAT_WRITABLE | GDK_PIXBUF_FORMAT_THREADSAFE;
\r
140 info->license = "LGPL";
\r