10000 Fix image_masked.py example · matplotlib/matplotlib@1204436 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1204436

Browse files
committed
Fix image_masked.py example
1 parent eda0912 commit 1204436

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
365365
if A.dtype.kind == 'f':
366366
rgba[..., 3] = ~A.mask
367367
else:
368-
rgba[..., 3] = np.where(A.mask, 0, np.iinfo(np.dtype).max)
368+
rgba[..., 3] = np.where(A.mask, 0, np.iinfo(A.dtype).max)
369369
A = rgba
370370
output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
371371
alpha = 1.0

src/_image_resample.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,35 @@ template <> class type_mapping<agg::rgba8>
533533
};
534534

535535

536+
template <> class type_mapping<agg::rgba16>
537+
{
538+
public:
539+
typedef agg::rgba16 color_type;
540+
typedef fixed_blender_rgba_plain<color_type, agg::order_rgba> blender_type;
541+
typedef fixed_blender_rgba_pre<color_type, agg::order_rgba> pre_blender_type;
542+
typedef agg::pixfmt_alpha_blend_rgba<blender_type, agg::rendering_buffer> pixfmt_type;
543+
typedef agg::pixfmt_alpha_blend_rgba<pre_blender_type, agg::rendering_buffer> pixfmt_pre_type;
544+
545+
template <typename A>
546+
struct span_gen_affine_type
547+
{
548+
typedef agg::span_image_resample_rgba_affine<A> type;
549+
};
550+
551+
template <typename A, typename B>
552+
struct span_gen_filter_type
553+
{
554+
typedef agg::span_image_filter_rgba<A, B> type;
555+
};
556+
557+
template <typename A, typename B>
558+
struct span_gen_nn_type
559+
{
560+
typedef agg::span_image_filter_rgba_nn<A, B> type;
561+
};
562+
};
563+
564+
536565
template <> class type_mapping<agg::rgba32>
537566
{
538567
public:

src/_image_wrapper.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
226226
params);
227227
Py_END_ALLOW_THREADS
228228
break;
229+
case NPY_UINT16:
230+
case NPY_INT16:
231+
Py_BEGIN_ALLOW_THREADS
232+
resample(
233+
(agg::rgba16 *)PyArray_DATA(input_array),
234+
PyArray_DIM(input_array, 1),
235+
PyArray_DIM(input_array, 0),
236+
(agg::rgba16 *)PyArray_DATA(output_array),
237+
PyArray_DIM(output_array, 1),
238+
PyArray_DIM(output_array, 0),
239+
params);
240+
Py_END_ALLOW_THREADS
241+
break;
229242
case NPY_FLOAT32:
230243
Py_BEGIN_ALLOW_THREADS
231244
resample(
@@ -254,13 +267,13 @@ image_resample(PyObject *self, PyObject* args, PyObject *kwargs)
254267
PyErr_SetString(
255268
PyExc_ValueError,
256269
"3-dimensional arrays must be of dtype unsigned byte, "
257-
"float32 or float64");
270+
"unsigned short, float32 or float64");
258271
goto error;
259272
}
260273
} else {
261274
PyErr_Format(
262275
PyExc_ValueError,
263-
"If 3-dimensional, array must be RGBA. Got %d.",
276+
"If 3-dimensional, array must be RGBA. Got %d planes.",
264277
PyArray_DIM(input_array, 2));
265278
goto error;
266279
}

0 commit comments

Comments
 (0)
0