def adjustmentValueChanged(self, event): value = event.getSource().getValue() rowstride = min(width, value) for j in range(0, min(height, int(width * height / value))): System.arraycopy(pixelsCopy, j * value, pixels, j * width, rowstride) image.updateAndDraw()
def adjustmentValueChanged(self, event): value = event.getSource().getValue() rowstride = min(width, value) for j in range(0, min(height, int(width * height / value))): System.arraycopy(pixelsCopy, j * value, pixels, j * width, rowstride) image.updateAndDraw()
def unpackBits2(bytes_packedbits, tags, use_imagereader=False): # Decompress a packBits-compressed image, returns an array of n_bytes. # ra: a RandomAccessFile with the pointer at the right place to start reading. # PackBits actually packages bytes: a byte-wise RLE most efficient at encoding runs of bytes # 3 types of data packets: # 1. two-byte encoded run packet: # - first byte is the number of bytes in the run. # Ranges from -127 to -1, meaning +1: from 2 to 128 (-count + 1) # - second byte value of each byte in the run. # 2. literal run packet: stores 1 to 128 bytes literally without compression. # - first byte is the number of bytes in the run. # Ranges from 0 to 127, indicating 1 to 128 values (count + 1) # - then the sequence of literal bytes # 3. no-op packet: never used, value -128. # See documentation: http://paulbourke.net/dataformats/tiff/tiff_summary.pdf # (note documentation PDF has its details flipped when it comes to the ranges for literal runs and packed runs) # See also: ij.io.ImageReader.packBitsUncompress (a public method without side effects) n_bytes = tags["width"] * tags["height"] if use_imagereader: return ImageReader(FileInfo()).packBitsUncompress( bytes_packedbits, n_bytes) bytes = zeros(n_bytes, 'b') try: indexP = 0 # packed indexU = 0 # unpacked while indexU < n_bytes: count = bytes_packedbits[indexP] if count >= 0: # Literal run System.arraycopy(bytes_packedbits, indexP + 1, bytes, indexU, count + 1) indexP += count + 2 # one extra for the 'count' byte indexU += count + 1 else: # Packed run Arrays.fill(bytes, indexU, indexU - count + 1, bytes_packedbits[indexP + 1]) indexP += 2 indexU += -count + 1 except: print sys.exc_info() finally: return bytes
def intoImg(pixels): img = ArrayImgFactory(UnsignedByteType()).create([4, 4]) System.arraycopy(pixels, 0, img.update(None).getCurrentStorageArray(), 0, len(pixels)) return img