Skip to content

Commit

Permalink
Testing...
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed Aug 26, 2013
1 parent 4b17698 commit 1219a15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
30 changes: 16 additions & 14 deletions src/Image.cc
Expand Up @@ -207,7 +207,7 @@ Image::loadFromBuffer(uint8_t *buf, unsigned len) {
#endif
#ifdef HAVE_JPEG
#if CAIRO_VERSION_MINOR < 10
if (isJPEG(buf)) return loadJPEGFromBuffer(buf, len);
if (isJPEG(buf)) return loadJPEGFromBuffer(buf, len);
#else
if (isJPEG(buf)) {
if (DATA_IMAGE == data_mode) return loadJPEGFromBuffer(buf, len);
Expand Down Expand Up @@ -314,6 +314,16 @@ Image::Image() {

Image::~Image() {
clearData();

if (onerror) {
delete onerror;
onerror = NULL;
}

if (onload) {
delete onload;
onload = NULL;
}
}

/*
Expand Down Expand Up @@ -348,10 +358,6 @@ Image::loaded() {
delete onload;
onload = NULL;
}
if (onerror != NULL) {
delete onerror;
onerror = NULL;
}
}

/*
Expand All @@ -367,15 +373,11 @@ Image::error(Local<Value> err) {
delete onerror;
onerror = NULL;
}
if (onload != NULL) {
delete onload;
onload = NULL;
}
}

/*
* Load cairo surface from the image src.
*
*
* TODO: support more formats
* TODO: use node IO or at least thread pool
*/
Expand Down Expand Up @@ -467,7 +469,7 @@ Image::loadGIF(FILE *stream) {
if (fstat(fd, &s) < 0) {
fclose(stream);
return CAIRO_STATUS_READ_ERROR;
}
}

uint8_t *buf = (uint8_t *) malloc(s.st_size);

Expand Down Expand Up @@ -500,10 +502,10 @@ Image::loadGIFFromBuffer(uint8_t *buf, unsigned len) {
#if GIFLIB_MAJOR >= 5
int errorcode;
if ((gif = DGifOpen((void*) &gifd, read_gif_from_memory, &errorcode)) == NULL)
return CAIRO_STATUS_READ_ERROR;
return CAIRO_STATUS_READ_ERROR;
#else
if ((gif = DGifOpen((void*) &gifd, read_gif_from_memory)) == NULL)
return CAIRO_STATUS_READ_ERROR;
return CAIRO_STATUS_READ_ERROR;
#endif

if (GIF_OK != DGifSlurp(gif)) {
Expand Down Expand Up @@ -710,7 +712,7 @@ Image::decodeJPEGIntoSurface(jpeg_decompress_struct *args) {
*pixel = 255 << 24
| src[bx + 0] << 16
| src[bx + 1] << 8
| src[bx + 2];
| src[bx + 2];
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/JPEGStream.h
Expand Up @@ -80,7 +80,7 @@ jpeg_closure_dest(j_compress_ptr cinfo, closure_t * closure, int bufsize){
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof(closure_destination_mgr));
}

dest = (closure_destination_mgr *) cinfo->dest;

cinfo->dest->init_destination = &init_closure_destination;
Expand All @@ -99,7 +99,10 @@ void
jpeg_free_custom_allocations(j_compress_ptr cinfo){
closure_destination_mgr * dest;
dest = (closure_destination_mgr *) cinfo->dest;
free(dest->buffer);
if (dest->buffer) {
free(dest->buffer);
dest->buffer = NULL;
}
}

void
Expand Down

0 comments on commit 1219a15

Please sign in to comment.