Project

General

Profile

Actions

Feature #1201

open

Initialize WRasterImage from raw data

Added by Anonymous about 12 years ago. Updated over 11 years ago.

Status:
InProgress
Priority:
Normal
Assignee:
Target version:
-
Start date:
03/20/2012
Due date:
% Done:

0%

Estimated time:

Description

Hi,

to fill WRasterImage with data, for example by procedurally generated content like in the Mandelbrot example or other applications image data, you need to use the WRasterImage::setPixel() method. This sets and syncs a single pixel to GraphicsImage.

What about providing another constructor that allows to set the full data on initialization using a given raw pixel pointer? I append an alternative constructor that receives a rawPixel pointer and a map parameter to specify the channel order for GraphicsMagic (see below).

Doing some measurements with the Mandelbrot example, and measuring only the time spent to set the data either pixel wise or in one step (as proposed), I gained about x10 in release and x100 in debug mode.

What do you think? If you have time, also the setter methods from GraphicsMagic to change a region could be exposed, but for me a second constructor would be fine.

Two more minor things:

- In the constructor, you convert the given type (e.g. "png") to uppercase, but this string is not used subsequently. Does not seem to harm, though.

  • In your constructor, you initialize the GraphicsImage with an allocated unsigned char array, which is not used anywhere else except to initialize GraphicsImage (and to delete in the destructor, later). You could consider using GraphicsImage::AllocateImage() with the desired background color set as a parameter, instead, using less memory + overhead.

Best,

Tassilo

Proposed constructor:

WRasterImage::WRasterImage(const std::string& type,
    const WLength& width, const WLength& height,
    const unsigned char * rawPixels,
    const char* map, 
    WObject *parent )
: WResource(parent),
width_(width),
height_(height),
type_(type),
painter_(0),
currentClipPath_(-1),
currentClipPathRendered_(-1)
{
    InitializeMagick(0);

    w_ = static_cast<unsigned long>(width.toPixels());
    h_ = static_cast<unsigned long>(height.toPixels());

    context_ = 0;
    fontSupport_ = 0;

    if (!w_ || !h_) {
        pixels_ = 0;
        image_ = 0;
        return;
    }

    // only support RGBA and RGB, with all permutations, e.g., BGRA
    ImageType imageType = TrueColorMatteType;
    if (strstr(map,"A") == NULL)
    {
        imageType = TrueColorType;
    }

    ExceptionInfo exception;
    GetExceptionInfo(&exception);
    image_ = ConstituteImage(w_, h_, map, CharPixel, rawPixels, &exception);

    SetImageType(image_, imageType);
    // no opacity since we initialized with values
    SetImageOpacity(image_, 0);

    // changed this to acutally use the uppercase string
    std::string magick = type;
    std::transform(magick.begin(), magick.end(), magick.begin(), toupper);
    strcpy(image_->magick, magick.c_str());
}
Actions #1

Updated by Koen Deforche about 12 years ago

  • Status changed from New to InProgress
  • Assignee set to Koen Deforche
  • Target version set to 3.2.2

Hey,

That is indeed a useful addition. The challenge is to design an API that covers enough flexibility and is easy to understand. Personally I'm not such a big fan of the graphicsmagick API in this case.

Regards,

koen

Actions #2

Updated by Koen Deforche almost 12 years ago

  • Target version changed from 3.2.2 to 3.2.3
Actions #3

Updated by Koen Deforche over 11 years ago

  • Target version deleted (3.2.3)
Actions

Also available in: Atom PDF