Method: MagickWand::Wand#import_pixels

Defined in:
ext/magickwand/wand.c

#import_pixels(*args) ⇒ Object

wand.import_pixels(x, y, columns, rows, pixels, :map=>“rgb”, :storage_type=>“char”) imports into the first image in the wand



1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
# File 'ext/magickwand/wand.c', line 1309

static VALUE wand_import_pixels(int argc, VALUE *argv, VALUE obj)
{
    Wand *wand;
    VALUE columns, rows, pixels, options, x_off, y_off, v;
    unsigned long width, height, length;
    long x, y;
    void *data;
    StorageType stg_type;
    char *map;
    size_t stg_type_size;

    rb_check_frozen(obj);

    (void) rb_scan_args(argc, argv, "51", &x_off, &y_off, &columns, &rows, &pixels, &options);
    x = NUM2LONG(x_off);
    y = NUM2LONG(y_off);
    width = NUM2ULONG(columns);
    height = NUM2ULONG(rows);
    StringValue(pixels);
    data = (void *) RSTRING_PTR(pixels);
    length = (unsigned long) RSTRING_LEN(pixels);

    (void) mwr_get_option(options, "map", &v);
    map = v != Qnil ? StringValuePtr(v) : "RGB";
    (void) mwr_get_option(options, "storage_type", &v);
    stg_type = mwr_string_to_storagetype(v, CharPixel, RaiseUndefinedOption);
    stg_type_size = get_stg_type_size(stg_type);

    if (length < width*height*stg_type_size*strlen(map))
    {
        rb_raise(rb_eArgError, "pixel buffer too small (expecting %lu got %lu)",
            width*height*stg_type_size*strlen(map), length);
    }

    Data_Get_Struct(obj, Wand, wand);
    MagickResetIterator(wand->magickwand);
    MagickImportImagePixels(wand->magickwand, x, y, width, height, map, stg_type, data);
    mwr_check_magickwand_error(wand->magickwand);

    return obj;
}