Knowing if userdata is really an image

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Knowing if userdata is really an image

Post by Ubermann » Sun Jan 27, 2013 12:40 pm

How?

So I can predict and avoid app crashes?

Because doing type(myImage) only tell me that it is userdata.

I could run through all elements in userdata and check if all of them are {r, g, b, a}, but since i'm implementing support for CMYK and HSV colors, it would be too much time invested for just that.

Thanks in advance.

Santos
Party member
Posts: 383
Joined: Sat Oct 22, 2011 7:37 am

Re: Knowing if userdata is really an image

Post by Santos » Sun Jan 27, 2013 12:48 pm

Assuming we're talking about Image objects, does this work?

Code: Select all

if image:typeOf("Image") then

User avatar
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

Re: Knowing if userdata is really an image

Post by Ubermann » Sun Jan 27, 2013 9:04 pm

Santos wrote:Assuming we're talking about Image objects, does this work?

Code: Select all

if image:typeOf("Image") then
No.

It is in fact ImageData type of object.
And when doing type() it just returns "userdata".
But I need to know if it really contains data that is image data or not.

User avatar
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

Re: Knowing if userdata is really an image

Post by ejmr » Sun Jan 27, 2013 9:11 pm

Ubermann wrote:But I need to know if it really contains data that is image data or not.
If you want there to be zero doubt about the nature of the data I don't see any other option besides reading the entire file and verifying it, byte-by-byte if you have to. Popular image formats have header metadata you could look at, but if you base the test just on that you're trusting the rest of the data to be uncorrupted.
ejmr :: Programming and Game-Dev Blog, GitHub
南無妙法蓮華經

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests