>
> On 13.05.2011, at 22:01, Domingo Alvarez Duarte wrote:
>
> > I know that that function exists but my case isn't to convert a JPEG =
> image =20
> > to Fl_Image but the opposite convert a FL_Image to a JPEG or PNG.
> >=20
> > Anyway thanks for your attention.
>

Longtime back i have attempted on such task.
i am giving the source for that.
there may be modification required.
your views are welcome.

/* 19thmarch2010
 *retrd:14thmay2011
 */

/*  a membuff rgb data to jpeg file write routine  */

#include <stdio.h>
#include <stdlib.h>
#include <jpeglib.h>

/* compress 'rgb' data and write as a jpeg file
 * compression quality is settable between 0 to 100
 */

int write2jpeg(FILE *fileptr,unsigned char *image,int width,int height,int 
quality)
{
/* from:libjpeg manual
 * Allocate and initialize a JPEG compression object
 * Specify the destination for the compressed data (eg, a file)
 * Set parameters for compression, including image size & colorspace
 * jpeg_start_compress(...);
 *         while (scan lines remain to be written)
 *                 jpeg_write_scanlines(...);
 * jpeg_finish_compress(...);
 * Release the JPEG compression object
 */

int i,j;
/*Allocate a JPEG compression object-(cinfo here)*/
struct jpeg_compress_struct cinfo;

        JSAMPROW row_pointer[1];

/* jpegimage=oneline compressed jpeg image buffer  */
        JSAMPLE *jpegimage = NULL;
        int row_stride;

/* jpeg error manager     */
struct jpeg_error_mgr jerr;

/* allocate the jpegimage buffer memory   */
        if ((jpegimage = malloc(width*3)) == NULL)
        {
        /* :( */
        fprintf(stderr,"jpegwrite--memory allocation error\n");
        return(1);
        }
/* set the jpeg error handler  */
   cinfo.err = jpeg_std_error(&jerr);

/* Initialize the JPEG compression object.  */
        jpeg_create_compress(&cinfo);

/*Specify the destination for the compressed data (eg, a file)*/
        jpeg_stdio_dest(&cinfo,fileptr);


/* Set parameters for compression,
 *      including image size & colorspace
 */
   cinfo.image_width = width;
   cinfo.image_height = height;
/* 'components' are 'no.of color channels'(RGB=3 here)    */
   cinfo.input_components = 3;
/* this is in RGB color space  */
   cinfo.in_color_space = JCS_RGB;
/* set default compression settings  */
        jpeg_set_defaults(&cinfo);
/* set compression quality        */
/* TRUE= limit quality to baseline of JPEG values  */
jpeg_set_quality(&cinfo, quality, TRUE);


/* jpeg_start_compress(...);  */
        jpeg_start_compress(&cinfo, TRUE);

        row_stride = width * 3;
        row_pointer[0] = jpegimage;
/* initialise 'j' with last row to start, then count down...  */
        j = cinfo.image_height - 1;
/* while (scan lines remain to be written)
 *       jpeg_write_scanlines(...);
 */
        while (cinfo.next_scanline < cinfo.image_height)
                {
                for (i=0;i<width;i++)
                        {
                        jpegimage[3*i  ] = image[j*width+i+0];
                        jpegimage[3*i+1] = image[j*width+i+1];
                        jpegimage[3*i+2] = image[j*width+i+2];
                        }
        jpeg_write_scanlines(&cinfo,row_pointer,1);
                j--;
                }


/* jpeg_finish_compress(...);  */
        jpeg_finish_compress(&cinfo);
/* Release the JPEG compression object  */
        jpeg_destroy_compress(&cinfo);
/* free the jpegimage buffer memory  */
        free(jpegimage);

/* everything went on smoothly... :)  */
        return(0);
}

_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to