add PIL_mode_from_vips () and vips_from_PIL_mode () utility functions
This commit is contained in:
parent
6e2afe75c7
commit
48a5e364e2
|
@ -21,6 +21,7 @@
|
||||||
- revise i18n configure, get rid of intltool
|
- revise i18n configure, get rid of intltool
|
||||||
- command-line IMAGVEC input could segv with non-vips image output
|
- command-line IMAGVEC input could segv with non-vips image output
|
||||||
- added .tobuffer()/.frombuffer(), .tostring()/.fromstring() to Python binding
|
- added .tobuffer()/.frombuffer(), .tostring()/.fromstring() to Python binding
|
||||||
|
- add PIL_mode_from_vips () and vips_from_PIL_mode () utility functions
|
||||||
|
|
||||||
25/1/08 started 7.14.0
|
25/1/08 started 7.14.0
|
||||||
- bump all version numbers for new stable
|
- bump all version numbers for new stable
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* 3/8/08
|
* 3/8/08
|
||||||
* - add .tobuffer() / .frombuffer (), .tostring (), .fromstring ()
|
* - add .tobuffer() / .frombuffer (), .tostring (), .fromstring ()
|
||||||
* methods
|
* methods
|
||||||
|
* - add PIL_mode_from_vips () and vips_from_PIL_mode () utility
|
||||||
|
* functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
%module VImage
|
%module VImage
|
||||||
|
@ -142,6 +144,46 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
%pythoncode %{
|
||||||
|
# try to guess a PIL mode string from a VIPS image
|
||||||
|
def PIL_mode_from_vips (vim):
|
||||||
|
if vim.Bands () == 3 and vim.BandFmt () == VImage.FMTUCHAR:
|
||||||
|
return 'RGB'
|
||||||
|
elif vim.Bands () == 4 and vim.BandFmt () == VImage.FMTUCHAR and vim.Type == VImage.VImage.RGB:
|
||||||
|
return 'RGBA'
|
||||||
|
elif vim.Bands () == 4 and vim.BandFmt () == VImage.FMTUCHAR and vim.Type == VImage.CMYK:
|
||||||
|
return 'CMYK'
|
||||||
|
elif vim.Bands () == 1 and vim.BandFmt () == VImage.FMTUCHAR:
|
||||||
|
return 'L'
|
||||||
|
elif vim.Bands () == 1 and vim.BandFmt () == VImage.FMTINT:
|
||||||
|
return 'I'
|
||||||
|
elif vim.Bands () == 1 and vim.BandFmt () == VImage.FMTFLOAT:
|
||||||
|
return 'F'
|
||||||
|
elif vim.Bands () == 2 and vim.BandFmt () == VImage.FMTUCHAR:
|
||||||
|
return 'LA'
|
||||||
|
else:
|
||||||
|
raise ValueError ('unsupported vips -> pil image')
|
||||||
|
|
||||||
|
# return vips (bands, format, type) for a PIL mode
|
||||||
|
def vips_from_PIL_mode (mode):
|
||||||
|
if mode == 'RGB':
|
||||||
|
return (3, VImage.FMTUCHAR, VImage.RGB)
|
||||||
|
elif mode == 'RGBA':
|
||||||
|
return (4, VImage.FMTUCHAR, VImage.RGB)
|
||||||
|
elif mode == 'CMYK':
|
||||||
|
return (4, VImage.FMTUCHAR, VImage.CMYK)
|
||||||
|
elif mode == 'L':
|
||||||
|
return (1, VImage.FMTUCHAR, VImage.B_W)
|
||||||
|
elif mode == 'I':
|
||||||
|
return (1, VImage.FMTINT, VImage.B_W)
|
||||||
|
elif mode == 'F':
|
||||||
|
return (1, VImage.FMTFLOAT, VImage.B_W)
|
||||||
|
elif mode == 'LA':
|
||||||
|
return (2, VImage.FMTUCHAR, VImage.B_W)
|
||||||
|
else:
|
||||||
|
raise ValueError ('unsupported pil -> vips image')
|
||||||
|
%}
|
||||||
|
|
||||||
/* Helper code for vips_init().
|
/* Helper code for vips_init().
|
||||||
*/
|
*/
|
||||||
%{
|
%{
|
||||||
|
@ -211,14 +253,13 @@ args_new (void)
|
||||||
if (!PyList_Check (av)) {
|
if (!PyList_Check (av)) {
|
||||||
PyErr_Warn (PyExc_Warning, "ignoring sys.argv: "
|
PyErr_Warn (PyExc_Warning, "ignoring sys.argv: "
|
||||||
"it must be a list of strings");
|
"it must be a list of strings");
|
||||||
return (args);
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
n = PyList_Size (av);
|
n = PyList_Size (av);
|
||||||
args->str = g_new (char *, n);
|
args->str = g_new (char *, n);
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
args->str[i] = g_strdup
|
args->str[i] = g_strdup (PyString_AsString (PyList_GetItem (av, i)));
|
||||||
(PyString_AsString (PyList_GetItem (av, i)));
|
|
||||||
args->n = n;
|
args->n = n;
|
||||||
|
|
||||||
/* +1 for NULL termination.
|
/* +1 for NULL termination.
|
||||||
|
@ -229,7 +270,7 @@ args_new (void)
|
||||||
args->argv[i] = args->str[i];
|
args->argv[i] = args->str[i];
|
||||||
args->argv[i] = NULL;
|
args->argv[i] = NULL;
|
||||||
|
|
||||||
return (args);
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -269,7 +310,7 @@ vips_fatal (const char *msg)
|
||||||
g_option_context_add_group (context, im_get_option_group());
|
g_option_context_add_group (context, im_get_option_group());
|
||||||
|
|
||||||
g_option_context_set_ignore_unknown_options (context, TRUE);
|
g_option_context_set_ignore_unknown_options (context, TRUE);
|
||||||
if( !g_option_context_parse (context,
|
if (!g_option_context_parse (context,
|
||||||
&args->argc, &args->argv, &error)) {
|
&args->argc, &args->argv, &error)) {
|
||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
args_free (args);
|
args_free (args);
|
||||||
|
|
Loading…
Reference in New Issue