Skip to content

Commit

Permalink
jpeg-handler: Fix issue with libjpeg62.
Browse files Browse the repository at this point in the history
mandelbrot-example: Create 3 channel image instead of 4 channel image
during jpg creation. The previous version can not be handled by all
variants of libjpeg.
  • Loading branch information
YggdrasiI committed Nov 18, 2014
1 parent e6b140e commit 0d9aa7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 5 additions & 6 deletions examples/mandelbrot/mandelbrot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <onion/extras/jpeg.h>
#endif

#define MAX(X,Y) (((X)>(Y))?X:Y)
#define MIN(X,Y) (((X)<(Y))?X:Y)
#define MAX(X,Y) (((X)>(Y))?(X):(Y))
#define MIN(X,Y) (((X)<(Y))?(X):(Y))

/// Basic complex class, to ease the fractal calculation
class Complex{
Expand Down Expand Up @@ -133,7 +133,7 @@ int mandelbrotJPEG(void *p, onion_request *req, onion_response *res){

int channels = 1;
if( color == 1)
channels = 4;
channels = 3;

unsigned char *image=new unsigned char[channels*width*height];
int i,j,n;
Expand Down Expand Up @@ -161,19 +161,18 @@ int mandelbrotJPEG(void *p, onion_request *req, onion_response *res){
if (n >= steps) P=255;
else P=(n*256)/steps;

if( channels == 4 ){
if( channels == 3 ){
*imagep++=P;
*imagep++=2*P+30;
*imagep++=255-P*3;
*imagep++=255;
}else{
*imagep++=P;
}
}
}

onion_jpeg_response(image, channels,
(channels==1?JCS_GRAYSCALE:JCS_EXT_RGBX)
(channels==1?JCS_GRAYSCALE:JCS_RGB)
, width, height, jpgQuality, res);

delete[] image;
Expand Down
6 changes: 6 additions & 0 deletions src/onion/extras/jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ void onion_init_destination(j_compress_ptr cinfo)
boolean onion_empty_output_buffer(j_compress_ptr cinfo)
{
onion_jpeg_data *d=(onion_jpeg_data*)cinfo->client_data;
/*
* Note: It's not correct to substract free_in_buffer. This value
* should be zero, but this depends on the implementation of libjpeg.
* It's better to assume that all bytes of the buffer are used.
d->res->buffer_pos = sizeof(d->res->buffer)-cinfo->dest->free_in_buffer;
*/
d->res->buffer_pos = sizeof(d->res->buffer);

if(onion_response_flush(d->res)<0){
// Flush failed.
Expand Down

0 comments on commit 0d9aa7b

Please sign in to comment.