コード例 #1
0
ファイル: window.py プロジェクト: jackwalker64/reflect
  def _redrawDisplay(self):
    leaf = self._leaves[self._currentTab]["clip"]
    n = self._leaves[self._currentTab]["currentFrame"]

    if Cache.current()._enableStatistics:
      t1 = time.perf_counter()
      image = leaf.frame(n)
      t2 = time.perf_counter()
      logging.info(Cache.current().stats())
      logging.info("Accessed frame {} in {} us".format(n, round((t2 - t1) * 1000000, 5)))
    else:
      image = leaf.frame(n)

    self._screen.fill((127, 127, 127), rect = self._displayPanel)

    # The leaf is assumed to fit within the display panel, so we just need to shift it
    # to be in the centre middle.
    (blitLeft, blitTop) = (self._displayPanel.left, self._displayPanel.top)
    blitLeft += (self._displayPanel.width - leaf.width) / 2
    blitTop += (self._displayPanel.height - leaf.height) / 2

    surface = pygame.surfarray.make_surface(image.swapaxes(0, 1))
    self._screen.blit(surface, (blitLeft, blitTop))

    pygame.display.update(self._displayPanel)

    self._redrawTimeline(n, leaf)
    self._redrawProgress(n, leaf)
コード例 #2
0
ファイル: window.py プロジェクト: jackwalker64/reflect
 def makeIcon(leaf):
   # Render the clip's frame and resize it to be used as an icon in the tabstrip
   if Cache.current()._enableStatistics:
     t1 = time.perf_counter()
     image = leaf.frame(0)
     t2 = time.perf_counter()
     logging.info(Cache.current().stats())
     logging.info("Accessed first frame for making icon in {} us".format(round((t2 - t1) * 1000000, 5)))
   else:
     image = leaf.frame(0)
   newHeight = self._tabstripPanel.height - 4
   newWidth = max(round(newHeight / 2), round(leaf.width * newHeight / leaf.height))
   resizedImage = cv2.resize(image, (newWidth, newHeight), interpolation = cv2.INTER_AREA)
   surface = pygame.surfarray.make_surface(resizedImage.swapaxes(0, 1))
   return surface
コード例 #3
0
ファイル: clips.py プロジェクト: jackwalker64/reflect
  def save(self, filepath, **kwargs):
    saveMethod = None

    videoExtensions = [".mov", ".avi", ".mpg", ".mpeg", ".mp4", ".mkv", ".wmv"]
    for extension in videoExtensions:
      if filepath.lower().endswith(extension):
        saveMethod = self._saveVideo

    gifExtensions = [".gif"]
    for extension in gifExtensions:
      if filepath.lower().endswith(extension):
        saveMethod = self._saveGif

    imageExtensions = [".png", ".jpg", ".jpeg", ".bmp", ".ppm", ".tiff", ".psd"]
    for extension in imageExtensions:
      if filepath.lower().endswith(extension):
        saveMethod = self._saveImage

    if saveMethod is not None:
      if mode == "server":
        # Potentially many frames are about to be rendered while the script is running.
        # Normally these frames would be staged, to be committed to the cache when the script terminates.
        # Here, however, that would result in staging an entire video's worth of frames.
        # So we want to temporarily disable staging until the file has been saved.
        from reflect.server.cache import Cache
        cache = Cache.current()
        cache.lockStagingArea()

      saveMethod(filepath, **kwargs)

      if mode == "server":
        cache.unlockStagingArea()
    else:
      raise ValueError("Don't know how to write {}. Try giving a filepath with an extension like .mp4 or .gif or .png.".format(filepath))
コード例 #4
0
ファイル: clips.py プロジェクト: jackwalker64/reflect
  def frame(self, n):
    if self._isConstant:
      n = 0 # Redirect the request to be for the first frame only, to avoid rendering/caching the same image multiple times

    if mode == "server":
      from reflect.server.cache import Cache
      cache = Cache.current()
      image = cache.get(self, n, None)
      if image is not None:
        # The frame already exists in the cache, so don't bother re-rendering it
        return image
      else:
        # Render the frame, offer it to the cache, and then return it
        image = self._framegen(n)
        cache.set(self, n, image)
        return image
    else:
      # We are not in server mode, so there is no global cache.
      if self._isConstant:
        # It might be useful to cache the rendered image locally in this object, in
        # case this frame method is called frequently.
        if self._constantImage is None:
          self._constantImage = self._framegen(0)
        return self._constantImage
      else:
        return self._framegen(n)