Image2DRGBA.kl¶
Types¶
Image2DRGBA (object)¶
The Image2DRGBA is an Image2D storing RGBA pixel values.
参考
Members¶
String | name | The name of the image. |
Size | width | the width of the image |
Size | height | the height of the image |
UInt32 | version | the current version number of the image |
UInt32 | flags | A set of binary flags for the image. |
StatisticsAutoRegisterMember | autoStats | A statistics collection member used to track memory usage throughout an application. |
RGBA[] | pixels |
/*
** Example: Image2DRGBA
*/
require OpenImageIO;
require FileIO;
require Images;
function Boolean loadRGBAImageData(
String filePath,
io Image2DRGBA image
) {
OpenImageInput oiimage = OpenImageInput();
oiimage.open(filePath);
if(oiimage.valid()) {
OpenImageTypeDesc desc = OpenImageTypeDesc(OpenImage_BASETYPE_UINT8, OpenImage_AGGREGATE_SCALAR, OpenImage_VECSEMANTICS_NOXFORM);
OpenImageSpec spec = oiimage.spec();
image.resize(spec.get_full_width(), spec.get_full_height());
Boolean success = false;
if(spec.get_nchannels() == 4) {
Data data = image.pixels.data();
success = oiimage.read_image(desc, data, 0, 0, 0);
} else if(spec.get_nchannels() == 3) {
image.resize(image.width, image.height);
Byte bytes[];
bytes.resize(image.width * image.height * spec.get_nchannels());
Data data = bytes.data();
success = oiimage.read_image(desc, data, 0, 0, 0);
if(success) {
Size offset = 0;
for(Size i=0;i< image.pixels.size();i++) {
image.pixels[i].r = bytes[offset++];
image.pixels[i].g = bytes[offset++];
image.pixels[i].b = bytes[offset++];
image.pixels[i].a = 255;
}
}
}
if(!success) {
setError("Image2D '"+filePath+"' could not be converted to RGBA.");
}
}
else {
setError("Image2D '"+filePath+"' could not be opened!");
return false;
}
return true;
}
operator entry() {
FilePath inputPath = FilePath('${FABRIC_SCENE_GRAPH_DIR}/Python/Apps/Resources/Images/logo.png').expandEnvVars();
Image2DRGBA image();
loadRGBAImageData(inputPath.string(), image);
// report some pixel
for(Size i=1;i<5;i++)
for(Size j=1;j<5;j++)
report(image.sample(Scalar(i)/5.0, Scalar(j)/5.0));
}
/*
** Output:
{r:0,g:0,b:0,a:0}
{r:39,g:168,b:223,a:255}
{r:39,g:168,b:223,a:255}
{r:0,g:0,b:0,a:0}
{r:39,g:168,b:223,a:255}
{r:39,g:168,b:223,a:255}
{r:39,g:168,b:223,a:255}
{r:39,g:168,b:223,a:255}
{r:39,g:168,b:223,a:255}
{r:0,g:0,b:0,a:0}
{r:39,g:168,b:223,a:255}
{r:39,g:168,b:223,a:255}
{r:0,g:0,b:0,a:0}
{r:39,g:168,b:223,a:255}
{r:39,g:168,b:223,a:255}
{r:0,g:0,b:0,a:0}
*/
Methods¶
Image2DRGBA ( in Image2DRGBA other ) | |
Image2DRGBA () | |
Image2DRGBA | clone ? () |
StatisticRecord[] | getStatistics ? () |
resize ! ( in UInt32 width, in UInt32 height ) | |
RGBA | sample ? ( in Scalar u, in Scalar v ) |
setPixel ! ( in Integer uindex, in Integer vindex, in RGBA pixelValue ) |