From 69d4eb398703870e00dd804416a6ded8d17478ab Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Fri, 4 May 2012 10:07:40 -0700 Subject: [PATCH] slight refactor --- src/Image.cc | 26 +++++++++++--------------- src/Image.h | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/Image.cc b/src/Image.cc index a4aa048..560a023 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -55,8 +55,8 @@ Image::Initialize(Handle target) { proto->SetAccessor(String::NewSymbol("onerror"), GetOnerror, SetOnerror); #if CAIRO_VERSION_MINOR >= 10 proto->SetAccessor(String::NewSymbol("dataMode"), GetDataMode, SetDataMode); - constructor->Set(String::NewSymbol("MODE_IMAGE"), Number::New(1)); - constructor->Set(String::NewSymbol("MODE_MIME"), Number::New(2)); + constructor->Set(String::NewSymbol("MODE_IMAGE"), Number::New(DATA_IMAGE)); + constructor->Set(String::NewSymbol("MODE_MIME"), Number::New(DATA_MIME)); #endif target->Set(String::NewSymbol("Image"), constructor->GetFunction()); } @@ -107,16 +107,8 @@ Image::SetDataMode(Local, Local val, const AccessorInfo &info) { if (val->IsNumber()) { Image *img = ObjectWrap::Unwrap(info.This()); int mode = val->Uint32Value(); - switch (mode) { - case 1: - img->data_mode = DATA_IMAGE; - break; - case 2: - img->data_mode = DATA_MIME; - break; - case 3: - img->data_mode = DATA_IMAGE_AND_MIME; - break; + if (mode >= DATA_IMAGE && mode <= DATA_IMAGE_AND_MIME) { + img->data_mode = (data_mode_t) mode; } } } @@ -171,11 +163,10 @@ Image::clearData() { free(_data); _data = NULL; - width = height = 0; - free(filename); filename = NULL; + width = height = 0; state = DEFAULT; } @@ -827,7 +818,12 @@ Image::assignDataAsMime(uint8_t *data, int len, const char *mime_type) { 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 diff --git a/src/Image.h b/src/Image.h index 8a085c8..0de51e1 100644 --- a/src/Image.h +++ b/src/Image.h @@ -72,10 +72,10 @@ class Image: public node::ObjectWrap { , COMPLETE } state; - enum { - DATA_IMAGE = 1, - DATA_MIME, - DATA_IMAGE_AND_MIME + enum data_mode_t { + DATA_IMAGE + , DATA_MIME + , DATA_IMAGE_AND_MIME } data_mode; typedef enum {