def _get_rgbarray(self, idx, rgbobj, image_order): # NOTE: data is assumed to be in the range 0-255 at this point # but clip as a precaution # See NOTE [A]: idx is always an array calculated in the caller and # discarded afterwards # idx = idx.clip(0, 255) idx.clip(0, 255, out=idx) # run it through the shift array and clip the result # See NOTE [A] # idx = self.sarr[idx].clip(0, 255) idx = self.sarr[idx] idx.clip(0, 255, out=idx) ri, gi, bi = self.get_order_indexes(rgbobj.get_order(), "RGB") out = rgbobj.rgbarr if len(idx.shape) == 2: out[..., ri] = self.arr[0][idx] out[..., gi] = self.arr[1][idx] out[..., bi] = self.arr[2][idx] else: rj, gj, bj = self.get_order_indexes(image_order, "RGB") out[..., ri] = self.arr[0][idx[..., rj]] out[..., gi] = self.arr[1][idx[..., gj]] out[..., bi] = self.arr[2][idx[..., bj]] # convert to monitor profile, if one is available # TODO: this conversion doesn't really belong here! if PythonImage.have_monitor_profile(): self.logger.debug("Converting to monitor profile.") self.convert_profile_monitor(rgbobj)
def convert_profile_monitor(self, rgbobj): inp = rgbobj.get_array("RGB") arr = PythonImage.convert_profile_monitor(inp) out = rgbobj.rgbarr ri, gi, bi = rgbobj.get_order_indexes("RGB") out[..., ri] = arr[..., 0] out[..., gi] = arr[..., 1] out[..., bi] = arr[..., 2]
def load_image(self, filepath): # Create an image. Assume type to be an AstroImage unless # the MIME association says it is something different. image = AstroImage.AstroImage(logger=self.logger) try: self.logger.info("Loading image from %s" % (filepath)) typ, enc = mimetypes.guess_type(filepath) if typ: typ, subtyp = typ.split('/') self.logger.info("MIME type is %s/%s" % (typ, subtyp)) if (typ == 'image') and (subtyp != 'fits'): image = PythonImage.PythonImage(logger=self.logger) image.load_file(filepath) #self.gui_do(chinfo.fitsimage.onscreen_message, "") except Exception, e: errmsg = "Failed to load file '%s': %s" % (filepath, str(e)) self.logger.error(errmsg) try: (type, value, tb) = sys.exc_info() tb_str = "\n".join(traceback.format_tb(tb)) except Exception, e: tb_str = "Traceback information unavailable."