Browse Source

fixed Image bit flags

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

22
src/Image.cc

@ -107,10 +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();
if (mode >= DATA_IMAGE && mode <= DATA_IMAGE_AND_MIME) {
img->data_mode = (data_mode_t) mode; img->data_mode = (data_mode_t) mode;
} }
}
} }
#endif #endif
@ -219,12 +217,9 @@ 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:
return decodeJPEGBufferIntoMimeSurface(buf, len);
case DATA_IMAGE_AND_MIME:
cairo_status_t status; cairo_status_t status;
status = loadJPEGFromBuffer(buf, len); status = loadJPEGFromBuffer(buf, len);
if (status) return status; if (status) return status;
@ -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.
case DATA_IMAGE_AND_MIME:
status = loadJPEGFromBuffer(buf, len); status = loadJPEGFromBuffer(buf, len);
if (status) break; if (!status) status = assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG);
status = assignDataAsMime(buf, len, CAIRO_MIME_TYPE_JPEG); } else if (DATA_MIME == data_mode) {
break;
case DATA_MIME:
status = decodeJPEGBufferIntoMimeSurface(buf, len); 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