Beispiel #1
0
        def get_scaled_spec(source_spec):
            w = source_spec.width
            h = source_spec.height
            factor = float(size) / max(float(w), float(h))
            w *= factor
            h *= factor

            s = OpenImageIO.ImageSpec(int(w), int(h), 4, OpenImageIO.UINT8)
            s.channelnames = ('R', 'G', 'B', 'A')
            s.alpha_channel = 3
            s.attribute('oiio:ColorSpace', 'sRGB')
            s.attribute('oiio:Gamma', '0.454545')
            return s
Beispiel #2
0
def test_tiff_cmyk():
    # Create a file that has unassociated alpha
    filename = "test_cmyk.tif"
    print("Testing write and read of TIFF CMYK with auto RGB translation:")
    spec = oiio.ImageSpec(2, 2, 4, "uint8")
    spec.attribute("tiff:ColorSpace", "CMYK")
    spec.channelnames = ("C", "M", "Y", "K")
    wbuf = oiio.ImageBuf(spec)
    oiio.ImageBufAlgo.fill(wbuf, (0.5, 0.0, 0.0, 0.5))
    print("  writing: ", wbuf.get_pixels())
    wbuf.write(filename)
    rbuf = oiio.ImageBuf(filename)
    print("\n  default reading as IB: ", rbuf.get_pixels())
    config = oiio.ImageSpec()
    config.attribute("oiio:RawColor", 1)
    rbuf = oiio.ImageBuf(filename, 0, 0, config)
    print("\n  reading as IB with rawcolor=1: ", rbuf.get_pixels())
    print("\n  reading as II with rawcolor=0, read scanlines backward: ")
    ii = oiio.ImageInput.open(filename)
    print("    [1] = ", ii.read_scanline(1))
    print("    [0] = ", ii.read_scanline(0))
    print("\n")
Beispiel #3
0
def writeTIFF16(filename, data, size=(8, 8), attributes={}):
    w, h = size
    spec = oiio.ImageSpec(w, h, 4, oiio.UINT16)
    for key, val in attributes.items():
        spec.attribute(key, val)
    out = oiio.ImageOutput.create(filename)
    assert out, "Can not create ImageOutput \"%s\"" % oiio.getError()
    assert out.open(
        filename, spec,
        oiio.Create), "Can not open %s : \"%s\"" % (filename, oiio.getError())
    out.write_image(spec.format, data)
    out.close()
    print filename
Beispiel #4
0
def decrypt():
    import OpenImageIO as o
    import array
    import pickle
    import random
    path = raw_input("Enter OIIO plugin path: ")
    key_path = raw_input("Name of the file with the key: ")
    in_file = raw_input("Name of the encrypted file: ")

    # Open the input files, read the RNG state and store it in "key"
    f = open(key_path, "r")
    key = pickle.load(f)
    
    spec_cr = o.ImageSpec()
    pic_cr = o.ImageInput.create(in_file, path)
    pic_cr.open(in_file, spec_cr)
    desc_cr = spec_cr.format

    # The encrypted pixel values will be stored here.
    # The decoding will be done inplace, so that will also be
    # the output buffer once the decryption is done.
    arr_cr = array.array("B", "\0" * spec_cr.image_bytes())
    length = range(len(arr_cr))
    print "Working, please wait..."

    # Let's read the encrypted image
    pic_cr.read_image(desc_cr, arr_cr)
    
    # Set the state of the RNG to match the state of the RNG which coded 
    # the image. After this, we can generate the same random sequence 
    # used to code the image.
    random.setstate(key)
    
    # Decryption!
    for i in length:
        rand_val = random.randint(0, 255)
        # This is the inverse of the encryption.
        restored_pixel = arr_cr[i] - rand_val
        if restored_pixel < 0:
            arr_dec[i] = 256 + restored_pixel
        else:
            arr_dec[i] = restored_pixel

    print "Decryption completed!"
    image = raw_input("Enter the name under which to store the result: ")
    print "Working, please wait..."    
    out_dec = o.ImageOutput.create(image, path)
    out_dec.open(image, spec_cr, False)
    out_dec.write_image(desc_cr, arr_dec)
    out_dec.close()
    return True
Beispiel #5
0
def make_test_pattern1 (filename, xres=288, yres=216) :
    buf = oiio.ImageBuf (oiio.ImageSpec (xres, yres, 3, oiio.FLOAT))
    for y in range(yres) :
        for x in range(xres) :
            b = 0.25 + 0.5 * float (((x/16) & 1) ^ ((y/16) & 1))
            if x == 1 or y == 1 or x == xres-2 or y == yres-2 :
                b = 0.0
            if (((x >= 10 and x <= 20) or (x >= xres-20 and x <= xres-10)) and
                ((y >= 10 and y <= 20) or (y >= yres-20 and y <= yres-10))) :
                b = 0.0
            if ((x == 15 or x == xres-15) and (y == 15 or y == yres-15)) :
                b = 1.0
            buf.setpixel (x, y, (float(x)/1000.0, float(y)/1000.0, b))
    buf.write (filename)
Beispiel #6
0
def ii_read_scanline_simple_test():
    # This method reads to continuous float pixels.
    # The wrapper is missing a check which would make sure that the opened image
    # contains float pixels. The first test segfaults when it tries to read
    # a wrong image.
    print "Starting ImageInput::read_scanline() (overload) tests..."
    pic_rss = oiio.ImageInput.create("../../../oiio-testimages/tahoe-gps.jpg", plugin_path)
    if pic_rss == None:
        print "Can't open test image, skipping read_scanline() (overload) tests"
        print
        return
    spec_rss = oiio.ImageSpec()
    pic_rss.open("../../../oiio-testimages/tahoe-gps.jpg", spec_rss)
    arr_rss = array.array("B", "1234" * spec_rss.scanline_bytes()) # '1234' == sizeof(float)
    # test 1
    if (pic_rss.read_scanline(0, 0, arr_rss)):
        print "Test 1 passed"
    else:
        print "Test 1 failed"
    # test 1.1 
    # This test passes a buffer much larger than is actually needed.
    arr_rss2 = array.array("B", "\0" * spec_rss.image_bytes())
    if (pic_rss.read_scanline(0, 0, arr_rss2)):
        print "Test 1.1 passed"
    else:
        print "Test 1.1 failed"
    # test 2 (check if method returns False when given a non-existing scanline -1)
    try:
        pic_rss.read_scanline(-1, 0, arr_rss)
        print "Test 2 failed"
    except IndexError:
        print "Test 2 passed"
    # test 3
    test3 = "failed"
    a = "this is not a proper argument"
    try:
        pic_rss.read_scanline(a, 0, arr_rss)
    except:
        test3 = "passed"
    print "Test 3", test3
    # test 4  (a buffer of insufficient size is passed)
    test4 = "failed"
    arr_rss = array.array("B", "\0" * (spec_rss.scanline_bytes() -1))
    try:
        pic_rss.read_scanline(0, 0, arr_rss)
    except IndexError:
        test4 = "passed"
    print "Test 4", test4
       
    print
Beispiel #7
0
def test_stitch_thirds():           
    pic_third1 = "/home/dgaletic/code/oiio-testimages/stitch_me/tahoe-0.jpg"
    pic_third2 = "/home/dgaletic/code/oiio-testimages/stitch_me/tahoe-1.jpg"
    pic_third3 = "/home/dgaletic/code/oiio-testimages/stitch_me/tahoe-2.jpg"
    path = "/home/dgaletic/code/oiio-trunk/dist/linux/lib"
    spec1 = o.ImageSpec()
    spec2 = o.ImageSpec()
    spec3 = o.ImageSpec()
    pic1 = o.ImageInput.create("jpg", path)
    pic2 = o.ImageInput.create("jpg", path)
    pic3 = o.ImageInput.create("jpg", path)
    pic1.open(pic_third1, spec1)
    pic2.open(pic_third2, spec2)
    pic3.open(pic_third3, spec3)
    spec_stitched = o.ImageSpec(spec1.width + spec2.width + spec3.width, spec1.height, spec1.nchannels, spec1.format)
    # create a list of opened ImageInput instances
    images = [pic1, pic2, pic3]
    # stitch the images next to each other, return the resulting array
    arr = stitch_row(images)
    if arr:
        out = o.ImageOutput.create("jpg", path)
        out.open("/home/dgaletic/code/branch/src/python/thirds.jpg", spec_stitched, False)  
        out.write_image(spec_stitched.format, arr)
        out.close()
Beispiel #8
0
def crypt():
    import OpenImageIO as o
    import array
    import random
    import pickle

    path = raw_input("Enter OIIO plugin path: ")
    in_file = raw_input("Enter the name of the file for encryption: ")
    out_file = raw_input("Enter the name of the resulting file: ")
    key_path = raw_input("Enter the name of the file in which to store the key: ")

    # open the input file
    spec = o.ImageSpec()
    pic = o.ImageInput.create(in_file, path)
    pic.open(in_file, spec)
    desc = spec.format

    # Create a couple of arrays where we'll store the data.
    # They all need to be the same size, and we'll fill them with dummy data for now.
    # We'll read the original pixel values in arr
    arr = array.array("B", "\0" * spec.image_bytes())
    # the values we'll write to the encrypted file
    new_values = arr[:]
    length = range(len(new_values))
    print "Working, please wait..."
    pic.read_image(desc, arr)

    # save the state of the random number generator so we can use it 
    # to decode the image
    state = random.getstate()

    # generate random values, add them to the original values.
    # Do % 256 so nothing overflows
    for i in length:
        rand_val = random.randint(0, 255)
        new_values[i] = (arr[i] + rand_val) % 256
        
    # write new values to the output file, close everything
    out = o.ImageOutput.create(out_file, path)
    out.open(out_file, spec, False)
    out.write_image(desc, new_values)
    out.close()
    # save the state of the RNG - that's the key for decryption
    f = open(key_path, "w")
    pickle.dump(state, f)
    f.close()
    return True
Beispiel #9
0
    def frame_thread(self):
        stitch_args = None
        try:
            stitch_args = self.stitch_queue.get_nowait()
        except queue.Empty:
            pass

        while stitch_args:
            frame = stitch_args[0]
            tiles_path = Path(stitch_args[1])
            images_path = Path(stitch_args[2])
            frame_path = str(os.path.join(images_path, frame["outfile"]))
            print("Assembling frame {}".format(frame_path))

            first_tile_path = os.path.join(tiles_path,
                                           frame["tiles"][0]["outfile"])
            if os.path.isfile(first_tile_path):
                first_tile = oiio.ImageBuf(str(first_tile_path))
                spec = first_tile.spec()
                frame_buf = oiio.ImageBuf(
                    oiio.ImageSpec(frame["res_x"], frame["res_y"],
                                   spec.nchannels, spec.format))

                for tile in frame["tiles"]:
                    tile_path = os.path.join(tiles_path, tile["outfile"])
                    if not os.path.isfile(tile_path):
                        continue
                    tile_buf = oiio.ImageBuf(str(tile_path))

                    oiio.ImageBufAlgo.paste(frame_buf, tile["coords"][0],
                                            tile["coords"][1], 0, 0, tile_buf)

                print("Writing {}".format(frame_path))

                try:
                    os.mkdir(os.path.dirname(frame_path))
                except FileExistsError:
                    pass
                frame_buf.write(str(frame_path))
            else:
                print("Could not find first tile. Aborting frame stitch")

            try:
                stitch_args = self.stitch_queue.get_nowait()
            except queue.Empty:
                print("Worker exiting")
                break
Beispiel #10
0
def generate_1d_LUT_image(ramp_1d_path,
                          resolution=1024,
                          min_value=0,
                          max_value=1):
    """
    Generates a 1D LUT image, i.e. a simple ramp, going from the min_value to 
    the max_value.

    Parameters
    ----------
    ramp_1d_path : str or unicode
        The path of the 1D ramp image to be written
    resolution : int, optional
        The resolution of the 1D ramp image to be written
    min_value : float, optional
        The lowest value in the 1D ramp
    max_value : float, optional
        The highest value in the 1D ramp

    Returns
    -------
    None
    """

    ramp = oiio.ImageOutput.create(ramp_1d_path)

    spec = oiio.ImageSpec()
    spec.set_format(oiio.FLOAT)
    # spec.format.basetype = oiio.FLOAT
    spec.width = resolution
    spec.height = 1
    spec.nchannels = 3

    ramp.open(ramp_1d_path, spec, oiio.Create)

    data = array.array('f',
                       '\0' * spec.width * spec.height * spec.nchannels * 4)
    for i in range(resolution):
        value = float(i) / (resolution - 1) * (
            max_value - min_value) + min_value
        data[i * spec.nchannels + 0] = value
        data[i * spec.nchannels + 1] = value
        data[i * spec.nchannels + 2] = value

    ramp.write_image(spec.format, data)
    ramp.close()
Beispiel #11
0
def ii_read_native_scanline_test():
    print "Starting ImageInput::read_native_scanline() tests..."
    pic_rns = oiio.ImageInput.create("../../../oiio-images/tahoe-gps.jpg",
                                     plugin_path)
    if pic_rns == None:
        print "Can't open test image, skipping read_native_scanline() tests"
        print
        return
    spec_rns = oiio.ImageSpec()
    pic_rns.open("../../../oiio-images/tahoe-gps.jpg", spec_rns)
    arr_rns = array.array("B", "\0" * spec_rns.scanline_bytes())
    # test 1
    if (pic_rns.read_native_scanline(0, 0, arr_rns)):
        print "Test 1 passed"
    else:
        print "Test 1 failed"
    # test 1.1
    # This test passes a buffer much larger than is actually needed.
    arr_rns2 = array.array("B", "\0" * spec_rns.image_bytes())
    if (pic_rns.read_native_scanline(0, 0, arr_rns2)):
        print "Test 1.1 passed"
    else:
        print "Test 1.1 failed"
    # test 2 (check if method returns False when given a non-existing scanline -1)
    if (not pic_rns.read_native_scanline(-1, 0, arr_rns)):
        print "Test 2 passed"
    else:
        print "Test 2 failed"
    # test 3
    test3 = "failed"
    a = "this is not a proper argument"
    try:
        pic_rns.read_native_scanline(a, 0, arr_rns)
    except:
        test3 = "passed"
    print "Test 3", test3
    # test 4  (a buffer of insufficient size is passed)
    test4 = "failed"
    arr_rns = array.array("B", "\0" * (spec_rns.scanline_bytes() - 1))
    try:
        pic_rns.read_native_scanline(0, 0, arr_rns)
    except IndexError:
        test4 = "passed"
    print "Test 4", test4

    print
Beispiel #12
0
def is_image_pixels_test():
    print "Starting ImageSpec::image_pixels tests..."
    spec = oiio.ImageSpec()
    # test 1
    if spec.image_pixels() == 0:
        print "Test 1 passed"
    else:
        print "Test 1 failed"
    # test 2 (call with wrong() argument)
    a = "not a proper argument"
    try:
        spec.image_pixels(a)
        print "Test 2 failed"
    except:
        print "Test 2 passed"

    print
Beispiel #13
0
def is_scanline_bytes_test():
    print "Starting ImageSpec::scanline_bytes tests..."
    spec = oiio.ImageSpec()
    # test 1
    if spec.scanline_bytes() == 0:
        print "Test 1 passed"
    else:
        print "Test 1 failed"
    # test 2 (call with wrong argument)
    a = "not a proper argument"
    try:
        spec.scanline_bytes(a)
        print "Test 2 failed"
    except:
        print "Test 2 passed"

    print
Beispiel #14
0
def oiio_get_buf(source, hash=None, force=False):
    """Check and load a source image with OpenImageIO's format reader.


    Args:
        source (str):       Path to an OpenImageIO compatible image file.
        hash (str):         Specify the hash manually, otherwise will be generated.
        force (bool):       When `true`, forces the buffer to be re-cached.

    Returns:
        ImageBuf: An `ImageBuf` instance or `None` if the image cannot be read.

    """
    common.check_type(source, str)

    if hash is None:
        hash = common.get_hash(source)

    if not force and ImageCache.contains(hash, BufferType):
        return ImageCache.value(hash, BufferType)

    # We use the extension to initiate an ImageInput with a format
    # which in turn is used to check the source's validity
    if '.' not in source:
        return None
    ext = source.split('.').pop().lower()
    if ext not in get_oiio_extensions():
        return None
    i = OpenImageIO.ImageInput.create(ext)
    if not i or not i.valid_file(source):
        i.close()
        return None

    # If all went well, we can initiate an ImageBuf
    config = OpenImageIO.ImageSpec()
    config.format = OpenImageIO.TypeDesc(OpenImageIO.FLOAT)

    buf = OpenImageIO.ImageBuf()
    buf.reset(source, 0, 0, config=config)
    if buf.has_error:
        print(buf.geterror())
        return None

    ImageCache.setValue(hash, buf, BufferType)
    return buf
Beispiel #15
0
def tiles_from_heatmap(frame, depth, threshold, heatmap_dir):
    # Load rendered heatmap
    frame_path = os.path.join(heatmap_dir, frame["outfile"])
    print("Frame path: {}".format(frame_path))
    frame_buf = oiio.ImageBuf(str(os.path.join(heatmap_dir, frame["outfile"])))
    orig_spec = oiio.ImageSpec(frame_buf.spec())
    orig_spec.width = frame["res_x"]
    orig_spec.full_width = frame["res_x"]
    orig_spec.height = frame["res_y"]
    orig_spec.full_height = frame["res_y"]

    resized_frame_buf = oiio.ImageBuf(orig_spec)
    oiio.ImageBufAlgo.resize(resized_frame_buf, frame_buf)

    # Create tiles from resized images
    quadtree = QuadSplit(Rect(0, resized_frame_buf.spec().width, 0, resized_frame_buf.spec().height), 1, depth, ["raycount"], threshold)
    quadtree.test_image(resized_frame_buf)
    return quadtree.get_quads()
Beispiel #16
0
def test_deep():
    # Test write and read of deep data
    # Let's try writing one
    print("\nWriting deep buffer...")
    deepbufout_spec = oiio.ImageSpec(2, 2, 5, oiio.FLOAT)
    deepbufout_spec.channelnames = ("R", "G", "B", "A", "Z")
    deepbufout_spec.deep = True
    deepbufout = oiio.ImageBuf(deepbufout_spec)
    deepbufout.set_deep_samples(x=1, y=0, z=0, nsamples=2)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=0, sample=0, value=0.42)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=4, sample=0, value=42.0)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=0, sample=1, value=0.47)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=4, sample=1, value=43.0)
    # Also insert some new samples
    deepbufout.deep_insert_samples(x=1, y=0, z=0, samplepos=1, nsamples=2)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=0, sample=1, value=1.1)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=1, sample=1, value=2.2)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=2, sample=1, value=2.3)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=3, sample=1, value=1.0)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=3, sample=1, value=42.25)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=0, sample=2, value=0.1)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=1, sample=2, value=0.2)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=2, sample=2, value=0.3)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=3, sample=2, value=1.0)
    deepbufout.set_deep_value(x=1, y=0, z=0, channel=3, sample=2, value=42.5)
    # But delete the first one
    deepbufout.deep_erase_samples(x=1, y=0, z=0, samplepos=1, nsamples=1)
    # Save
    deepbufout.write("deepbuf.exr")
    # And read it back
    print("\nReading back deep buffer:")
    deepbufin = oiio.ImageBuf("deepbuf.exr")
    deepbufin_spec = deepbufin.spec()
    dd = deepbufin.deepdata()
    for p in range(dd.pixels):
        ns = dd.samples(p)
        if ns > 1:
            print("Pixel", p // deepbufin_spec.width, p % deepbufin_spec.width,
                  "had", ns, "samples")
            for s in range(ns):
                print("Sample", s)
                for c in range(dd.channels):
                    print("\tc {0} : {1:.3f}".format(c, dd.deep_value(p, c,
                                                                      s)))
Beispiel #17
0
    def _create_mipmap(self, source_path, target_path):
        """
        Use OIIO to convert a given image into a mipmapped image.

        :param source_path: path to source image file
        :param target_path: path to write the mipmapped file to

        :return: bool (success of mipmap creation)
        """
        # cast here as OIIO has an issue with unicode strings (C++ matches types strictly)
        source_path = str(source_path)
        target_path = str(target_path)

        _img_input = oiio.ImageBuf(source_path)
        _target_spec = oiio.ImageSpec(_img_input.spec())
        _target_spec.attribute("maketx:filtername", "lanczos3")
        _target_spec.attribute("maketx:fixnan", "box3")

        return oiio.ImageBufAlgo.make_texture(oiio.MakeTxTexture, _img_input,
                                              target_path, _target_spec)
Beispiel #18
0
def test_multiimage():
    print("Writing multi-image file")
    spec = oiio.ImageSpec(128, 64, 3, "float")
    out = oiio.ImageOutput.create("multipart.exr")
    # Open with intent to write two subimages, each with same spec
    if not out.open("multipart.exr", (spec, spec)):
        print("Error on initial open:", out.geterror())
        return
    img = oiio.ImageBufAlgo.fill((0.5, 0.0, 0.0), spec.roi)
    if not img.write(out):
        print("Error on write:", img.geterror())
        return
    if not out.open("multipart.exr", spec, "AppendSubimage"):
        print("Error on open for append:", out.geterror())
        return
    img = oiio.ImageBufAlgo.fill((0.0, 0.5, 0.0), spec.roi)
    if not img.write(out):
        print("Error on write:", img.geterror())
        return
    out.close()
Beispiel #19
0
def write_image_cubemap(cubemap, filename):

    output = oiio.ImageOutput.create(filename)
    mode = oiio.Create
    size = cubemap[0].shape[0]
    # print "size {}".format(cubemap[0].shape[0])
    spec_rgba = oiio.ImageSpec(size, size, 3, oiio.FLOAT)

    for face in cubemap:
        output.open(filename, spec_rgba, mode)
        # can't transform to rgb
        s = face.shape[0]
        # delete the A from RGBA
        f = face.view(dtype=numpy.float32).reshape(s * s, 4)
        f = numpy.delete(f, 3, 1)
        buffer = numpy.getbuffer(f)
        output.write_image(oiio.FLOAT, buffer)
        mode = oiio.AppendSubimage

    output.close()
Beispiel #20
0
def save_image(filename, image):
  ext = get_path_ext(filename).lower()
  if ext == 'pfm':
    save_pfm(filename, image)
  else:
    output = oiio.ImageOutput.create(filename)
    if not output:
      raise RuntimeError('could not create image: "' + filename + '"')
    format = oiio.FLOAT if ext == 'exr' else oiio.UINT8
    spec = oiio.ImageSpec(image.shape[1], image.shape[0], image.shape[2], format)
    if ext == 'exr':
      spec.attribute('compression', 'piz')
    elif ext == 'png':
      spec.attribute('png:compressionLevel', 3)
    if not output.open(filename, spec):
      raise RuntimeError('could not open image: "' + filename + '"')
    # FIXME: copy is needed for arrays owned by PyTorch for some reason
    if not output.write_image(image.copy()):
      raise RuntimeError('could not save image')
    output.close()
def run_io_tests():
    # first we use ImageInput to produce data ImageOutput uses
    spec = oiio.ImageSpec()
    inp = oiio.ImageInput.create("../../../oiio-images/tahoe-gps.jpg",
                                 plugin_path)
    inp.open("../../../oiio-images/tahoe-gps.jpg", spec)
    desc = spec.format
    arr = array.array("B", "\0" * spec.image_bytes(True))
    inp.read_image(desc, arr)

    io_create_test()
    io_spec_test()
    io_open_test(spec)
    io_close_test(spec)
    io_write_image_test(arr, spec)  # lengthy operation
    io_copy_image_test(inp, spec)
    io_format_name_test(spec)
    io_supports_test(spec)
    io_error_message_test(spec)
    io_write_scanline_test()
Beispiel #22
0
def is_default_channel_names_test():
    print "Starting ImageSpec::default_channel_names() tests..."
    spec = oiio.ImageSpec()
    # test 1
    test1 = "passed"
    try:
        spec.default_channel_names()
        assert spec.channelnames == ()
    except:
        test1 = "failed"
    print "Test 1", test1
    # test 2
    a = "not a proper argument"
    test2 = "failed"
    try:
        spec.default_channel_names_test(a)
    except:
        test2 = "passed (wrong argument raised exception)"

    print
Beispiel #23
0
def maketx():
    Input = oiio.ImageBuf(
        "/s/prodanim/ta/assets/Character/huHuman/surface_texturing/surface_texturing/work/textures/testAces/huHuman_longSleevesShirt_smooth_1001_BaseColor.exr"
    )
    config = oiio.ImageSpec()
    config.set_format(oiio.HALF)
    oiio.ImageBufAlgo.colorconvert(Input, Input, 'linear_srgb',
                                   'Utility - sRGB - Texture')
    config.attribute("maketx:highlightcomp", 1)
    config.attribute("maketx:filtername", "lanczos3")
    config.attribute("maketx:opaque_detect", 1)
    config.attribute('maketx:forcefloat', 1)
    config.attribute('maketx:fileformatname', 'tx')
    config.attribute('maketx:incolorspace', 'srgb8')
    config.attribute('maketx:outcolorspace', 'acescg')
    Input.set_write_format(oiio.HALF)
    ok = oiio.ImageBufAlgo.make_texture(
        oiio.MakeTxTexture, Input,
        "/s/prodanim/ta/_sandbox/duda/tmp/crap/acescg_testC.tx", config)
    if not ok:
        print("error:", oiio.geterror())
Beispiel #24
0
def io_write_scanline_test():
    print "Running ImageInput::write_scanline() tests..."

    # create II instance and open a file
    spec_ws = oiio.ImageSpec()
    pic_ws = oiio.ImageInput.create("../../../oiio-testimages/tahoe-gps.jpg",
                                    plugin_path)
    pic_ws.open("../../../oiio-testimages/tahoe-gps.jpg", spec_ws)

    #create IO instance and open a file for writing
    out_ws = oiio.ImageOutput.create(
        "../../../oiio-testimages/tahoe-gps-scanline.jpg", plugin_path)
    out_ws.open("../../../oiio-testimages/tahoe-gps-scanline.jpg", spec_ws,
                False)
    desc_ws = spec_ws.format

    # test 1 (reads each scanline and writes it to a new file)
    # this tests several things, so it's quite good if it passed
    try:
        for i in range(spec_ws.height):
            arr_ws = array.array("B", "\0" * spec_ws.scanline_bytes())
            pic_ws.read_scanline(i, 0, desc_ws, arr_ws)
            out_ws.write_scanline(i, 0, desc_ws, arr_ws)
        print "Test 1 passed"
    except:
        print "Test 1 failed (raised exception)"
    out_ws.close()

    # test 2 (same as test 1, but will pass a nonexisting coordinate)
    try:
        for i in range(spec_ws.height):
            arr_ws = array.array("B", "\0" * spec_ws.scanline_bytes())
            pic_ws.read_scanline(i, 0, desc_ws, arr_ws)
            out_ws.write_scanline(i, 0, desc_ws, arr_ws)
        print "Test 1 passed"
    except:
        print "Test 1 failed (raised exception)"
    out_ws.close()

    print
Beispiel #25
0
def is_attribute_test():
    print "Running ImageSpec::attribute tests..."
    spec = oiio.ImageSpec()
    # test 1
    try:
        spec.attribute("test_attribute_int", 1)
        print "Test 1 passed"
    except:
        print "Test 1 failed (exception raised)"
    # test 2
    try:
        spec.attribute("test_attribute_float", 3.14)
        print "Test 2 passed"
    except:
        print "Test 2 failed (exception raised)"
    # test 3
    try:
        spec.attribute("test_attribute_string", "asd")
        print "Test 3 passed"
    except:
        print "Test 3 failed (exception raised)"
    # test 4
    try:
        spec.attribute("test_attribute_int", "a")
        print "Test 4 passed"
    except:
        print "Test 4 failed (exception raised)"
    # test 5 (wrong argument passed)
    a = ["not a proper argument"]
    try:
        spec.attribute(a, 1)
        print "Test 5 failed (accepted wrong argument)"
    except:
        print "Test 5 passed"

    print
Beispiel #26
0
def is_format_from_quantize_test():
    print "Starting ImageSpec::format_from_quantize tests..."
    spec = oiio.ImageSpec()
    #test 1 (calls without the class instance)
    try:
        desc = oiio.ImageSpec.format_from_quantize(0, 255, 0, 255)
        print "Test 1 passed"
    except:
        print "Test 1 failed"
    # test 2 (calls from instance)
    try:
        desc = spec.format_from_quantize(0, 255, 0, 255)
        print "Test 2 passed"
    except:
        print "Test 2 failed"
    # test 3 (call with wrong arguments)
    a = "not a proper argument"
    try:
        desc = spec.format_from_quantize(a)
        print "Test 3 failed (accepts wrong arguments)"
    except:
        print "Test 3 passed"

    print
Beispiel #27
0
def write (image, filename, format=oiio.UNKNOWN) :
    if not image.has_error :
        image.write (filename, format)
    if image.has_error :
        print ("Error writing", filename, ":", image.geterror())



######################################################################
# main test starts here

try:

    print ("Constructing to be a writeable 320x240,4 UINT16:")
    b = oiio.ImageBuf (oiio.ImageSpec(320,240,4,oiio.UINT16))
    print_imagespec (b.spec())
    print ("Resetting to be a writeable 640x480,3 Float:")
    b.reset (oiio.ImageSpec(640,480,3,oiio.FLOAT))
    print_imagespec (b.spec())
    print ("")

    # Test reading from disk
    print ("Testing read of ../common/textures/grid.tx:")
    b = oiio.ImageBuf ("../common/textures/grid.tx")
    print ("subimage:", b.subimage, " / ", b.nsubimages)
    print ("miplevel:", b.miplevel, " / ", b.nmiplevels)
    print ("channels:", b.nchannels)
    print ("name:", b.name)
    print ("file_format_name:", b.file_format_name)
    print ("deep:", b.deep)
Beispiel #28
0
    # test readtile
    print("Testing read_tile:")
    test_readtile("grid.tx")

    # test readscanlines
    print("Testing read_scanlines:")
    test_readimage(OIIO_TESTSUITE_IMAGEDIR + "/tahoe-gps.jpg",
                   method="scanlines")

    # test readtiles
    print("Testing read_tiles:")
    test_readimage("grid.tx", method="tiles")

    # test reading a raw buffer in native format, we should get back
    # an unsigned byte array.
    b = oiio.ImageBuf(oiio.ImageSpec(64, 64, 3, oiio.UINT16))
    oiio.ImageBufAlgo.fill(b, (1, 0, 0), (0, 1, 0), (0, 0, 1), (1, 1, 1))
    write(b, "testu16.tif", oiio.UINT16)
    b.set_write_tiles(32, 32)
    write(b, "testf16.exr", oiio.HALF)
    print("Test read_image native u16:")
    test_readimage("testu16.tif",
                   method="image",
                   type=oiio.UNKNOWN,
                   keep_unknown=True,
                   print_pixels=False)
    print("Test read_scanlines native u16:")
    test_readimage("testu16.tif",
                   method="scanlines",
                   type=oiio.UNKNOWN,
                   keep_unknown=True,
Beispiel #29
0
    for i in range(len(spec.extra_attribs)):
        if type(spec.extra_attribs[i].value) == str:
            print " ", spec.extra_attribs[
                i].name, "= \"" + spec.extra_attribs[i].value + "\""
        else:
            print " ", spec.extra_attribs[i].name, "=", spec.extra_attribs[
                i].value


######################################################################
# main test starts here

try:

    print "Constructing to be a writeable 320x240,4 UINT16:"
    b = oiio.ImageBuf(oiio.ImageSpec(320, 240, 4, oiio.UINT16))
    print_imagespec(b.spec())
    print "Resetting to be a writeable 640x480,3 Float:"
    b.reset(oiio.ImageSpec(640, 480, 3, oiio.FLOAT))
    print_imagespec(b.spec())
    print ""

    # Test reading from disk
    print "Testing read of grid.tx:"
    b = oiio.ImageBuf("../common/textures/grid.tx")
    print "subimage:", b.subimage, " / ", b.nsubimages
    print "miplevel:", b.miplevel, " / ", b.nmiplevels
    print "channels:", b.nchannels
    print "name:", b.name
    print "file_format_name:", b.file_format_name
    print "deep:", b.deep
Beispiel #30
0
def is_data_members_test():
    print "Starting tests of various ImageSpec data members..."
    spec = oiio.ImageSpec()
    # test 1
    if spec.height != 0:
        print "Test 1 failed"
    else:
        print "Test 1 passed"
    # test 2
    if spec.width != 0:
        print "Test 2 failed"
    else:
        print "Test 2 passed"

    # test 3
    if spec.x != 0:
        print "Test 3 failed"
    else:
        print "Test 3 passed"
    # test 4
    if spec.y != 0:
        print "Test 4 failed"
    else:
        print "Test 4 passed"
    # test 5
    if spec.z != 0:
        print "Test 5 failed"
    else:
        print "Test 5 passed"

    # test 6
    if spec.full_x != 0:
        print "Test 6 failed"
    else:
        print "Test 6 passed"
    # test 7
    if spec.full_y != 0:
        print "Test 7 failed"
    else:
        print "Test 7 passed"
    # test 8
    if spec.full_z != 0:
        print "Test 8 failed"
    else:
        print "Test 8 passed"

    # test 9
    if spec.full_width != 0:
        print "Test 9 failed"
    else:
        print "Test 9 passed"
    # test 10
    if spec.full_height != 0:
        print "Test 10 failed"
    else:
        print "Test 10 passed"
    # test 11
    if spec.full_depth != 0:
        print "Test 11 failed"
    else:
        print "Test 11 passed"

    # test 12
    if spec.tile_width != 0:
        print "Test 12 failed"
    else:
        print "Test 12 passed"
    # test 13
    if spec.tile_height != 0:
        print "Test 13 failed"
    else:
        print "Test 13 passed"
    # test 14
    if spec.tile_depth != 1:
        print "Test 14 failed"
    else:
        print "Test 14 passed"

    # test 15
    if spec.alpha_channel != -1:
        print "Test 15 failed"
    else:
        print "Test 15 passed"
    # test 16
    if spec.z_channel != -1:
        print "Test 16 failed"
    else:
        print "Test 16 passed"

    # test 17
    if spec.gamma != 1.0:
        print "Test 17 failed"
    else:
        print "Test 17 passed"

    # test 18
    if spec.quant_black != 0:
        print "Test 18 failed"
    else:
        print "Test 18 passed"
    # test 19
    if spec.quant_white != 255:
        print "Test 19 failed"
    else:
        print "Test 19 passed"
    # test 20
    if spec.quant_min != 0:
        print "Test 20 failed"
    else:
        print "Test 20 passed"
    # test 21
    if spec.quant_max != 255:
        print "Test 22 failed"
    else:
        print "Test 21 passed"

    # test 23
    if spec.nchannels != 0:
        print "Test 23 failed"
    else:
        print "Test 23 passed"

    # test 24
    test24 = ""
    try:
        assert spec.channelnames == ()
        spec.channelnames = ('c', 'm', 'y', 'k')
        assert spec.channelnames == ('c', 'm', 'y', 'k')
        test24 = "passed"
    except:
        test24 = "failed"
    print "Test 24", test24

    print