def call(self, function, args, output_args, limit_choices=None): if function.image_types_must_match and limit_choices is not None: choices = self._get_choices_for_pixel_type(limit_choices) else: choices = self._get_choices() result = "switch(get_image_combination(%(pysymbol)s)) {\n" % self for choice, pixel_type in choices: result += "case %s:\n" % choice.upper() new_output_args = output_args + ["*((%s*)%s)" % (choice, self.symbol)] if len(args) == 0: result += self._do_call(function, new_output_args) else: if limit_choices is None: result += args[0].call(function, args[1:], new_output_args, pixel_type) else: result += args[0].call(function, args[1:], new_output_args, limit_choices) result += "break;\n" result += "default:\n" acceptable_types = [util.get_pixel_type_name(y).upper() for x, y in choices] if len(acceptable_types) >= 2: phrase = "values are" acceptable_types[-1] = "and " + acceptable_types[-1] else: phrase = "value is" acceptable_types = ", ".join(acceptable_types) result += ('PyErr_Format(PyExc_TypeError,' '"The \'%s\' argument of \'%s\' can not have pixel type \'%%s\'. ' 'Acceptable %s %s."' ', get_pixel_type_name(%s));\nreturn 0;\n' % (self.name, function.__name__, phrase, acceptable_types, self.pysymbol)) result += "}\n" return result
def _get_choices_for_pixel_type(self, pixel_type): if pixel_type == ONEBIT: result = [ "OneBitImageView", "Cc", "OneBitRleImageView", "RleCc", "MlCc" ] else: result = [util.get_pixel_type_name(pixel_type) + "ImageView"] return [(x, pixel_type) for x in result]
def rest_repr(self, name=False): result = '``Image`` [%s]' % '|'.join([util.get_pixel_type_name(x) for x in self.pixel_types]) if name: result += " *%s*" % self.name if self.list_of: result = "[%s]" % result if self.has_default: result += " = %s" % str(self.default) return result
def pixel_type_name(self): """String **pixel_type_name** () Returns a string representing the pixel type of the image. Intended primarily for display (GUI) purposes, since using the integer values in ``Image.data.pixel_type`` is more efficient. See `pixel types`_ for more information.""" return util.get_pixel_type_name(self.data.pixel_type)
def rest_repr(self, name=False): result = '``Image`` [%s]' % '|'.join( [util.get_pixel_type_name(x) for x in self.pixel_types]) if name: result += " *%s*" % self.name if self.list_of: result = "[%s]" % result if self.has_default: result += " = %s" % str(self.default) return result
def call(self, function, args, output_args, limit_choices=None): if limit_choices is None: raise RuntimeError("You can not create a plugin that takes a Pixel argument that does not have a self type") pixel_type = limit_choices new_output_args = (output_args + ["pixel_from_python<%sPixel>::convert(%s)" % (util.get_pixel_type_name(pixel_type), self.pysymbol)]) if len(args) == 0: return self._do_call(function, new_output_args) else: return args[0].call(function, args[1:], new_output_args, limit_choices)
def call(self, function, args, output_args, limit_choices=None): if limit_choices is None: raise RuntimeError( "You can not create a plugin that takes a Pixel argument that does not have a self type" ) pixel_type = limit_choices new_output_args = (output_args + [ "pixel_from_python<%sPixel>::convert(%s)" % (util.get_pixel_type_name(pixel_type), self.pysymbol) ]) if len(args) == 0: return self._do_call(function, new_output_args) else: return args[0].call(function, args[1:], new_output_args, limit_choices)
def call(self, function, args, output_args, limit_choices=None): if function.image_types_must_match and limit_choices is not None: choices = self._get_choices_for_pixel_type(limit_choices) else: choices = self._get_choices() result = "switch(get_image_combination(%(pysymbol)s)) {\n" % self for choice, pixel_type in choices: result += "case %s:\n" % choice.upper() new_output_args = output_args + [ "*((%s*)%s)" % (choice, self.symbol) ] if len(args) == 0: result += self._do_call(function, new_output_args) else: if limit_choices is None: result += args[0].call(function, args[1:], new_output_args, pixel_type) else: result += args[0].call(function, args[1:], new_output_args, limit_choices) result += "break;\n" result += "default:\n" acceptable_types = [ util.get_pixel_type_name(y).upper() for x, y in choices ] if len(acceptable_types) >= 2: phrase = "values are" acceptable_types[-1] = "and " + acceptable_types[-1] else: phrase = "value is" acceptable_types = ", ".join(acceptable_types) result += ( 'PyErr_Format(PyExc_TypeError,' '"The \'%s\' argument of \'%s\' can not have pixel type \'%%s\'. ' 'Acceptable %s %s."' ', get_pixel_type_name(%s));\nreturn 0;\n' % (self.name, function.__name__, phrase, acceptable_types, self.pysymbol)) result += "}\n" return result
def _get_choices_for_pixel_type(self, pixel_type): if pixel_type == ONEBIT: result = ["OneBitImageView", "Cc", "OneBitRleImageView", "RleCc", "MlCc"] else: result = [util.get_pixel_type_name(pixel_type) + "ImageView"] return [(x, pixel_type) for x in result]