Browse Source

fixed Image bit flags

v1.x
TJ Holowaychuk 13 years ago
parent
commit
f47422fd06
  1. 36
      src/Image.cc
  2. 5
      src/Image.h

36
src/Image.cc

@ -107,9 +107,7 @@ 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();
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); if (isJPEG(buf)) return loadJPEGFromBuffer(buf, len);
#else #else
if (isJPEG(buf)) { if (isJPEG(buf)) {
switch (data_mode) { if (DATA_IMAGE == data_mode) return loadJPEGFromBuffer(buf, len);
case DATA_IMAGE: if (DATA_MIME == data_mode) return decodeJPEGBufferIntoMimeSurface(buf, len);
return loadJPEGFromBuffer(buf, len); if ((DATA_IMAGE | DATA_MIME) == data_mode) {
case DATA_MIME: cairo_status_t status;
return decodeJPEGBufferIntoMimeSurface(buf, len); status = loadJPEGFromBuffer(buf, len);
case DATA_IMAGE_AND_MIME: if (status) return status;
cairo_status_t status; return assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG);
status = loadJPEGFromBuffer(buf, len);
if (status) return status;
return assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG);
} }
} }
#endif #endif
@ -890,16 +885,11 @@ Image::loadJPEG(FILE *stream) {
fread(buf, len, 1, stream); fread(buf, len, 1, stream);
fclose(stream); fclose(stream);
switch (data_mode) { if ((DATA_IMAGE | DATA_MIME) == data_mode) {
case DATA_IMAGE: // Can't be this, but compiler warning. status = loadJPEGFromBuffer(buf, len);
case DATA_IMAGE_AND_MIME: if (!status) status = assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG);
status = loadJPEGFromBuffer(buf, len); } else if (DATA_MIME == data_mode) {
if (status) break; status = decodeJPEGBufferIntoMimeSurface(buf, len);
status = assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG);
break;
case DATA_MIME:
status = decodeJPEGBufferIntoMimeSurface(buf, len);
break;
} }
free(buf); free(buf);

5
src/Image.h

@ -73,9 +73,8 @@ class Image: public node::ObjectWrap {
} state; } state;
enum data_mode_t { enum data_mode_t {
DATA_IMAGE DATA_IMAGE = 1
, DATA_MIME , DATA_MIME = 2
, DATA_IMAGE_AND_MIME
} data_mode; } data_mode;
typedef enum { typedef enum {

Loading…
Cancel
Save