We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexSuggestions & BugsSoftware Bugs › 32 bit uncompressed TGAs Won't Load
Page Index Toggle Pages: 1
32 bit uncompressed TGAs Won't Load (Read 2651 times)
32 bit uncompressed TGAs Won't Load
Feb 15th, 2007, 10:50pm
 
Hi,
I'm trying to load some 32 bit, uncompressed TGA files (some saved from Photoshop CS 2, others saved from Apple's Preview) and not one of them will load. All have alpha channels and none are compressed. I'm not absolutely sure if this is a bug (or I would have put it in the bug database, but it may be just me). Can anyone else confirm this or tell me what I'm doing wrong?

here's a sample TGA file:
http://temp.duodec.net/Explosion1.tga
Re: 32 bit uncompressed TGAs Won't Load
Reply #1 - Feb 16th, 2007, 12:11pm
 
jep. i can't get it to load either (osx 10.4, P_0124).

i tried several different versions (RLE / no RLE) / (alpha / no alpha), none loaded.

think you should file a bug report for this and attach the image for ben ...

F
Re: 32 bit uncompressed TGAs Won't Load
Reply #2 - Feb 16th, 2007, 2:50pm
 
generally, only tga images that are created by processing are going to work, i should update the reference to say that. use png instead.
Re: 32 bit uncompressed TGAs Won't Load
Reply #3 - Feb 17th, 2007, 2:58am
 
Hmm, ok. It's rather important to me for integration with another program. Well, I'll get my own TGA loader that opens my files. I have one in C that shouldn't take more than a few minutes to port.

If I get a decent working TGA loading function in processing should I post it here to possibly be added to processing. I might be able to get one that works with more types of TGA?
Re: 32 bit uncompressed TGAs Won't Load
Reply #4 - Feb 17th, 2007, 3:23am
 
interesting... what sort of process are you running, i.e. is this something that others will run into as well? tga support was implemented as a means for a better option than uncompressed tiff, which was causing problems with some adobe products.

offhand, my guess is that your file is using the 'normal' row order for tga (starting at the bottom), i'd have to take a look, though.

if you're gonna write the code, then definitely post, because it'll be useful to someone else. inclusion in PApplet would hinge on how small the changes are--since tga isn't a huge priority (unless your process is something that more people will be using), it's less likely to get more code.
Re: 32 bit uncompressed TGAs Won't Load
Reply #5 - Feb 19th, 2007, 3:09am
 
The "processess" is unlikely to be used enough to merit inclusion in processing. I simply have a C program that uses TGAs (and no other format) and it's more convenient for me to be able to import the data files and images without conversion. I am making a tool for editing data files attached to the TGAs. Again, unlikely to be used too often. I'll post the code though when I get to it.
Re: 32 bit uncompressed TGAs Won't Load
Reply #6 - Feb 19th, 2007, 2:51pm
 
verified that it's the y-ordering issue.. you can actually use this (pre-0115) version of the tga loader to load it properly. i'll hack this back into the loader since it's functionality that we lost and will only take a couple of lines to fix.

Code:

PImage loadImageTGA(String filename) {
// load image file as byte array
byte[] buffer = loadBytes(filename);
if (buffer == null) return null;

// check if it's a TGA and has 8bits/colour channel
//if (buffer[2] == 2 && buffer[17] == 8) {
// [toxi20050929] changed format validation
// only number of bits/pixel are checked now...
if (buffer[2] == 2 && (buffer[16] == 24 || buffer[16]==32 )) {
// get image dimensions
int w = ((buffer[13] & 0xff) << 8) + (buffer[12] & 0xff);
int h = ((buffer[15] & 0xff) << 8) + (buffer[14] & 0xff);
// check if image has alpha
boolean hasAlpha=(buffer[16] == 32);

// setup new image object
PImage img = new PImage(w,h);
img.format = (hasAlpha ? ARGB : RGB);

// targa's are written upside down, so we need to parse it in reverse
int index = (h-1) * w;
// actual bitmap data starts at byte 18
int offset = 18;

// read out line by line
for (int y = h-1; y >= 0; y--) {
for (int x = 0; x < w; x++) {
img.pixels[index + x] =
(buffer[offset++] & 0xff) |
((buffer[offset++] & 0xff) << 8) |
((buffer[offset++] & 0xff) << 16) |
(hasAlpha ? ((buffer[offset++] & 0xff) << 24) : 0xff000000);
}
index -= w;
}
return img;
}
System.err.println("loadImage(): bad targa image format");
return null;
}
Re: 32 bit uncompressed TGAs Won't Load
Reply #7 - Feb 19th, 2007, 4:06pm
 
now fixed for 0125.
Page Index Toggle Pages: 1