def scan_sizes(filespecs, verbose): """ Displays the dimensions of the given list of images. """ total_compressed = 0 total_uncompressed = 0 num_processed = 0 for filespec in sorted(filespecs): basename = os.path.basename(filespec) try: info = imsize.read(filespec) except RuntimeError as e: print(f"{basename}: Skipping: {e}") continue if info is not None: num_processed += 1 total_uncompressed += info.nbytes / 1024**2 total_compressed += info.filesize / 1024**2 if verbose: megs = info.nbytes / 1024**2 mpix = info.width * info.height / 1000000 est = " [estimated]" if info.uncertain else "" if info.rot90_ccw_steps in [0, 2]: width, height = (info.width, info.height) else: width, height = (info.height, info.width) print(f"{basename}: {width} x {height} x {info.nchan} x {info.bitdepth} bits => {megs:.1f} MB{est}, {mpix:.1f} MP") print(f"Scanned {num_processed} images, total {total_compressed:.1f} MB compressed, {total_uncompressed:.1f} MB uncompressed")
def test_dng(self): dngs = glob.glob(os.path.join(imagedir, "*.DNG")) self.assertTrue(len(dngs) > 0) for i, dng in enumerate(sorted(dngs)): info = imsize.read(dng) self.assertEqual(info.filetype, "dng") self.assertEqual(info.nchan, 1) self.assertTrue(info.width, 7296) self.assertTrue(info.height, 3648) self.assertEqual(info.bitdepth, 12) self.assertEqual(info.bytedepth, 2) self.assertEqual(info.maxval, 4095) self.assertEqual(info.isfloat, False) self.assertEqual(info.uncertain, False) self.assertEqual(info.cfa_raw, True) self.assertEqual(info.nbytes, 7296 * 3648 * 2) self.assertEqual(info.orientation, 1)
def test_png(self): pngs = glob.glob(os.path.join(imagedir, "*.png")) self.assertTrue(len(pngs) > 0) for i, png in enumerate(sorted(pngs)): info = imsize.read(png) self.assertEqual(info.filetype, "png") self.assertEqual(info.nchan, 3) self.assertTrue(info.width in [600, 450]) self.assertTrue(info.height in [600, 450]) self.assertEqual(info.bitdepth, 8) self.assertEqual(info.bytedepth, 1) self.assertEqual(info.maxval, 255) self.assertEqual(info.isfloat, False) self.assertEqual(info.uncertain, False) self.assertEqual(info.cfa_raw, False) self.assertEqual(info.nbytes, 600 * 450 * 3) self.assertEqual(info.orientation, 1)
def test_orientations(self): jpegs = sorted( glob.glob(os.path.join(imagedir, "orientations", "*.jpg"))) tiffs = sorted( glob.glob(os.path.join(imagedir, "orientations", "*.tif"))) self.assertTrue(len(jpegs) == 16) self.assertTrue(len(tiffs) == 16) for fmt, fileset in zip(["jpeg", "tiff"], [jpegs, tiffs]): for i, filespec in enumerate(fileset): info = imsize.read(filespec) self.assertEqual(info.filetype, fmt) self.assertEqual(info.nchan, 3) self.assertTrue(info.width in [600, 450]) self.assertTrue(info.height in [600, 450]) self.assertEqual(info.bitdepth, 8) self.assertEqual(info.bytedepth, 1) self.assertEqual(info.maxval, 255) self.assertEqual(info.isfloat, False) self.assertEqual(info.uncertain, False) self.assertEqual(info.cfa_raw, False) self.assertEqual(info.nbytes, 600 * 450 * 3) self.assertEqual(info.orientation, (i % 8) + 1)
def on_key_press(symbol, modifiers): keys = pyglet.window.key disallowed_keys = keys.MOD_CTRL | keys.MOD_ALT self._vprint( f"on_key_press({keys.symbol_string(symbol)}, modifiers={keys.modifiers_string(modifiers)})" ) if symbol == keys.C and modifiers == keys.MOD_CTRL: self.running = False self.event_loop.has_exit = True if (modifiers & disallowed_keys ) == 0: # ignore NumLock, ScrollLock, CapsLock, Shift if symbol in [keys.ESCAPE, keys.Q]: # exit self.running = False self.event_loop.has_exit = True if symbol == keys.F: # fullscreen self.fullscreen = not self.fullscreen self.window.set_fullscreen(self.fullscreen) self.window.set_mouse_visible(not self.fullscreen) self.need_redraw = True if symbol == keys.H: # reset zoom & pan ("home") self.scale = 1.0 self.mousepos = np.zeros(2) self.need_redraw = True if symbol == keys.G: # gamma self.gamma = not self.gamma self.need_redraw = True if symbol == keys.B: # brightness ev = (self.ev * 2) + 4 ev = (ev + 1) % 9 # [0, 8] ==> [-2, +2] EV in 0.5-EV steps self.ev = (ev - 4) / 2 self.need_redraw = True if symbol == keys.T: # texture filtering self.texture_filter = "LINEAR" if self.texture_filter == "NEAREST" else "NEAREST" self.need_redraw = True if symbol == keys.S: # split self.numtiles = (self.numtiles % 4) + 1 self.tileidx = min(self.tileidx, self.numtiles - 1) self.img_per_tile = np.clip(self.img_per_tile, 0, self.files.numfiles - 1) self.viewports = self._retile(self.numtiles, self.winsize) self.window.set_caption(self._caption()) self.need_redraw = True if symbol == keys.R: # rotate imgidx = self.img_per_tile[self.tileidx] self.files.orientations[imgidx] += 90 self.files.orientations[imgidx] %= 360 self.need_redraw = True if symbol == keys.I: # image info imgidx = self.img_per_tile[self.tileidx] filespec = self.files.filespecs[imgidx] fileinfo = imsize.read(filespec) print(fileinfo) self._print_exif(filespec) if symbol in [keys.D, keys.DELETE]: # drop and/or delete if self.numtiles == 1: # only in single-tile mode imgidx = self.img_per_tile[self.tileidx] if symbol == keys.D: self.files.remove(imgidx) # drop else: self.files.delete(imgidx) # delete if self.files.numfiles == 0: self.running = False self.event_loop.has_exit = True else: self.img_per_tile[self.tileidx] = ( imgidx - 1) % self.files.numfiles self.window.set_caption(self._caption()) self.need_redraw = True # pylint: disable=protected-access if symbol in [keys._1, keys._2, keys._3, keys._4]: tileidx = symbol - keys._1 self.tileidx = tileidx if tileidx < self.numtiles else self.tileidx self.need_redraw = True