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()) {
Image *img = ObjectWrap::Unwrap<Image>(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);

5
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 {

Loading…
Cancel
Save