www.riscos.com Technical Support: |
|
The CompressJPEG module is available from RISC OS 3.6 onwards. It provides SWIs with which you can compress raw image data into a JPEG image. It is a port of release 5 of the Independent JPEG Group's software.
The module is not in the RISC OS 3.6 ROM, but is instead held in the System application. If you wish to use the module in a program, you should first use the following command to ensure it is loaded:
RMEnsure CompressJPEG 0.00 RMLoad System:Modules.JCompMod
To compress raw image data into a JPEG image, you start by calling CompressJPEG_Start, which sets up the compression environment. You then compress each row of the source image with a separate call to CompressJPEG_WriteLine. Finally you finish the compression by calling CompressJPEG_Finish.
JPEG files encode colour pictures as YUV (Y = intensity, U and V are colour) data. Compressing involves the following steps:
(Incidentally, decompression involves reversing these steps.)
Starts the JPEG compression process, setting up various parameters for it
R0 = pointer to buffer for JPEG data
R1 = size of JPEG data buffer
R2 = pointer to block of parameters:
+ | width of image in pixels |
+ | height of image in pixels |
+ | quality value (0 - 100): lower quality results in a smaller image |
+ 2 | number of 8 bit components in source: 3 24 BIT COLOUR_ 1 8 bit greyscale |
+ 6 | horizontal DPI of image, or 0 if unknown |
+ 0 | vertical DPI of image, or 0 if unknown |
R0 = JPEG tag, to be passed to other CompressJPEG SWIs
Interrupt status is undefined
Fast interrupts are enabled
Processor is in SVC mode
Not defined
This call starts the JPEG compression process, setting up various parameters for it.
The buffer for the JPEG data should be as large as possible, since the JPEG compression routines cannot guarantee to compress the image by a fixed amount.
If you wish to supply your own workspace area, its required size for a colour (24 bit) image is:
and its required size for a greyscale (8bit) image is:
An error is returned if the workspace area becomes full.
None
Compresses one row of source pixels into the JPEG buffer
R0 = JPEG tag
R1 = pointer to a row of pixels:
For colour: | a buffer of continuous RGB values - ie a byte stream of the format R, G, B, R, G, B... |
For greyscale: | a buffer of continuous 8 bit gray values |
R0, R1 preserved
Interrupt status is undefined
Fast interrupts are enabled
Processor is in SVC mode
Not defined
This call compresses one row of source pixels into the JPEG buffer. It should be called once for each row of the source data.
An error is returned if the JPEG buffer becomes full.
None
Finishes the JPEG compression process, returning the size of the complete image
R0 = JPEG tag
R0 = size of JPEG image within the buffer
Interrupt status is undefined
Fast interrupts are enabled
Processor is in SVC mode
Not defined
This call finishes the JPEG compression process, returning the size of the complete image. Any workspace claimed by the CompressJPEG module for the compression is released.
None
The pseudo-code below shows you how you might convert a 32 bpp sprite into a JPEG:
/* Pseudo C code for converting a 32bpp sprite to a JPEG */ Allocate buffer for JPEG = JPEG_buffer; Allocate buffer for workspace = workspace_buffer; Allocate buffer for line of source pixels = line_buffer; argument_block arguments; arguments.width = sprite_width_in_pixels; arguments.height = sprite_height_in_pixels; arguments.quality = quality; arguments.components = 3; arguments.horizontal_dpi = 0; arguments.vertical_dpi = 0; sprite_pointer = start_of_data_within_sprite; JPEG_tag = CompressJPEG_Start(JPEG_buffer, JPEG_buffer_size, arguments, workspace_buffer, workspace_buffer_size); for loop = 1 to sprite_height_in_pixels { convert_sprite_data_to_rgb(sprite_pointer, line_buffer); CompressJPEG_WriteLine(JPEG_tag, line_buffer); sprite_pointer += sprite_width_in_words; } CompressJPEG_Finish(JPEG_tag);