def get_coords_of_all_pixels(self): # These are in x, y order, to help me keep things straight full_space_dims = np.array( [self.get_frame_width(), self.get_frame_height()]) full_pixel_dims = np.array( [self.get_pixel_width(), self.get_pixel_height()]) # These are addressed in the same y, x order as in pixel_array, but the values in them # are listed in x, y order uncentered_pixel_coords = np.indices( [self.get_pixel_height(), self.get_pixel_width()])[::-1].transpose(1, 2, 0) uncentered_space_coords = fdiv( uncentered_pixel_coords * full_space_dims, full_pixel_dims) # Could structure above line's computation slightly differently, but figured (without much # thought) multiplying by frame_shape first, THEN dividing by pixel_shape, is probably # better than the other order, for avoiding underflow quantization in the division (whereas # overflow is unlikely to be a problem) centered_space_coords = (uncentered_space_coords - fdiv(full_space_dims, 2)) # Have to also flip the y coordinates to account for pixel array being listed in # top-to-bottom order, opposite of screen coordinate convention centered_space_coords = centered_space_coords * (1, -1) return centered_space_coords
def get_cairo_context(self, pixel_array): cached_ctx = self.get_cached_cairo_context(pixel_array) if cached_ctx: return cached_ctx pw = self.get_pixel_width() ph = self.get_pixel_height() fw = self.get_frame_width() fh = self.get_frame_height() fc = self.get_frame_center() surface = cairo.ImageSurface.create_for_data(pixel_array, cairo.FORMAT_ARGB32, pw, ph) ctx = cairo.Context(surface) ctx.scale(pw, ph) ctx.set_matrix( cairo.Matrix( fdiv(pw, fw), 0, 0, -fdiv(ph, fh), (pw / 2) + fc[0] * fdiv(pw, fw), (ph / 2) + fc[1] * fdiv(ph, fh), )) self.cache_cairo_context(pixel_array, ctx) return ctx
def get_coords_of_all_pixels(self): # These are in x, y order, to help me keep things straight full_space_dims = np.array([ self.get_frame_width(), self.get_frame_height() ]) full_pixel_dims = np.array([ self.get_pixel_width(), self.get_pixel_height() ]) # These are addressed in the same y, x order as in pixel_array, but the values in them # are listed in x, y order uncentered_pixel_coords = np.indices( [self.get_pixel_height(), self.get_pixel_width()] )[::-1].transpose(1, 2, 0) uncentered_space_coords = fdiv( uncentered_pixel_coords * full_space_dims, full_pixel_dims) # Could structure above line's computation slightly differently, but figured (without much # thought) multiplying by frame_shape first, THEN dividing by pixel_shape, is probably # better than the other order, for avoiding underflow quantization in the division (whereas # overflow is unlikely to be a problem) centered_space_coords = ( uncentered_space_coords - fdiv(full_space_dims, 2) ) # Have to also flip the y coordinates to account for pixel array being listed in # top-to-bottom order, opposite of screen coordinate convention centered_space_coords = centered_space_coords * (1, -1) return centered_space_coords
def point_to_number(self, point): start_point, end_point = self.main_line.get_start_and_end() full_vect = end_point - start_point unit_vect = normalize(full_vect) def distance_from_start(p): return np.dot(p - start_point, unit_vect) proportion = fdiv(distance_from_start(point), distance_from_start(end_point)) return interpolate(self.x_min, self.x_max, proportion)
def adjusted_thickness(self, thickness): # TODO: This seems...unsystematic big_sum = op.add( PRODUCTION_QUALITY_CAMERA_CONFIG["pixel_height"], PRODUCTION_QUALITY_CAMERA_CONFIG["pixel_width"], ) this_sum = op.add( self.get_pixel_height(), self.get_pixel_width(), ) factor = fdiv(big_sum, this_sum) return 1 + (thickness - 1) / factor
def adjusted_thickness(self, thickness): # TODO: This seems...unsystematic big_sum = op.add( PRODUCTION_QUALITY_CAMERA_CONFIG["pixel_height"], PRODUCTION_QUALITY_CAMERA_CONFIG["pixel_width"], ) this_sum = op.add( self.get_pixel_height(), self.get_pixel_width(), ) factor = fdiv(big_sum, this_sum) return 1 + (thickness - 1) / factor
def resize_frame_shape(self, fixed_dimension=0): """ Changes frame_shape to match the aspect ratio of the pixels, where fixed_dimension determines whether frame_height or frame_width remains fixed while the other changes accordingly. """ pixel_height = self.get_pixel_height() pixel_width = self.get_pixel_width() frame_height = self.get_frame_height() frame_width = self.get_frame_width() aspect_ratio = fdiv(pixel_width, pixel_height) if fixed_dimension == 0: frame_height = frame_width / aspect_ratio else: frame_width = aspect_ratio * frame_height self.set_frame_height(frame_height) self.set_frame_width(frame_width)
def resize_frame_shape(self, fixed_dimension=0): """ Changes frame_shape to match the aspect ratio of the pixels, where fixed_dimension determines whether frame_height or frame_width remains fixed while the other changes accordingly. """ pixel_height = self.get_pixel_height() pixel_width = self.get_pixel_width() frame_height = self.get_frame_height() frame_width = self.get_frame_width() aspect_ratio = fdiv(pixel_width, pixel_height) if fixed_dimension == 0: frame_height = frame_width / aspect_ratio else: frame_width = aspect_ratio * frame_height self.set_frame_height(frame_height) self.set_frame_width(frame_width)
def overlay_rgba_array(self, arr): fg = arr bg = self.pixel_array # rgba_max_val = self.rgb_max_val src_rgb, src_a, dst_rgb, dst_a = [ a.astype(np.float32) / self.rgb_max_val for a in fg[..., :3], fg[..., 3], bg[..., :3], bg[..., 3] ] out_a = src_a + dst_a * (1.0 - src_a) # When the output alpha is 0 for full transparency, # we have a choice over what RGB value to use in our # output representation. We choose 0 here. out_rgb = fdiv(src_rgb * src_a[..., None] + dst_rgb * dst_a[..., None] * (1.0 - src_a[..., None]), out_a[..., None], zero_over_zero_value=0) self.pixel_array[..., :3] = out_rgb * self.rgb_max_val self.pixel_array[..., 3] = out_a * self.rgb_max_val
def get_zoom_factor(self): return fdiv(self.zoomed_camera.frame.get_height(), self.zoomed_display.get_height())
def get_zoom_factor(self): return fdiv( self.zoomed_camera.frame.get_height(), self.zoomed_display.get_height() )