8000 Fix image interpolation edges for Agg 2.4. It no longer needs funny · MengranDu/matplotlib@f91469a · GitHub
[go: up one dir, main page]

Skip to content

Commit f91469a

Browse files
committed
Fix image interpolation edges for Agg 2.4. It no longer needs funny
workarounds with memory copies to interpolate the edges of the image correctly. svn path=/branches/transforms/; revision=4568
1 parent 4107850 commit f91469a

File tree

2 files changed

+6
-55
lines changed

2 files changed

+6
-55
lines changed

lib/matplotlib/image.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ def make_image(self, magnification=1.0):
156156
sx = dxintv/self.axes.viewLim.width
157157
sy = dyintv/self.axes.viewLim.height
158158

159-
if im.get_interpolation()!=_image.NEAREST:
160-
im.apply_translation(-1, -1)
161-
162159
# the viewport translation
163160
tx = (xmin-self.axes.viewLim.x0)/dxintv * numcols
164161
ty = (ymin-self.axes.viewLim.y0)/dyintv * numrows
@@ -382,7 +379,7 @@ def set_interpolation(self, s):
382379
if s != None and s != 'nearest':
383380
raise NotImplementedError('Only nearest neighbor supported')
384381
AxesImage.set_interpolation(self, s)
385-
382+
386383
def get_extent(self):
387384
if self._A is None:
388385
raise RuntimeError('Must set data first')

src/_image.cpp

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -379,56 +379,10 @@ Image::resize(const Py::Tuple& args, const Py::Dict& kwargs) {
379379

380380
double x0, y0, x1, y1;
381381

382-
if (interpolation==NEAREST) {
383-
x0 = 0.0;
384-
x1 = colsIn;
385-
y0 = 0.0;
386-
y1 = rowsIn;
387-
}
388-
else {
389-
// if interpolation != nearest, create a new input buffer with the
390-
// edges mirrored on all size. Then new buffer size is colsIn+2 by
391-
// rowsIn+2
392-
393-
x0 = 1.0;
394-
x1 = colsIn+1;
395-
y0 = 1.0;
396-
y1 = rowsIn+1;
397-
398-
399-
bufferPad = new agg::int8u[(rowsIn+2) * (colsIn+2) * BPP];
400-
if (bufferPad ==NULL)
401-
throw Py::MemoryError("Image::resize could not allocate memory");
402-
rbufPad.attach(bufferPad, colsIn+2, rowsIn+2, (colsIn+2) * BPP);
403-
404-
pixfmt pixfpad(rbufPad);
405-
renderer_base rbpad(pixfpad);
406-
407-
pixfmt pixfin(*rbufIn);
408-
renderer_base rbin(pixfin);
409-
410-
rbpad.copy_from(*rbufIn, 0, 1, 1);
411-
412-
agg::rect_base<int> firstrow(0, 0, colsIn-1, 0);
413-
rbpad.copy_from(*rbufIn, &firstrow, 1, 0);
414-
415-
agg::rect_base<int> lastrow(0, rowsIn-1, colsIn-1, rowsIn-1);
416-
rbpad.copy_from(*rbufIn, &lastrow, 1, 2);
417-
418-
agg::rect_base<int> firstcol(0, 0, 0, rowsIn-1);
419-
rbpad.copy_from(*rbufIn, &firstcol, 0, 1);
420-
421-
agg::rect_base<int> lastcol(colsIn-1, 0, colsIn-1, rowsIn-1);
422-
rbpad.copy_from(*rbufIn, &lastcol, 2, 1);
423-
424-
rbpad.copy_pixel(0, 0, rbin.pixel(0,0) );
425-
rbpad.copy_pixel(0, colsIn+1, rbin.pixel(0,colsIn-1) );
426-
rbpad.copy_pixel(rowsIn+1, 0, rbin.pixel(rowsIn-1,0) );
427-
rbpad.copy_pixel(rowsIn+1, colsIn+1, rbin.pixel(rowsIn-1,colsIn-1) );
428-
429-
430-
}
431-
382+
x0 = 0.0;
383+
x1 = colsIn;
384+
y0 = 0.0;
385+
y1 = rowsIn;
432386

433387
path.move_to(x0, y0);
434388
path.line_to(x1, y0);
@@ -439,7 +393,7 @@ Image::resize(const Py::Tuple& args, const Py::Dict& kwargs) {
439393
ras.add_path(imageBox);
440394

441395
typedef agg::image_accessor_clip<pixfmt> img_accessor_type;
442-
396+
443397
pixfmt pixfmtin(*rbufIn);
444398
img_accessor_type ia(pixfmtin, background);
445399
switch(interpolation)

0 commit comments

Comments
 (0)
0