Anim8or Community

General Category => ASL Scripts => Topic started by: Steve on March 13, 2019, 05:47:45 pm

Title: New Write Image Functions.
Post by: Steve on March 13, 2019, 05:47:45 pm
In the latest development build 1356 (http://www.anim8or.com/download/preview/files/animcl1356.zip) you can save rendered images in BMP, JPG and PNG format.

class image {
    int WriteBMP(string fName); // All functions return 1 if OK, 0 if failed
    int WriteJPG(string fName [ , int quality = 95 ] ); // 0 = lowest, 100 = highest
    int WritePNG(string fName [, int IncludeAlpha = 0 ] );
}

image GetImage(int image_id); // Returns NULL if no such image.
enum image_id { IMAGE_COLOR, IMAGE_ALPHA, IMAGE_DEPTH };

I've attached a sample script.

Title: Re: New Write Image Functions.
Post by: Raxx on March 13, 2019, 06:48:23 pm
Very cool, I always like to see ASL enhancements. Are there any plans on extending the image class to include the ability to create images from scratch, and functions for reading and manipulating pixels?
Title: Re: New Write Image Functions.
Post by: Steve on March 13, 2019, 06:57:08 pm
That's a thought. What kind of functions did you have in mind? Compositing?
Title: Re: New Write Image Functions.
Post by: Raxx on March 13, 2019, 08:08:58 pm
I don't really (read: never) deal with image processing via code. I expect for starters, something like:

new data types:
byte: unsigned 8-bit integer (0-255)
struct pixel {
 byte r, g, b, a;
}

creation:
image $img;
$img.Read(fileName);
$img.New(width, height) or $img = Image(width, height) - Width/height can only be set during this stage. Construction creates blank and transparent pixels (zeroes across the rgba channels)

fields/properties:
$img.width (read only)
$img.height (read only)
$img.pixels[] (get/set array values, but protected array size). Array length is width*height

Manipulation aside from $img.pixels[]:
$img.GetPixel(x, y) - user-friendly means of getting pixels by its x and y coordinates in the image.
$img.SetPixel(x, y, pixel) - user friendly means of setting the pixel

Maybe also tie this class into textures as well, as it expands capability to create procedural and possibly (scratches head) animated textures? For example, $tex.SetTexture($img) uses an Image object for its image information rather than a file.
Title: Re: New Write Image Functions.
Post by: NickE on March 14, 2019, 06:34:39 pm
Yea!  You rock, Steve! This solves many of the problems with rendering script-driven physics simulations.  I used to have to start an object script, manually switch to scene mode and start rendering, then remove all the duplicate frames from the scene rendering as the object script ran in the background with strategic delays to give the renderer time to finish the frame before the object script incremented.

Ideally, the scene controller parameters "frame" or "time" would be available to object scripts from scene mode, but this is a huge step forward.

Thank you, Steve!