Browse Source

slight refactor

v1.x
TJ Holowaychuk 13 years ago
parent
commit
69d4eb3987
  1. 26
      src/Image.cc
  2. 8
      src/Image.h

26
src/Image.cc

@ -55,8 +55,8 @@ Image::Initialize(Handle<Object> target) {
proto->SetAccessor(String::NewSymbol("onerror"), GetOnerror, SetOnerror); proto->SetAccessor(String::NewSymbol("onerror"), GetOnerror, SetOnerror);
#if CAIRO_VERSION_MINOR >= 10 #if CAIRO_VERSION_MINOR >= 10
proto->SetAccessor(String::NewSymbol("dataMode"), GetDataMode, SetDataMode); proto->SetAccessor(String::NewSymbol("dataMode"), GetDataMode, SetDataMode);
constructor->Set(String::NewSymbol("MODE_IMAGE"), Number::New(1)); constructor->Set(String::NewSymbol("MODE_IMAGE"), Number::New(DATA_IMAGE));
constructor->Set(String::NewSymbol("MODE_MIME"), Number::New(2)); constructor->Set(String::NewSymbol("MODE_MIME"), Number::New(DATA_MIME));
#endif #endif
target->Set(String::NewSymbol("Image"), constructor->GetFunction()); target->Set(String::NewSymbol("Image"), constructor->GetFunction());
} }
@ -107,16 +107,8 @@ Image::SetDataMode(Local<String>, Local<Value> val, const AccessorInfo &info) {
if (val->IsNumber()) { if (val->IsNumber()) {
Image *img = ObjectWrap::Unwrap<Image>(info.This()); Image *img = ObjectWrap::Unwrap<Image>(info.This());
int mode = val->Uint32Value(); int mode = val->Uint32Value();
switch (mode) { if (mode >= DATA_IMAGE && mode <= DATA_IMAGE_AND_MIME) {
case 1: img->data_mode = (data_mode_t) mode;
img->data_mode = DATA_IMAGE;
break;
case 2:
img->data_mode = DATA_MIME;
break;
case 3:
img->data_mode = DATA_IMAGE_AND_MIME;
break;
} }
} }
} }
@ -171,11 +163,10 @@ Image::clearData() {
free(_data); free(_data);
_data = NULL; _data = NULL;
width = height = 0;
free(filename); free(filename);
filename = NULL; filename = NULL;
width = height = 0;
state = DEFAULT; state = DEFAULT;
} }
@ -827,7 +818,12 @@ Image::assignDataAsMime(uint8_t *data, int len, const char *mime_type) {
V8::AdjustAmountOfExternalAllocatedMemory(len); V8::AdjustAmountOfExternalAllocatedMemory(len);
return cairo_surface_set_mime_data(_surface, mime_type, mime_data, len, clearMimeData, mime_closure); return cairo_surface_set_mime_data(_surface
, mime_type
, mime_data
, len
, clearMimeData
, mime_closure);
} }
#endif #endif

8
src/Image.h

@ -72,10 +72,10 @@ class Image: public node::ObjectWrap {
, COMPLETE , COMPLETE
} state; } state;
enum { enum data_mode_t {
DATA_IMAGE = 1, DATA_IMAGE
DATA_MIME, , DATA_MIME
DATA_IMAGE_AND_MIME , DATA_IMAGE_AND_MIME
} data_mode; } data_mode;
typedef enum { typedef enum {

Loading…
Cancel
Save