Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create an image from scratch by writing values to a buffer then use IImageFrameWriter to generate an IDOMImage that can be be saved to disk
// -----------------------------------------------------------------------
// <copyright file="TestFrameWriter.cpp" company="Global Graphics Software Ltd">
// Copyright (c) 2021 Global Graphics Software Ltd. All rights reserved.
// </copyright>
// <summary>
// This example is provided on an "as is" basis and without warranty of any kind.
// Global Graphics Software Ltd. does not warrant or make any representations regarding the use or
// results of use of this example.
// </summary>
// -----------------------------------------------------------------------
#include <jawsmako/jawsmako.h>
using namespace JawsMako;
using namespace EDL;
int main()
{
/* Synopsis
* Create an image from scratch by writing values to a buffer then use
* an IImageFrameWriter to generate an IDOMImage that can be be saved to disk
*/
const uint32 width = 2010;
const uint32 height = 1500;
const uint32 componentCount = 4; // for RGBA
// Image buffer
CEDLVector< CEDLVector <uint8> > imageBuffer;
imageBuffer.resize(height);
for (uint32 y = 0; y < height; y++)
{
imageBuffer[y].resize(width * componentCount);
memset(&imageBuffer[y][0], 0x00, width * componentCount); // Fill with zeroes
}
// Red pixels
for (uint32 y = 0; y < 500; y++)
{
for (uint32 x = 0; x < width; x++)
{
imageBuffer[y][x * componentCount] = 0xFF;
}
}
// Green pixels
for (uint32 y = 500; y < 1000; y++)
{
for (uint32 x = 0; x < width; x++)
{
imageBuffer[y][x * componentCount + 1] = 0xFF;
}
}
// Blue pixels
for (uint32 y = 1000; y < 1500; y++)
{
for (uint32 x = 0; x < width; x++)
{
imageBuffer[y][x * componentCount + 2] = 0xFF;
}
}
// Opacity
for (uint32 y = 0; y < height; y++)
{
for (uint32 x = 0; x < width; x++)
{
imageBuffer[y][x * componentCount + 3] = (uint8)((float)x / (float)width * 255.0f);
}
}
IJawsMakoPtr jawsMako = IJawsMako::create();
// Load the buffer into an IDOMImage so that it can be written out
IImageFrameWriterPtr frameWriter;
IDOMImagePtr renderedImage = IDOMRawImage::createWriterAndImage(jawsMako, frameWriter,
IDOMColorSpaceDeviceRGB::create(jawsMako), width,
height, 8, 96.0, 96.0, eIECAlpha);
for (uint64 y = 0; y < height; y++)
{
frameWriter->writeScanLine(&imageBuffer[y][0]);
}
frameWriter->flushData();
IDOMPNGImage::encode(jawsMako, renderedImage, IOutputStream::createToFile(jawsMako, "out.png"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment