You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
2.6 KiB
101 lines
2.6 KiB
|
|
//
|
|
// Image.h
|
|
//
|
|
// Copyright (c) 2010 LearnBoost <tj@learnboost.com>
|
|
//
|
|
|
|
#ifndef __NODE_IMAGE_H__
|
|
#define __NODE_IMAGE_H__
|
|
|
|
#include <nan.h>
|
|
#include "Canvas.h"
|
|
|
|
#ifdef HAVE_JPEG
|
|
#include <jpeglib.h>
|
|
#include <jerror.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_GIF
|
|
#include <gif_lib.h>
|
|
#endif
|
|
|
|
class Image: public node::ObjectWrap {
|
|
public:
|
|
char *filename;
|
|
int width, height;
|
|
NanCallback *onload;
|
|
NanCallback *onerror;
|
|
static Persistent<FunctionTemplate> constructor;
|
|
static void Initialize(Handle<Object> target);
|
|
static NAN_METHOD(New);
|
|
static NAN_GETTER(GetSource);
|
|
static NAN_GETTER(GetOnload);
|
|
static NAN_GETTER(GetOnerror);
|
|
static NAN_GETTER(GetComplete);
|
|
static NAN_GETTER(GetWidth);
|
|
static NAN_GETTER(GetHeight);
|
|
static NAN_GETTER(GetDataMode);
|
|
static NAN_SETTER(SetSource);
|
|
static NAN_SETTER(SetOnload);
|
|
static NAN_SETTER(SetOnerror);
|
|
static NAN_SETTER(SetDataMode);
|
|
inline cairo_surface_t *surface(){ return _surface; }
|
|
inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); }
|
|
inline int stride(){ return cairo_image_surface_get_stride(_surface); }
|
|
static int isPNG(uint8_t *data);
|
|
static int isJPEG(uint8_t *data);
|
|
static int isGIF(uint8_t *data);
|
|
static cairo_status_t readPNG(void *closure, unsigned char *data, unsigned len);
|
|
inline int isComplete(){ return COMPLETE == state; }
|
|
cairo_status_t loadSurface();
|
|
cairo_status_t loadFromBuffer(uint8_t *buf, unsigned len);
|
|
cairo_status_t loadPNGFromBuffer(uint8_t *buf);
|
|
cairo_status_t loadPNG();
|
|
void clearData();
|
|
#ifdef HAVE_GIF
|
|
cairo_status_t loadGIFFromBuffer(uint8_t *buf, unsigned len);
|
|
cairo_status_t loadGIF(FILE *stream);
|
|
#endif
|
|
#ifdef HAVE_JPEG
|
|
cairo_status_t loadJPEGFromBuffer(uint8_t *buf, unsigned len);
|
|
cairo_status_t loadJPEG(FILE *stream);
|
|
cairo_status_t decodeJPEGIntoSurface(jpeg_decompress_struct *info);
|
|
#if CAIRO_VERSION_MINOR >= 10
|
|
cairo_status_t decodeJPEGBufferIntoMimeSurface(uint8_t *buf, unsigned len);
|
|
cairo_status_t assignDataAsMime(uint8_t *data, int len, const char *mime_type);
|
|
#endif
|
|
#endif
|
|
void error(Local<Value> error);
|
|
void loaded();
|
|
cairo_status_t load();
|
|
Image();
|
|
|
|
enum {
|
|
DEFAULT
|
|
, LOADING
|
|
, COMPLETE
|
|
} state;
|
|
|
|
enum data_mode_t {
|
|
DATA_IMAGE = 1
|
|
, DATA_MIME = 2
|
|
} data_mode;
|
|
|
|
typedef enum {
|
|
UNKNOWN
|
|
, GIF
|
|
, JPEG
|
|
, PNG
|
|
} type;
|
|
|
|
static type extension(const char *filename);
|
|
|
|
private:
|
|
cairo_surface_t *_surface;
|
|
uint8_t *_data;
|
|
int _data_len;
|
|
~Image();
|
|
};
|
|
|
|
#endif
|
|
|