Skip to content

Oscar Software Framework Manual JPEG Encoding Module

sparre edited this page Apr 5, 2013 · 6 revisions

Go to Table of Contents.

Table of Contents

JPEG Encoding Module (jpg)

Description

This module allows images to be compressed into a JPEG image. A raw image which is supplied to the module's encoding function as an OSC_PICTURE is compressed according to a compression factor and written into the supplied buffer. This data may then be written directly into a file to form a valid JPEG image.

Dependencies

  • log: For logging.

Usage

 {
     unsigned char *jpgPicEnd, jpgbuf[500000]; /* (1) */
     struct OSC_PICTURE pic;
     
     colpic.data = picture_data; /* (2) */
     colpic.type = OSC_PICTURE_BGR_24;
     colpic.width = picture_width;
     colpic.height = picture_height;
     
     jpgPicEnd = OscJpgEncode(&colpic, jpgbuf, 1024); /* (3) */
     
     fp = fopen (filename, "wb"); /* (4) */
     fwrite (jpgbuf, 1, jpgPicEnd - jpgbuf, fp);
     fclose(fp);
 }
  1. Allocate enough memory for the final image.
  2. Contruct the OSC_PICTURE struct.
  3. Encode the image.
  4. Write the encoded image to a file.
The compression factor can be any value in the range from 0 (minimal compression) to 1024 (heavy compression).
Clone this wiki locally