def stitch_raster_frame()

in src/spg/spg.py [0:0]


    def stitch_raster_frame(self, frame, kwargs, results):
        """ The method to produce a single raster frame stitched from the output of each of the generators

        :param frame: the frame we are going to stitch
        :param kwargs: a dictionary of arguments for the function
        :param results: a dictionary to store the output results in cross thread
        """
        raster_map = kwargs.get("raster_map", None)
        if raster_map is None:
            raise ValueError("raster_data not found in kwargs")

        full_sequence_frame_num = kwargs.get("full_sequence_frame_num", None)
        if full_sequence_frame_num is None:
            raise ValueError("full_sequence_frame_num not found in kwargs")

        pattern_results = kwargs.get("pattern_results", None)
        if pattern_results is None:
            raise ValueError("pattern_results not found in kwargs")

        raster_name = raster_map.name
        base_path = self.get_raster_base_path(raster_name)
        resolution_width = raster_map.resolution_width
        resolution_height = raster_map.resolution_height

        raster_image = _imageUtils.create_solid_color_image(
            resolution_width, resolution_height,
            num_channels=3, color=(0, 0, 0)
        )
        frame_num = self.project_settings.sequence_start_frame + frame
        for mapping in raster_map.mappings:
            led_wall = self.walls[mapping.wall_name]
            file_path = pattern_results[led_wall.name][frame_num]
            buf = oiio.ImageBuf(file_path)
            buf.read()
            if buf.has_error:
                print("Error reading the file:", buf.geterror())

            wall_segment_region = oiio.ROI(
                mapping.wall_segment_u_start, mapping.wall_segment_u_end,
                mapping.wall_segment_v_start, mapping.wall_segment_v_end
            )

            # We always make the top left hand corner the origin before we apply any positioning
            # into the mapping
            wall_segment = oiio.ImageBufAlgo.cut(buf, roi=wall_segment_region, nthreads=0)
            wall_segment_rotated = oiio.ImageBufAlgo.rotate(wall_segment,
                                                            math.radians(mapping.wall_segment_orientation),
                                                            recompute_roi=True)
            wall_segment_rotated.set_origin(0, 0)

            oiio.ImageBufAlgo.paste(
                raster_image, mapping.raster_u, mapping.raster_v, 0, 0, wall_segment_rotated, roi=oiio.ROI.All
            )

        file_name = "{0}.{1}.{2}".format(
            raster_name,
            str(full_sequence_frame_num).zfill(self.project_settings.frame_padding), self.project_settings.image_file_format
        )
        full_file_path = os.path.join(
            base_path,
            file_name
        )

        # We do not provide a channel mapping here as our images will already have had their channels swapped
        # We do not apply a color space conversion here either as these will have already been done
        _imageUtils.write_image(raster_image, full_file_path, self.project_settings.image_file_bit_depth)
        results[raster_name][full_sequence_frame_num] = full_file_path