You're right, works perfectly !
Thumbnail generation is down from 180s to 14s on a decent size asset :)

Thx for the help,
Alexis

2018-03-12 13:25 GMT+01:00 Daniel Flehner Heen <flehnerhee...@gmail.com>:

> Hey!
>
> Someone with deeper knowledge should correct me if I'm wrong here, but I
> don't think you read the entire image upon initialization of an
> ImageBuf(filename). It only loads the image upon certain function calls.
>
> So with some luck you could do the following without too much IO:
>
> # Open the buffer
> buf = oiio.ImageBuf(filename)
>
> # Find miplevel of choice with your own code
> #buf.nmiplevels
> # MIP = ??
>
> # Load the desired miplevel
> buf.reset(filename, miplevel=MIP)
> buf.write(newfilename.jpg)
> #------
>
> There's also a ImageInput.seek_subimage(subimage, miplevel) function that
> does't crash but returns False if you pass invalid an level.
>
> I highly recommend looking at the docs for your version of OIIO. For tha
> later versions pretty much everything for the python bindings are well
> documented and you can always look at the C++ parts for a deeper
> understanding of whats going on behind the scenes.
> https://github.com/OpenImageIO/oiio/blob/RB-1.8/src/doc/openimageio.pdf
>
>
> On Mon, Mar 12, 2018 at 10:50 AM, Alexis PRAYEZ <apra...@brunchstudio.tv>
> wrote:
>
>> Hi Daniel,
>>
>> Thx for the tip. Looks like it works indeed, but how do I get the list of
>> mipmap levels without loading the full file ? I can't find such information
>> in ImageInput
>> ImageBuf.nmiplevels contains the info I need, but by then the buffer has
>> already been loaded ...
>> And trying to read an invalid level makes the python interpreteur crash
>> so I can't "try first, ask for forgiveness afterwards"
>>
>> Cheers,
>>
>> 2018-03-12 10:31 GMT+01:00 Daniel Flehner Heen <flehnerhee...@gmail.com>:
>>
>>> Hi!
>>>
>>> I haven't done this my self, but in the docs for 1.8.x it says that
>>> ImageBuf  may be initialized with defined subimage and/or miplevel.
>>>
>>> buf = oiio.ImageBuf(filename, subimage, miplevel)
>>>
>>> Hope this helps
>>>
>>> On Mon, Mar 12, 2018 at 10:22 AM, Alexis PRAYEZ <apra...@brunchstudio.tv
>>> > wrote:
>>>
>>>> Hi all,
>>>>
>>>> New around here, even thou I worked with oiio occasionally over the
>>>> last years, but I'am kinda stuck.
>>>> Someone asked almost the same question a while ago (
>>>> http://lists.openimageio.org/pipermail/oiio-dev-openimageio.
>>>> org/2016-December/000832.html ) and the bottom line was
>>>>
>>>>>
>>>>> You can't "get an ImageBuf from an ImageInput", but you shouldn't need
>>>>> to
>>>>
>>>>
>>>> So it means I am probably doing something wrong:
>>>>
>>>> I am generating jpeg previews from hundreds of textures (exr, tx ...)
>>>> and this is painfully slow (the process is bound by network, as reading a
>>>> 200mb texture from the server is 10 times slower than doing the resizing.
>>>>
>>>> Since most of these textures have already been mipmapped, I would like
>>>> to only load the 512*512 mipmap level and write it back. But from what I
>>>> understood only ImageInput allows you choose what to load.
>>>> If I read all pixels from the ImageInput then "manually" create an
>>>> ImageBuf from it (requiring an extra numpy convert of the data) it works
>>>> but feel  a bit convoluted.
>>>>
>>>> Is there a better way to do this ?
>>>>
>>>> Cheers,
>>>>
>>>> --
>>>>
>>>> Alexis Prayez
>>>>
>>>> 41 rue de l'Echiquier - 75010 PARIS
>>>> <http://maps.google.com/maps?q=41+rue+%C3%A9chiqiuer+75010>
>>>> http://www.brunchstudio.tv/
>>>>
>>>> STATEMENT OF CONFIDENTIALITY
>>>> The information contained in this electronic message and any
>>>> attachments to this message are intended for the exclusive use of the
>>>> addressee(s) and may contain confidential or privileged information.
>>>> If you are not the intended recipient, you are hereby notified that any
>>>> dissemination, distribution or copying of this e-mail and any attachment(s)
>>>> is strictly prohibited. Please reply to the sender and destroy all copies
>>>> of this message and any attachments from your system.
>>>>
>>>> Please consider the environment before printing this e-mail.
>>>>
>>>> _______________________________________________
>>>> Oiio-dev mailing list
>>>> Oiio-dev@lists.openimageio.org
>>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>>>
>>>>
>>>
>>>
>>> --
>>> -Daniel
>>>
>>> _______________________________________________
>>> Oiio-dev mailing list
>>> Oiio-dev@lists.openimageio.org
>>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>>
>>>
>>
>>
>> --
>>
>> Alexis Prayez
>>
>> 41 rue de l'Echiquier - 75010 PARIS
>> <http://maps.google.com/maps?q=41+rue+%C3%A9chiqiuer+75010>
>> http://www.brunchstudio.tv/
>>
>> STATEMENT OF CONFIDENTIALITY
>> The information contained in this electronic message and any attachments
>> to this message are intended for the exclusive use of the addressee(s) and
>> may contain confidential or privileged information.
>> If you are not the intended recipient, you are hereby notified that any
>> dissemination, distribution or copying of this e-mail and any attachment(s)
>> is strictly prohibited. Please reply to the sender and destroy all copies
>> of this message and any attachments from your system.
>>
>> Please consider the environment before printing this e-mail.
>>
>> _______________________________________________
>> Oiio-dev mailing list
>> Oiio-dev@lists.openimageio.org
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>>
>>
>
>
> --
> -Daniel
>
> _______________________________________________
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org
>
>


-- 

Alexis Prayez

-- 

41 rue de l'Echiquier - 75010 PARIS 
<http://maps.google.com/maps?q=41+rue+%C3%A9chiqiuer+75010>
http://www.brunchstudio.tv/

STATEMENT OF CONFIDENTIALITY
The information contained in this electronic message and any attachments to 
this message are intended for the exclusive use of the addressee(s) and may 
contain confidential or privileged information. 
If you are not the intended recipient, you are hereby notified that any 
dissemination, distribution or copying of this e-mail and any attachment(s) 
is strictly prohibited. Please reply to the sender and destroy all copies 
of this message and any attachments from your system. 

Please consider the environment before printing this e-mail.
_______________________________________________
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to