Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
    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)
Beispiel #4
0
 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
Beispiel #5
0
    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)
Beispiel #6
0
 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)
Beispiel #7
0
 def generate_generic_pngs(self):
     print("Copying over generic images")
     for pixel_type in ALL:
         if pixel_type in (FLOAT, COMPLEX):
             pixel_type_name = "GreyScale"
         else:
             pixel_type_name = util.get_pixel_type_name(pixel_type)
         image = core.load_image(
             os.path.join(paths.test, pixel_type_name + "_generic.tiff"))
         print("  " + image.pixel_type_name)
         _png_support.save_PNG(
             image,
             os.path.join(self.output_images_path,
                          "%s_generic.png" % (pixel_type_name)))
Beispiel #8
0
 def generate_generic_pngs(self):
    print "Copying over generic images"
    for pixel_type in ALL:
       if pixel_type in (FLOAT, COMPLEX):
          pixel_type_name = "GreyScale"
       else:
          pixel_type_name = util.get_pixel_type_name(pixel_type)
       image = core.load_image(
          os.path.join(paths.test,
                       pixel_type_name + "_generic.tiff"))
       print "  " + image.pixel_type_name
       _png_support.save_PNG(
          image,
          os.path.join(self.output_images_path,
                       "%s_generic.png" % (pixel_type_name)))
Beispiel #9
0
 def get_generic_images():
    images = {}
    for i in [ONEBIT, RGB, GREYSCALE, GREY16]:
       pixel_type_name = util.get_pixel_type_name(i)
       images[i] = core.load_image(os.path.join(
          paths.test, pixel_type_name + "_generic.tiff"))
    for i in (FLOAT, COMPLEX):
       image = core.load_image(os.path.join(
          paths.test, "GreyScale_generic.tiff"))
       if i == FLOAT:
          images[i] = _image_conversion.to_float(image)
       elif i == COMPLEX:
          try:
             images[i] = _image_conversion.to_complex(image)
          except:
             pass
    return images
Beispiel #10
0
 def get_generic_images():
     images = {}
     for i in [ONEBIT, RGB, GREYSCALE, GREY16]:
         pixel_type_name = util.get_pixel_type_name(i)
         images[i] = core.load_image(
             os.path.join(paths.test, pixel_type_name + "_generic.tiff"))
     for i in (FLOAT, COMPLEX):
         image = core.load_image(
             os.path.join(paths.test, "GreyScale_generic.tiff"))
         if i == FLOAT:
             images[i] = _image_conversion.to_float(image)
         elif i == COMPLEX:
             try:
                 images[i] = _image_conversion.to_complex(image)
             except Exception:
                 pass
     return images
Beispiel #11
0
 def method_example(self, func, level, images, s):
     results = self.run_example(func, images)
     if len(results):
         s.write("\n----------\n\n")
     for i, (result, src_image, pixel_type,
             arguments) in enumerate(results):
         s.write("**Example %d:** %s" % (i + 1, func.__name__))
         if not arguments is None:
             s.write("(%s)" % ", ".join([str(x) for x in arguments]))
         s.write("\n\n")
         if not pixel_type is None:
             pixel_type_name = util.get_pixel_type_name(pixel_type)
             if pixel_type in (FLOAT, COMPLEX):
                 pixel_type_name = "GreyScale"
             self.write_image(s, "%s_generic" % pixel_type_name)
         result_filename = "%s_plugin_%02d" % (func.__name__, i)
         if isinstance(result, core.ImageBase):
             self.save_image(result, result_filename)
             self.write_image(s, result_filename)
         elif (result is None and isinstance(func.self_type, args.ImageType)
               and src_image is not None):
             self.save_image(src_image, result_filename)
             self.write_image(s, result_filename)
         elif util.is_image_list(result):
             result_filenames = []
             for j, part in enumerate(result):
                 result_filename = ("%s_plugin_%02d_%02d" %
                                    (func.__name__, i, j))
                 self.save_image(part, result_filename)
                 s.write("|%s| " % result_filename)
                 result_filenames.append(result_filename)
             s.write("\n\n")
             for result_filename in result_filenames:
                 self.write_image(s, result_filename,
                                  "|%s|" % result_filename)
         else:
             s.write("*result* = " + repr(result) + "\n\n")
     s.write("\n\n")
Beispiel #12
0
 def method_example(self, func, level, images, s):
    results = self.run_example(func, images)
    if len(results):
       s.write("\n----------\n\n")
    for i, (result, src_image, pixel_type, arguments) in enumerate(results):
       s.write(u"**Example %d:** %s" % (i + 1, func.__name__))
       if not arguments is None:
          s.write(u"(%s)" % ", ".join([str(x) for x in arguments]))
       s.write("\n\n")
       if not pixel_type is None:
          pixel_type_name = util.get_pixel_type_name(pixel_type)
          if pixel_type in (FLOAT, COMPLEX):
             pixel_type_name = "GreyScale"
          self.write_image(s, "%s_generic" % pixel_type_name)
       result_filename = "%s_plugin_%02d" % (func.__name__, i)
       if isinstance(result, core.ImageBase):
          self.save_image(result, result_filename)
          self.write_image(s, result_filename)
       elif (result is None and
             isinstance(func.self_type, args.ImageType) and
             src_image is not None):
          self.save_image(src_image, result_filename)
          self.write_image(s, result_filename)
       elif util.is_image_list(result):
          result_filenames = []
          for j, part in enumerate(result):
             result_filename = ("%s_plugin_%02d_%02d" %
                                (func.__name__, i, j))
             self.save_image(part, result_filename)
             s.write("|%s| " % result_filename)
             result_filenames.append(result_filename)
          s.write("\n\n")
          for result_filename in result_filenames:
             self.write_image(s, result_filename, "|%s|" % result_filename)
       else:
          s.write("*result* = " + repr(result) + "\n\n")
    s.write("\n\n")
Beispiel #13
0
 def _get_choices_for_pixel_type(self, pixel_type):
     if pixel_type == enums.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]