From f47422fd06601aca4e887fd69357427ff906d61a Mon Sep 17 00:00:00 2001 From: TJ Holowaychuk Date: Fri, 4 May 2012 13:11:43 -0700 Subject: [PATCH] fixed Image bit flags --- src/Image.cc | 36 +++++++++++++----------------------- src/Image.h | 5 ++--- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/Image.cc b/src/Image.cc index 560a023..6995345 100644 --- a/src/Image.cc +++ b/src/Image.cc @@ -107,9 +107,7 @@ Image::SetDataMode(Local, Local val, const AccessorInfo &info) { if (val->IsNumber()) { Image *img = ObjectWrap::Unwrap(info.This()); int mode = val->Uint32Value(); - if (mode >= DATA_IMAGE && mode <= DATA_IMAGE_AND_MIME) { - img->data_mode = (data_mode_t) mode; - } + img->data_mode = (data_mode_t) mode; } } @@ -219,16 +217,13 @@ Image::loadFromBuffer(uint8_t *buf, unsigned len) { if (isJPEG(buf)) return loadJPEGFromBuffer(buf, len); #else if (isJPEG(buf)) { - switch (data_mode) { - case DATA_IMAGE: - return loadJPEGFromBuffer(buf, len); - case DATA_MIME: - return decodeJPEGBufferIntoMimeSurface(buf, len); - case DATA_IMAGE_AND_MIME: - cairo_status_t status; - status = loadJPEGFromBuffer(buf, len); - if (status) return status; - return assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG); + if (DATA_IMAGE == data_mode) return loadJPEGFromBuffer(buf, len); + if (DATA_MIME == data_mode) return decodeJPEGBufferIntoMimeSurface(buf, len); + if ((DATA_IMAGE | DATA_MIME) == data_mode) { + cairo_status_t status; + status = loadJPEGFromBuffer(buf, len); + if (status) return status; + return assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG); } } #endif @@ -890,16 +885,11 @@ Image::loadJPEG(FILE *stream) { fread(buf, len, 1, stream); fclose(stream); - switch (data_mode) { - case DATA_IMAGE: // Can't be this, but compiler warning. - case DATA_IMAGE_AND_MIME: - status = loadJPEGFromBuffer(buf, len); - if (status) break; - status = assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG); - break; - case DATA_MIME: - status = decodeJPEGBufferIntoMimeSurface(buf, len); - break; + if ((DATA_IMAGE | DATA_MIME) == data_mode) { + status = loadJPEGFromBuffer(buf, len); + if (!status) status = assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG); + } else if (DATA_MIME == data_mode) { + status = decodeJPEGBufferIntoMimeSurface(buf, len); } free(buf); diff --git a/src/Image.h b/src/Image.h index 0de51e1..beec262 100644 --- a/src/Image.h +++ b/src/Image.h @@ -73,9 +73,8 @@ class Image: public node::ObjectWrap { } state; enum data_mode_t { - DATA_IMAGE - , DATA_MIME - , DATA_IMAGE_AND_MIME + DATA_IMAGE = 1 + , DATA_MIME = 2 } data_mode; typedef enum {