Crash when attempting to ifo.copy()

vncnt

Well-known member
Tried to run Image Filter example #2 from the LScript documentation:

process: ifo
{
buf1 = ifo.copy(1,1,ifo.width / 2,ifo.height);
buf2 = ifo.copy(ifo.width / 2,1,ifo.width,ifo.height);
ifo.select(buf1);
buf_width = ifo.width;
ifo.select();
ifo.paste(buf2,1,1);
ifo.paste(buf1,buf_width,1);
}

but it is crashing instantly.
However, the "Black & White" Image Filter example #1 from the LScript documentation runs fine:

process: ifo
{
for(i = 1;i <= ifo.height;++i)
{
for(j = 1;j <= ifo.width;++j)
{
average = (ifo.red[j,i] + ifo.green[j,i] + ifo.blue[j,i]) / 3;
ifo.red[j,i] = average;
ifo.green[j,i] = average;
ifo.blue[j,i] = average;
}
}
}

What is wrong here?
 

Sensei

TrueArt Support
Tried to run Image Filter example #2 from the LScript documentation:

process: ifo
{
buf1 = ifo.copy(1,1,ifo.width / 2,ifo.height);
buf2 = ifo.copy(ifo.width / 2,1,ifo.width,ifo.height);
ifo.select(buf1);
buf_width = ifo.width;
ifo.select();
ifo.paste(buf2,1,1);
ifo.paste(buf1,buf_width,1);
}

but it is crashing instantly.

I would start from turning off multi-threading in Render Globals.

Perhaps it's trying to read/write outside of image buffer.

ifo.width is 1920 and ifo.height is 1080?

If I understand correctly copy has parameters left,top,right,bottom?
If it would have left,top,width,height, 2nd copy would be reading from outside of buffer.
If it's the case, changing to
buf2 = ifo.copy(ifo.width / 2,1,ifo.width/2,ifo.height);
should help immediately (comment the rest of code to not execute).

If paste has parameters buf,left,top
2nd paste is writing to outside of buffer.
Try changing it to
ifo.paste(buf1,buf_width/2,1);

I am just guessing because these copy/paste are not existing in LWSDK.

However, the "Black & White" Image Filter example #1 from the LScript documentation runs fine:

process: ifo
{
for(i = 1;i <= ifo.height;++i)
{
for(j = 1;j <= ifo.width;++j)
{
average = (ifo.red[j,i] + ifo.green[j,i] + ifo.blue[j,i]) / 3;
ifo.red[j,i] = average;
ifo.green[j,i] = average;
ifo.blue[j,i] = average;
}
}
}

What is wrong here?

That's weird they don't start with 0,0 as corner...
LScript starts array from 1?
 

vncnt

Well-known member
I would start from turning off multi-threading in Render Globals.
Now it crashes even faster.
Perhaps it's trying to read/write outside of image buffer.
I don´t know. I´ve used the exact code from the help file.
ifo.width is 1920 and ifo.height is 1080?
1920x185
If I understand correctly copy has parameters left,top,right,bottom?
It seems to be like that.
If it would have left,top,width,height, 2nd copy would be reading from outside of buffer.
I believe the first copy should take the left part of the image and the second copy should take the right part of the image.
If it's the case, changing to
buf2 = ifo.copy(ifo.width / 2,1,ifo.width/2,ifo.height);
should help immediately (comment the rest of code to not execute).
At some point I was able to use copy with a maximum of 16x16 pixels. A slightly higher value caused Layout to complain about insufficient memory during the scene load phase, then crashed. A much higher value caused Layout to crash immediately.
If paste has parameters buf,left,top
2nd paste is writing to outside of buffer.
Try changing it to
ifo.paste(buf1,buf_width/2,1);
The help file about the ifo.select() statement: "Providing no arguments causes the main image buffer to become current.". That buffer should be 1920x185.
I am just guessing because these copy/paste are not existing in LWSDK.
Methods copy, paste and select are described in the Image Filters section of the help file and can also be found here: http://www.mikegreen.name/Lscript/Lscript Index.html
That's weird they don't start with 0,0 as corner...
LScript starts array from 1?
Correct. All arrays in LScript start with 1.
 

Sensei

TrueArt Support

Using odd height might be causing some problems.. Try using width,height dividable by f.e. 16, at least until finding the main source of crash.

At some point I was able to use copy with a maximum of 16x16 pixels. A slightly higher value caused Layout to complain about insufficient memory during the scene load phase, then crashed. A much higher value caused Layout to crash immediately.

Sounds like what I said - overflow of buffer. If you would use 1x1 it probably wouldn't crash at all.
 

vncnt

Well-known member
Now using an image 4416 x 3312 pixels and this code:

buf1 = ifo.copy(1,1,128,128);
buf2 = ifo.copy(1,1,64,64);
ifo.select(buf1);
buf_width = ifo.width;
ifo.select();
ifo.paste(buf1,16,16);
ifo.paste(buf2,16,256);

So I´ve used really small values.
Yet, the preview thumbnail displays a large square area that has now been copied over the original.
When I use this processed image as a background and press F9, nothing of this processing is visible in the final result.

My main goal is to be able to crop the original image to non-destructively match the camera frame aspect.
 

vncnt

Well-known member
It´s crashing as soon as I use larger values.
I´ve specified buf1 to be 128x128 so it´s strange that in the preview thumbnail almost the entire vertical height of the image was cloned on top of the original. I can´t see it that well because the thumbnail is small.

Somehow it translates the 128 pixels to the image height of 3312 pixels.
As if the 128 pixels for the buffer is being multiplied by 16 to fill a large section of the 3312 pixels.
 

Sensei

TrueArt Support
After running your script, I have this:



And no crash.
 

Attachments

  • Snap1.png
    Snap1.png
    1.3 MB · Views: 195

Sensei

TrueArt Support
Ahhh, you're using it inside of Image Editor > Processing filter,
I have added it to Effects > Processing > Image Filters.
 

Sensei

TrueArt Support
Add code:


process: ifo
{
info( ifo.width );
info( ifo.height );
}

Add start Layout, load your scene..
You will see why it's showing error message.

The same data 200x150 are while opening Image Editor. So it's probably that small image for IE window.
 

vncnt

Well-known member
I tried with ifo.height only, and in that case: first it displays 150 and half a second later it displays 3312 (the y size of the original).

Looks like both are handled in sequence.

Is there a way to distinguish between them, other than the y size of 150?
Some flag maybe?
 

Sensei

TrueArt Support
Personally I would get rid of flags LWFCF_PREPROCESS, so image filter will be possible to use only in Effects > Process, and not in Image Editor.
But you probably want this feature.. ?

Actually you have not used flags() at all (disabled part). So probably default (unknown) is used instead?

It's described in detail in LWSDK/html/classes/imgfilt.html
 

vncnt

Well-known member
In the mean time I've figured out that this works:

Code:
@version 2.5
@warnings
@script image
@name BUG

process: ifo
{
ImageWidth = ifo.width;
HalfWidth = ImageWidth/2;

ImageHeight = ifo.height;
HalfHeight = ImageHeight/2;
	
	buf1 = ifo.copy(1,1,HalfWidth,ImageHeight - 1);
	buf2 = ifo.copy(HalfWidth,1,ImageWidth,ImageHeight - 1);	// crash if (ImageHeight) is used instead of (ImageHeight - 1)
	
	ifo.select();
	
	ifo.paste(buf1,HalfWidth,1);					// crash if (2) is used, in case you wanted to cover the bottom line
	ifo.paste(buf2,1,1);
}

Note that both the ifo.copy() and the ifo.paste() functions seem crippled.

The height of the buffer can never be the same as the real height of the images. Layout will crash if you do.
And, you can never paste the buffer to the full height of the image. Layout will crash if you do.

This makes the functions ifo.copy() and ifo.paste() completely useless.
Do you agree?
 
Top Bottom