2 changed files with 88 additions and 0 deletions
@ -0,0 +1,60 @@ |
|||
|
|||
//
|
|||
// ImageData.cc
|
|||
//
|
|||
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
|
|||
//
|
|||
|
|||
#include "ImageData.h" |
|||
|
|||
/*
|
|||
* Initialize ImageData. |
|||
*/ |
|||
|
|||
void |
|||
ImageData::Initialize(Handle<Object> target) { |
|||
HandleScope scope; |
|||
Local<FunctionTemplate> t = FunctionTemplate::New(ImageData::New); |
|||
t->InstanceTemplate()->SetInternalFieldCount(1); |
|||
t->SetClassName(String::NewSymbol("ImageData")); |
|||
|
|||
// Prototype
|
|||
Local<ObjectTemplate> proto = t->PrototypeTemplate(); |
|||
proto->SetAccessor(String::NewSymbol("width"), GetWidth); |
|||
proto->SetAccessor(String::NewSymbol("height"), GetHeight); |
|||
target->Set(String::NewSymbol("ImageData"), t->GetFunction()); |
|||
} |
|||
|
|||
/*
|
|||
* Initialize a new ImageData object. |
|||
*/ |
|||
|
|||
Handle<Value> |
|||
ImageData::New(const Arguments &args) { |
|||
HandleScope scope; |
|||
// TODO: arg assertions
|
|||
PixelArray *data = ObjectWrap::Unwrap<PixelArray>(args[0]->ToObject()); |
|||
ImageData *imageData = new ImageData(data); |
|||
imageData->Wrap(args.This()); |
|||
return args.This(); |
|||
} |
|||
|
|||
/*
|
|||
* Get width. |
|||
*/ |
|||
|
|||
Handle<Value> |
|||
ImageData::GetWidth(Local<String> prop, const AccessorInfo &info) { |
|||
ImageData *imageData = ObjectWrap::Unwrap<ImageData>(info.This()); |
|||
return Number::New(imageData->pixelArray()->getWidth()); |
|||
} |
|||
|
|||
/*
|
|||
* Get height. |
|||
*/ |
|||
|
|||
Handle<Value> |
|||
ImageData::GetHeight(Local<String> prop, const AccessorInfo &info) { |
|||
ImageData *imageData = ObjectWrap::Unwrap<ImageData>(info.This()); |
|||
return Number::New(imageData->pixelArray()->getHeight()); |
|||
} |
@ -0,0 +1,28 @@ |
|||
|
|||
//
|
|||
// ImageData.h
|
|||
//
|
|||
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
|
|||
//
|
|||
|
|||
#ifndef __NODE_IMAGE_DATA_H__ |
|||
#define __NODE_IMAGE_DATA_H__ |
|||
|
|||
#include "Canvas.h" |
|||
#include "PixelArray.h" |
|||
#include <stdlib.h> |
|||
|
|||
class ImageData: public node::ObjectWrap { |
|||
public: |
|||
static void Initialize(Handle<Object> target); |
|||
static Handle<Value> New(const Arguments &args); |
|||
static Handle<Value> GetWidth(Local<String> prop, const AccessorInfo &info); |
|||
static Handle<Value> GetHeight(Local<String> prop, const AccessorInfo &info); |
|||
inline PixelArray *pixelArray(){ return _arr; } |
|||
ImageData(PixelArray *arr): _arr(arr) {} |
|||
~ImageData() { delete _arr; }; |
|||
private: |
|||
PixelArray *_arr; |
|||
}; |
|||
|
|||
#endif |
Loading…
Reference in new issue