Where does the error occur? On the call to rename?
I think that what's happening is that your ImageBuf is backed by an ImageCache,
which is holding the file open. That's my current hypothesis anyway.
I have two suggestions, either one might work:
1. Read the file explicitly, and use the 'force' parameter to read it fully
without being backed by an ImageCache.
img = oiio.ImageBuf(DIR_PATH+IN_FILE)
img.read (force=True)
2. Tell the ImageCache to close and release the file by invalidating it:
write_image(img, DIR_PATH+out_file)
oiio.ImageCache().invalidate (DIR_PATH+IN_FILE)
(Note: the default ImageCache() constructor will retrieve the "shared" one.)
> On Apr 11, 2018, at 7:39 AM, Stéphane Bertrand <[email protected]> wrote:
>
> hi all,
>
> i've this simple script, inpire by snippet in the docs :
>
> import os
> import OpenImageIO as oiio
>
>
> DIR_PATH = r"D:\Seq02\Scn01\Shot01\Left\pass\Decor\\"
> IN_FILE = "Seq02_Scn01_Shot01_Decor_0000.exr"
>
>
> ext = IN_FILE.rfind(".")
> out_file = IN_FILE[:ext]+ ".tmp" + IN_FILE[ext:]
>
>
> def write_image (image, filename, format=oiio.UNKNOWN) :
> if not image.has_error :
> image.set_write_format (format)
> image.write (filename)
> if image.has_error :
> print("Error writing", filename, ":", image.geterror())
>
> img = oiio.ImageBuf(DIR_PATH+IN_FILE)
> img.specmod().attribute("compression", "dwaa")
> write_image(img, DIR_PATH+out_file)
>
> os.remove(DIR_PATH+IN_FILE)
> os.rename(DIR_PATH+out_file, DIR_PATH+IN_FILE)
>
> it's a simple script for inplace convert with dwa compression a EXR file
> but i've a PermissionError, my own process have hands on my file
> i'll try to add
> img.reset(oiio.ImageSpec())
> for free my image
> but not
>
> thx for your help
> Stéphane
>
>
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
--
Larry Gritz
[email protected]
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org