def convert(self, mode):
        """Convert the current image to the given *mode*. See :class:`Image`
        for a list of available modes.
        """
        if mode == self.mode:
            return

        if mode not in ["L", "LA", "RGB", "RGBA",
                        "YCbCr", "YCbCrA", "P", "PA"]:
            raise ValueError("Mode %s not recognized." % (mode))

        if self.is_empty():
            self.mode = mode
            return

        if mode == self.mode + "A":
            self.channels.append(np.ma.ones(self.channels[0].shape))
            if self.fill_value is not None:
                self.fill_value += [1]
            self.mode = mode

        elif mode + "A" == self.mode:
            self.channels = self.channels[:-1]
            if self.fill_value is not None:
                self.fill_value = self.fill_value[:-1]
            self.mode = mode

        elif mode.endswith("A") and not self.mode.endswith("A"):
            self.convert(self.mode + "A")
            self.convert(mode)

        elif self.mode.endswith("A") and not mode.endswith("A"):
            self.convert(self.mode[:-1])
            self.convert(mode)

        else:
            cases = {
                "RGB": {"YCbCr": self._rgb2ycbcr,
                        "L": self._rgb2l,
                        "P": self._to_p},
                "RGBA": {"YCbCrA": self._rgb2ycbcr,
                         "LA": self._rgb2l,
                         "PA": self._to_p},
                "YCbCr": {"RGB": self._ycbcr2rgb,
                          "L": self._ycbcr2l,
                          "P": self._to_p},
                "YCbCrA": {"RGBA": self._ycbcr2rgb,
                           "LA": self._ycbcr2l,
                           "PA": self._to_p},
                "L": {"RGB": self._l2rgb,
                      "YCbCr": self._l2ycbcr,
                      "P": self._to_p},
                "LA": {"RGBA": self._l2rgb,
                       "YCbCrA": self._l2ycbcr,
                       "PA": self._to_p},
                "P": {"RGB": self._from_p,
                      "YCbCr": self._from_p,
                      "L": self._from_p},
                "PA": {"RGBA": self._from_p,
                       "YCbCrA": self._from_p,
                       "LA": self._from_p}}
            try:
                cases[self.mode][mode](mode)
            except KeyError:
                raise ValueError("Conversion from %s to %s not implemented !"
                                 % (self.mode, mode))
def convert ( self , mode ) : if mode == self . mode : return if mode not in [ "L" , "LA" , "RGB" , "RGBA" , "YCbCr" , "YCbCrA" , "P" , "PA" ] : raise ValueError ( "Mode %s not recognized." % ( mode ) ) if self . is_empty ( ) : self . mode = mode return if mode == self . mode + "A" : self . channels . append ( np . ma . ones ( self . channels [ 0 ] . shape ) ) if self . fill_value is not None : self . fill_value += [ 1 ] self . mode = mode elif mode + "A" == self . mode : self . channels = self . channels [ : - 1 ] if self . fill_value is not None : self . fill_value = self . fill_value [ : - 1 ] self . mode = mode elif mode . endswith ( "A" ) and not self . mode . endswith ( "A" ) : self . convert ( self . mode + "A" ) self . convert ( mode ) elif self . mode . endswith ( "A" ) and not mode . endswith ( "A" ) : self . convert ( self . mode [ : - 1 ] ) self . convert ( mode ) else : cases = { "RGB" : { "YCbCr" : self . _rgb2ycbcr , "L" : self . _rgb2l , "P" : self . _to_p } , "RGBA" : { "YCbCrA" : self . _rgb2ycbcr , "LA" : self . _rgb2l , "PA" : self . _to_p } , "YCbCr" : { "RGB" : self . _ycbcr2rgb , "L" : self . _ycbcr2l , "P" : self . _to_p } , "YCbCrA" : { "RGBA" : self . _ycbcr2rgb , "LA" : self . _ycbcr2l , "PA" : self . _to_p } , "L" : { "RGB" : self . _l2rgb , "YCbCr" : self . _l2ycbcr , "P" : self . _to_p } , "LA" : { "RGBA" : self . _l2rgb , "YCbCrA" : self . _l2ycbcr , "PA" : self . _to_p } , "P" : { "RGB" : self . _from_p , "YCbCr" : self . _from_p , "L" : self . _from_p } , "PA" : { "RGBA" : self . _from_p , "YCbCrA" : self . _from_p , "LA" : self . _from_p } } try : cases [ self . mode ] [ mode ] ( mode ) except KeyError : raise ValueError ( "Conversion from %s to %s not implemented !" % ( self . mode , mode ) )
Convert the current image to the given *mode*. See :class:`Image`
        for a list of available modes.