PDA

View Full Version : How to save an image using the image filter (with Targaman???)



Red_Oddity
03-27-2003, 10:53 AM
'kay...i'm getting sick pressing the save image as button a gazzillion times a day when working, so i decided i would 'attempt' to write a plugin (using LScript...can't do C or otherwise fancy programming, just your average copy paste programming).
The plugin has to simply save out the RGB(A) image buffer...easypeasy one might think...

Allas, not so, i've been screwing about with TargaMan for a couple of hours now, and i'm coming to the simple conclusion my highly evolved monkey brain doesn't quite grasp the principle behind it...heck, can't even get the damn thing to work, let alone get an error, it just doesn't seem to exist according LW...

Any help would be REALLY apreciated.



ps. In case you're wondering, why not just use the normal BufferSaver...welll, i like to see what i've done all day and not end up with a directory with just ONE file (frame 0).
That reminds me, is it even possible to append the day and time to a filename in LScript...other wise i might asswell quit now and ask someone nicely to do it in C....

pretty please???

faulknermano
03-29-2003, 08:09 AM
red_oddity: i have not used targaman to date, so i am unfamiliar with that Object Agent. not everybody has used it, so it will help for you to be specific with your problem. could you post the code that doesnt work and / or the error message that appears? what problems EXACTLY are you having?

jeremyhardin
03-17-2006, 04:08 PM
digging up an old thread here.

did targaman get included in lscript at any point?

faulknermano
03-17-2006, 06:09 PM
afaik, no. but it was, for a long time, available as a download. otoh, depending on how you look at it, many of the other object agents bob hood wrote he tried putting the functionality into lscript at some point, and at some degree. i think the image object agent allows you some of the targaman functionality. but, just like SceneMan, it doesnt give you everything. SceneMan was an awesome tool i miss.

jeremyhardin
03-17-2006, 06:37 PM
well, now i've found a way to write .tga files (modifying a Chrome Cow UDF), but it only works up to a certain size. beyond that it starts writing the wrong information. could this be the infamous byte swapping problem?

the command:
image.writeByte(320); //for the image width

is writing 064 instead. The thing is...it works with:
image.writeByte(160); //for the image width

ideas?

jeremyhardin
03-17-2006, 07:45 PM
nevermind. the problem was the 255 limit. so it wrapped around. I got a workaround sorted.

Red_Oddity
03-28-2006, 09:10 AM
Care to share Jeremy? :)

jeremyhardin
03-28-2006, 09:41 AM
sure! it's basically the chrome cow udf here (http://www.chromecow.com/uploads/udfs/tgaSwatch.ls), only i fixed it to work with larger image resolutions.

specifically i changed this part of the header-writing...


temptga.writeByte(16); //____x width 16 pixels
temptga.writeByte(0);
temptga.writeByte(16); //____y height 16 pixels
temptga.writeByte(0);
temptga.writeByte(24); //____bit-depth 24
temptga.writeByte(0);


to this



width_var = ifo.width;
height_var = ifo.height;

imgSeq.writeByte(width_var); //____x width
if(width_var <= 255)
{
width_multiplier = 0;
}
else
{
width_multiplier = integer(width_var/256);
}
imgSeq.writeByte(width_multiplier);
imgSeq.writeByte(height_var); //____y height
if(height_var <= 255)
{
height_multiplier = 0;
}
else
{
height_multiplier = integer(height_var/256);
}
imgSeq.writeByte(height_multiplier);
imgSeq.writeByte(24); //____bit-depth 24
imgSeq.writeByte(0);

Red_Oddity
03-28-2006, 01:59 PM
Aaaah, drat...i already had that implemented...i had hoped for a somewhat more elegant way of writing out files.
It would be so nice to have access to all the save output modes in LScript, alas...

jeremyhardin
03-28-2006, 03:16 PM
indeed. tga is the only way i'm familiar with. in theory you could do .iff since the .obj format follows .iff standards, but I haven't looked at it in depth. ****, I haven't even got alpha's working in .tga

Red_Oddity
03-29-2006, 01:49 AM
I had this working i believe (don't quote me)

2 years ago i wrote this auto saver (i believe i had the alpha's working, even though they are turned off right now)



//-----------------------------------------
// TGA Autosave v0.2
// by Sven Neve
//

@version 2.5
@warnings
@script image
@name autosave

var filenaam = "previews/dump";


process: ifo
{
// called when a frame is completely rendered

moninit(ifo.height) unless runningUnder() == SCREAMERNET;

datum = date();
(d1,d2,d3) = date();
bestandext = strright("00"+d1,2)+strright("00"+d2,2)+strright("0000"+d3,4);
(d1,d2,d3) = time();
bestandext = bestandext + strright("00"+d1,2)+strright("00"+d2,2)+strright("00"+d3,2);
// bestandnaam = getdir(PREVIEWSDIR)+"/dump"+ bestandext + ".tga";
bestandnaam = filenaam + bestandext + ".tga";

hs1 = integer(ifo.height / 256);
hs2 = (ifo.height - (256 * hs1));
ws1 = integer(ifo.width / 256);
ws2 = (ifo.width - (256 * ws1));
bits = 24;

f= File(bestandnaam , "wb");

f.writeByte(0); //identsize
f.writeByte(0); //colourmaptype
f.writeByte(2); //imagetype
f.writeByte(0); //colourmapstart
f.writeByte(0);
f.writeByte(0); //colourmaplength
f.writeByte(0);
f.writeByte(bits); //colourmapbits
f.writeByte(0); //xstart
f.writeByte(0);
f.writeByte(0); //ystart
f.writeByte(0);
f.writeByte(ws2); //width
f.writeByte(ws1);
f.writeByte(hs2); //height
f.writeByte(hs1);
f.writeByte(bits); //bits
f.writeByte(0); //descriptor

for(i = ifo.height;i >= 1;--i)
{
for(j = 1;j <= ifo.width;++j)
{
// red = integer(round((ifo.red[j,i]*256),0));
// green = integer(round((ifo.green[j,i]*256),0));
// blue = integer(round((ifo.blue[j,i]*256),0));
// alpha = integer(ifo.alpha[j,i]*255);
red = integer(ifo.red[j,i]*255);
green = integer(ifo.green[j,i]*255);
blue = integer(ifo.blue[j,i]*255);
// alpha = integer(ifo.alpha[j,i]*255);
f.writeByte(min(255,blue));
f.writeByte(min(255,green));
f.writeByte(min(255,red));
}
if(runningUnder() != SCREAMERNET)
if(monstep())
return;
}
f.close();
// monend() unless runningUnder() == SCREAMERNET;
}

options
{
reqbegin("autosave v0.2");
c0 = ctlfilename("Filename",filenaam);
return if !reqpost();
filenaam = getvalue(c0);
reqend();
}



Also, this helped me alot : http://organicbit.com/closecombat/formats/tga.html

Red_Oddity
03-29-2006, 02:19 AM
Okay, just checked the script (next time i'll do that BEFORE posting) as simply setting the bits to 32 and writing out the alpha aswell, does indeed, NOT work...how odd...i can swear i had it working...

Red_Oddity
03-29-2006, 03:25 AM
DOH!, stupid descriptor bits, now i remember...it should be set to 8

so that would be :



//-----------------------------------------
// TGA Autosave v0.2
// by Sven Neve
//

@version 2.5
@warnings
@script image
@name autosave

var filenaam = "previews/dump";


process: ifo
{
// called when a frame is completely rendered

moninit(ifo.height) unless runningUnder() == SCREAMERNET;

datum = date();
(d1,d2,d3) = date();
bestandext = strright("00"+d1,2)+strright("00"+d2,2)+strright("0000"+d3,4);
(d1,d2,d3) = time();
bestandext = bestandext + strright("00"+d1,2)+strright("00"+d2,2)+strright("00"+d3,2);
// bestandnaam = getdir(PREVIEWSDIR)+"/dump"+ bestandext + ".tga";
bestandnaam = filenaam + bestandext + ".tga";

hs1 = integer(ifo.height / 256);
hs2 = (ifo.height - (256 * hs1));
ws1 = integer(ifo.width / 256);
ws2 = (ifo.width - (256 * ws1));
bits = 32;

f= File(bestandnaam , "wb");

f.writeByte(0); //identsize
f.writeByte(0); //colourmaptype
f.writeByte(2); //imagetype
f.writeByte(0); //colourmapstart
f.writeByte(0);
f.writeByte(0); //colourmaplength
f.writeByte(0);
f.writeByte(0); //colourmapbits (is ignored)
f.writeByte(0); //xstart
f.writeByte(0);
f.writeByte(0); //ystart
f.writeByte(0);
f.writeByte(ws2); //width
f.writeByte(ws1);
f.writeByte(hs2); //height
f.writeByte(hs1);
f.writeByte(bits); //bits
f.writeByte(8); //descriptor // <-- DUH, Bits 3-0 - number of attribute bits associated with each pixel.
// For the Targa 24, it should be 0. For Targa 32, it should be 8.

for(i = ifo.height;i >= 1;--i)
{
for(j = 1;j <= ifo.width;++j)
{
red = integer(ifo.red[j,i]*255);
green = integer(ifo.green[j,i]*255);
blue = integer(ifo.blue[j,i]*255);
alpha = integer(ifo.alpha[j,i]*255);
f.writeByte(min(255,blue));
f.writeByte(min(255,green));
f.writeByte(min(255,red));
f.writeByte(min(255,alpha));
}
if(runningUnder() != SCREAMERNET)
if(monstep())
return;
}
f.close();
// monend() unless runningUnder() == SCREAMERNET;
}

options
{
reqbegin("autosave v0.2");
c0 = ctlfilename("Filename",filenaam);
return if !reqpost();
filenaam = getvalue(c0);
reqend();
}

jeremyhardin
03-29-2006, 08:26 AM
nice one! since you have to write out the rgb in reverse order, i would have guessed the alpha comes first (i.e. ABGR) rather than what you have there (BGRA). there's a little trial/error saved. :thumbsup:

Red_Oddity
03-30-2006, 05:00 AM
I do? Oh yeah... :D

I still wish there was a way to make this a lot more transparant, right now the plugin just takes too much time...


Even with the 'if then' routine for the progress removed and the thing compiled a blank empty scene at 640x480 takes 4.5 seconds.