PDA

View Full Version : Read image size error



clintonman
09-25-2012, 07:21 PM
This script loads an image from disk then attempts to display the size, but I get an error when trying to read the size. Any ideas?

Traceback (most recent call last):
File "C:\Program Files\NewTek\LightWave11.0\support\plugins\scripts \Python\Layout\Generic\load_image.py", line 33, in process
self._imagelist.size(self._imageID, self._xsize, self._ysize)
File "pcore.py", line 9180, in size
TypeError: in method 'LWImageList_size', argument 3 of type 'int *'

#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

"""
This is a LightWave Generic plug-in that loads an image.
"""

import sys
import lwsdk

__author__ = ""
__date__ = ""
__copyright__ = ""
__version__ = ""
__maintainer__ = ""
__email__ = ""
__status__ = ""
__lwver__ = ""

class load_image(lwsdk.IGeneric):
def __init__(self, context):
super(load_image, self).__init__()
self._imagelist = ""
self._imageID = ""
self._xsize = 0
self._ysize = 0

# LWGeneric -------------------------------------------
def process(self, ga):
self._imagelist = lwsdk.LWImageList()
self._imageID = self._imagelist.load('D:\\videoTuts\\tdw134-script\\Script Doctor\\HDR\\stwist_norton_HDR.tiff')
self._imagelist.size(self._imageID, self._xsize, self._ysize)
print 'xsize % ysize %' % self._xsize, self._ysize

return lwsdk.AFUNC_OK

ServerTagInfo = [
( "Python Load Image", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Load Image", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.GenericFactory("LW_PyLoadImage", load_image) : ServerTagInfo }

BigHache
09-26-2012, 07:15 PM
I tried to pick this apart. It seems that for some reason the size() method is not receiving integers. I even removed the variables and input '1', obviously an int, and still got a type error.

BigHache
09-27-2012, 09:05 PM
OK I dug a bit more. I don't think the size() method is used for what you're trying to do. I think that's why it's not working.

clintonman
09-28-2012, 09:06 AM
This is where I found the info for it in my LW installation:

file:///C:/Program%20Files/NewTek/LightWave11.0/sdk/lwsdk11.0/html/globals/imglist.html

"size( image, width, height )
Returns the width and height of the image in pixels."

I was thinking the problem was maybe because it's expecting a pointer to integers instead of actual integers:
"void (*size) (LWImageID, int *w, int *h);"

BigHache
09-29-2012, 05:00 PM
Yes but the method is asking for three arguments. You supplied the image but still have to get the width and height, then supply the method with those.

From LightWave11.0/sdk/lwsdk11.0/html/imageio.html
"The width and height are the number of pixels in a scanline and the number of scanlines"

I don't know how to have Python do this yet.

clintonman
02-01-2013, 03:38 PM
It's fixed in version 11.5 :D
It read in the image dimensions properly.



#! /usr/bin/env python
# -*- Mode: Python -*-
# -*- coding: ascii -*-

"""
This is a LightWave Generic plug-in that loads an image.
"""

import sys
import lwsdk

__author__ = ""
__date__ = ""
__copyright__ = ""
__version__ = ""
__maintainer__ = ""
__email__ = ""
__status__ = ""
__lwver__ = ""

class load_image(lwsdk.IGeneric):
def __init__(self, context):
super(load_image, self).__init__()
self._imagelist = ""
self._imageID = ""
self._xsize = 0
self._ysize = 0

# LWGeneric -------------------------------------------
def process(self, ga):
self._imagelist = lwsdk.LWImageList()
self._imageID = self._imagelist.load('D:\\videoTuts\\tdw134-script\\Script Doctor\\HDR\\stwist_norton_HDR.tiff')
#self._imagelist.size(self._imageID, self._xsize, self._ysize)
(self._xsize, self._ysize) = self._imagelist.size(self._imageID)
print 'xsize %f ysize %f' % (self._xsize, self._ysize)

return lwsdk.AFUNC_OK

ServerTagInfo = [
( "Python Load Image", lwsdk.SRVTAG_USERNAME | lwsdk.LANGID_USENGLISH ),
( "Load Image", lwsdk.SRVTAG_BUTTONNAME | lwsdk.LANGID_USENGLISH ),
( "Utilities/Python", lwsdk.SRVTAG_MENU | lwsdk.LANGID_USENGLISH )
]

ServerRecord = { lwsdk.GenericFactory("LW_PyLoadImage", load_image) : ServerTagInfo }

BigHache
02-06-2013, 05:32 AM
Very cool. Thanks for the update. I haven't had time to sit down with it yet.