# coding: utf-8

from __future__ import print_function, unicode_literals, absolute_import

from PIL import Image

from .base import BaseTestCase



class ResizeCase(BaseTestCase):
    filter_ids = {
        0: 'ner', 1: 'lzs', 2: 'bil', 3: 'bic',
        4: 'box', 5: 'hmn', 6: 'mtc',
    }

    def create_test_data(self, size, mode):
        return [Image.new(mode, size)]

    def runner(self, size, filter, im):
        size = list(size)
        if not self.kwargs.get('hpass', True):
            size[0] = im.size[0]
        if not self.kwargs.get('vpass', True):
            size[1] = im.size[1]
        return self.resize(im, size, filter)

    def readable_args(self):
        size = list(self.args[0])
        if not self.kwargs.get('hpass', True):
            size[0] = ""
        if not self.kwargs.get('vpass', True):
            size[1] = ""
        return [
            "x".join(map(str, size)),
            self.filter_ids.get(self.args[1]),
        ]

    @classmethod
    def resize(cls, self, size, resample=Image.NEAREST):
        self.load()

        if self.size == size:
            return self._new(self.im)

        if self.mode in ("1", "P"):
            resample = Image.NEAREST

        if self.mode == 'RGBA':
            return cls.resize(self.convert('RGBa'), size, resample).convert('RGBA')

        if self.mode == 'LA':
            return cls.resize(self.convert('La'), size, resample).convert('LA')

        if resample == Image.NEAREST:
            im = self.im.resize(size, resample)
        else:
            im = self.im.stretch(size, resample)

        return self._new(im)

    @property
    def desc(self):
        flt = _filters.get(self.args[1], self.args[1])
        add = ''
        if self.kwargs.get('hpass', True):
            add += 'h'
        if self.kwargs.get('vpass', True):
            add += 'v'
        return "{size[0]}x{size[1]}{add} {flt}".format(
            size=self.args[0], add=add, flt=flt)


cases = [
    ResizeCase(size, flt, hpass=hpass, vpass=vpass)
    for hpass, vpass in [
        # (True, False),
        # (False, True),
        (True, True),
    ] for size in [
        (16, 16),
        (320, 180),
        (1920, 1200),
        (7712, 4352),
    ] for flt in [
        # Image.NEAREST,
        # Image.BOX,
        Image.BILINEAR,
        # Image.HAMMING,
        Image.BICUBIC,
        Image.LANCZOS,
    ]
]

@@ -1611,352 +1611,8 @@
 m)%0A%0A
-    @property%0A    def desc(self):%0A        flt = _filters.get(self.args%5B1%5D, self.args%5B1%5D)%0A        add = ''%0A        if self.kwargs.get('hpass', True):%0A            add += 'h'%0A        if self.kwargs.get('vpass', True):%0A            add += 'v'%0A        return %22%7Bsize%5B0%5D%7Dx%7Bsize%5B1%5D%7D%7Badd%7D %7Bflt%7D%22.format(%0A            size=self.args%5B0%5D, add=add, flt=flt)%0A%0A
 %0Acas

remove obsolete method