Crop transform stops working in renpy 8?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Crop transform stops working in renpy 8?

#1 Post by zmook » Fri Jun 03, 2022 7:27 pm

Can anyone tell me what might have changed between renpy 7.4 and 8.0 to make this code stop working? Is there a subtle python 3 thing, or a change in Displayable handling?

Expected behavior is to loop through a list of image pathnames, crop square thumbnails out of them, and display them in a grid. In renpy 7.4 this worked. In renpy 8, *only the originally square images work*. For any rectangular image, a blank (or missing) thumb is produced. I find that strange.

Code: Select all

                vpgrid:
                    for (i,img) in enumerate(pinups):
                        python:
                            (w,h) = get_image_size(img)
                            if w < h:
                                rect = (0, (h-w)//2, w, w) 	# integer division for py3
                            else:
                                rect = ((w-h)//2, 0, h, h)
                            
                            # renpy 7.4: the trailing nultransform seems necessary to make At()
                            # return a Displayable (ATLTransform) rather than a Transform 
                            # (can't say I really understand why).
                            # if img is not a Displayable, then 'brighten' doesn't work
                            img = At(img, \
                                        Transform(crop=rect, size=(thumbsz,thumbsz)),
                                        nultransform)
                    
                        imagebutton:
                            xysize thumbsz,thumbsz
                            idle img #Fixed(img,Text("in progress", align=(0.95,0.05)))
                            hover At(img, brighten)
                            action [SetVariable("g_current_pz",('bonus',i+1)), Start()]
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Crop transform stops working in renpy 8?

#2 Post by PyTom » Fri Jun 03, 2022 11:33 pm

There was a change that made crops using floating point numbers relative, so that 2.0 means "twice the image size" rather than "two pixels".

If that's not the cause of this, It's also possible that an issue was introduced. If you can put together a small standalone demo, that would help a lot in debugging this. (That is, a small game with the script and image files I can just download and run to understand this problem.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Crop transform stops working in renpy 8?

#3 Post by zmook » Fri Jun 03, 2022 11:49 pm

PyTom wrote:
Fri Jun 03, 2022 11:33 pm
There was a change that made crops using floating point numbers relative, so that 2.0 means "twice the image size" rather than "two pixels".
Okay, that was half of the problem. Once I coerce the return values of render.get_size() to integers, square crops are produced.

However, it seems that the 'nultransform' trick I was using, has also stopped working. My buttons have idle images, but no hover images: 'At(img, brighten)' is returning a blank image. 'brighten' is a simple transform:

Code: Select all

transform brighten:
    matrixcolor BrightnessMatrix(0.1)
I have obviously had this problem before, witness the comment I left for myself in the code above, but I no longer remember where I got the 'nultransform' trick from or why it was supposed to work.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Crop transform stops working in renpy 8?

#4 Post by PyTom » Sat Jun 04, 2022 11:54 pm

I don't understand what nulltransform was supposed to do, so I'm not sure I can help you with that.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Crop transform stops working in renpy 8?

#5 Post by zmook » Sun Jun 05, 2022 9:42 am

PyTom wrote:
Sat Jun 04, 2022 11:54 pm
I don't understand what nulltransform was supposed to do, so I'm not sure I can help you with that.
Oh, whoops. It's literally:

Code: Select all

transform nultransform:
    pass
I don't understand why it worked, either.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Crop transform stops working in renpy 8?

#6 Post by zmook » Sun Jun 05, 2022 11:18 am

I think I have found an answer. I'm not sure if it's the recommended method, but it seems to work.

It seems to be the case that At() returns an ATLTransform object, which can be used as a Displayable for some purposes, but *not* passed back to another At() call. I'm not sure what Fixed() is really doing here, but it seems to serve to convert an ATLTransform object to something that *can* be passed to At().

Code: Select all

transform crop_thumb(rect, new_size):
    crop rect
    size new_size

transform brighten(factor=0.1):
    matrixcolor BrightnessMatrix(factor)

Code: Select all

                        python:
                            (w,h) = get_image_size(img)
                            if w < h:
                                rect = (0, (h-w)//2, w, w)
                            else:
                                rect = ((w-h)//2, 0, h, h)
                            # wrap the first transform in a Fixed, otherwise the second doesn't work (renpy 8.0)
                            img = Fixed(At(img, crop_thumb(rect, (thumbsz,thumbsz))))
                            hover_img = At(img, brighten(0.2))
                    
                        imagebutton:
                            xysize thumbsz,thumbsz
                            idle img 
                            hover hover_img
                            action [SetVariable("g_current_pz",(bonus_key,i+1)), Start()]
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

Post Reply

Who is online

Users browsing this forum: No registered users