예제 #1
0
 def _do_flip(self):
     """ Draw the canvas to the screen. """
     sdl2.SDL_FillRect(self.work_surface, None, self.border_attr)
     if self.composite_artifacts:
         self.work_pixels[:] = video_graphical.apply_composite_artifacts(
             self.pixels[self.vpagenum], 4 // self.bitsperpixel)
         sdl2.SDL_SetSurfacePalette(self.work_surface,
                                    self.composite_palette)
     else:
         self.work_pixels[:] = self.pixels[self.vpagenum]
         sdl2.SDL_SetSurfacePalette(self.work_surface,
                                    self.show_palette[self.blink_state])
     # apply cursor to work surface
     self._show_cursor(True)
     # convert 8-bit work surface to (usually) 32-bit display surface format
     pixelformat = self.display_surface.contents.format
     conv = sdl2.SDL_ConvertSurface(self.work_surface, pixelformat, 0)
     # scale converted surface and blit onto display
     if not self.smooth:
         sdl2.SDL_BlitScaled(conv, None, self.display_surface, None)
     else:
         # smooth-scale converted surface
         w, h = self.window_width, self.window_height
         zoomx = ctypes.c_double(w / (self.size[0] + 2.0 * self.border_x))
         zoomy = ctypes.c_double(h / (self.size[1] + 2.0 * self.border_y))
         # only free the surface just before zoomSurface needs to re-allocate
         # so that the memory block is highly likely to be easily available
         # this seems to avoid unpredictable delays
         sdl2.SDL_FreeSurface(self.zoomed)
         self.zoomed = sdl2.sdlgfx.zoomSurface(conv, zoomx, zoomy,
                                               sdl2.sdlgfx.SMOOTHING_ON)
         # blit onto display
         sdl2.SDL_BlitSurface(self.zoomed, None, self.display_surface, None)
     # create clipboard feedback
     if self.clipboard.active():
         rects = (sdl2.SDL_Rect(r[0] + self.border_x, r[1] + self.border_y,
                                r[2], r[3])
                  for r in self.clipboard.selection_rect)
         sdl_rects = (sdl2.SDL_Rect *
                      len(self.clipboard.selection_rect))(*rects)
         sdl2.SDL_FillRect(
             self.overlay, None,
             sdl2.SDL_MapRGBA(self.overlay.contents.format, 0, 0, 0, 0))
         sdl2.SDL_FillRects(
             self.overlay, sdl_rects, len(sdl_rects),
             sdl2.SDL_MapRGBA(self.overlay.contents.format, 128, 0, 128, 0))
         sdl2.SDL_BlitScaled(self.overlay, None, self.display_surface, None)
     # flip the display
     sdl2.SDL_UpdateWindowSurface(self.display)
예제 #2
0
 def _do_flip(self):
     """ Draw the canvas to the screen. """
     sdl2.SDL_FillRect(self.work_surface, None, self.border_attr)
     if self.composite_artifacts:
         self.work_pixels[:] = video_graphical.apply_composite_artifacts(
             self.pixels[self.vpagenum], 4 // self.bitsperpixel
         )
         sdl2.SDL_SetSurfacePalette(self.work_surface, self.composite_palette)
     else:
         self.work_pixels[:] = self.pixels[self.vpagenum]
         sdl2.SDL_SetSurfacePalette(self.work_surface, self.show_palette[self.blink_state])
     # apply cursor to work surface
     self._show_cursor(True)
     # convert 8-bit work surface to (usually) 32-bit display surface format
     pixelformat = self.display_surface.contents.format
     conv = sdl2.SDL_ConvertSurface(self.work_surface, pixelformat, 0)
     # scale converted surface and blit onto display
     if not self.smooth:
         sdl2.SDL_BlitScaled(conv, None, self.display_surface, None)
     else:
         # smooth-scale converted surface
         w, h = self.window_width, self.window_height
         zoomx = ctypes.c_double(w / (self.size[0] + 2.0 * self.border_x))
         zoomy = ctypes.c_double(h / (self.size[1] + 2.0 * self.border_y))
         # only free the surface just before zoomSurface needs to re-allocate
         # so that the memory block is highly likely to be easily available
         # this seems to avoid unpredictable delays
         sdl2.SDL_FreeSurface(self.zoomed)
         self.zoomed = sdl2.sdlgfx.zoomSurface(conv, zoomx, zoomy, sdl2.sdlgfx.SMOOTHING_ON)
         # blit onto display
         sdl2.SDL_BlitSurface(self.zoomed, None, self.display_surface, None)
     # create clipboard feedback
     if self.clipboard.active():
         rects = (
             sdl2.SDL_Rect(r[0] + self.border_x, r[1] + self.border_y, r[2], r[3])
             for r in self.clipboard.selection_rect
         )
         sdl_rects = (sdl2.SDL_Rect * len(self.clipboard.selection_rect))(*rects)
         sdl2.SDL_FillRect(self.overlay, None, sdl2.SDL_MapRGBA(self.overlay.contents.format, 0, 0, 0, 0))
         sdl2.SDL_FillRects(
             self.overlay, sdl_rects, len(sdl_rects), sdl2.SDL_MapRGBA(self.overlay.contents.format, 128, 0, 128, 0)
         )
         sdl2.SDL_BlitScaled(self.overlay, None, self.display_surface, None)
     # flip the display
     sdl2.SDL_UpdateWindowSurface(self.display)
예제 #3
0
def apply_composite_artifacts(screen, pixels=4):
    """ Process the canvas to apply composite colour artifacts. """
    src_array = pygame.surfarray.array2d(screen)
    return pygame.surfarray.make_surface(
                    video_graphical.apply_composite_artifacts(src_array, pixels))
예제 #4
0
def apply_composite_artifacts(screen, pixels=4):
    """ Process the canvas to apply composite colour artifacts. """
    src_array = pygame.surfarray.array2d(screen)
    return pygame.surfarray.make_surface(
        video_graphical.apply_composite_artifacts(src_array, pixels))