CompressJPEG module

Introduction and Overview

The CompressJPEG module has been extended beyond the functions provided by the original version as documented in PRM 5a-609. In particular it is now possible to transcode JPEGs (convert from one form of JPEG to another without loss of information), to add comments and to create JPEGs from arbitrary paletted data.

SWI Calls

CompressJPEG_WriteLineExtendedSWI &4A504
Write lines to a JPEG from a generic source
R0=JPEG tag
R1=Flags:
Bit(s)Meaning
0-2Pixel type, size of pixels (number of colours):
ValueMeaning
01bit (2 colours, palette supplied in R3)
12bits (4 colours, palette supplied in R3)
24bits (16 colours, palette supplied in R3)
38bits (256 colours, palette supplied in R3)
416bits (32767 colours, 15bits of colour data)
532bits (16M colours, 24bits of colour data)
6Reserved
724bits (16M colour, flag bits 4 and 5 are ignored)
3Palette has double entries (flashing colours included)
4If set, colour data has any spare data in high bits
5If set, colour data holds the red component in the high bits; if clear, colour data holds the red component in the low bits
6-31Reserved
R2=Pointer to data to write
R3=Pointer to palette data (for pixel type 0-3)
R4=Number of lines to write
R5=Bytes between each line (for alignment issues)
R2=New data pointer
R4=Number of lines that were not written
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This SWI can be used to write a line to a JPEG from a more generic source than with CompressJPEG_WriteLine. Example code for Sprite conversion can be supplied.

For a pixel type of 7, RGB data is provided in RGBRGBRGB... format, making it equivalent to that of CompressJPEG_WriteLine. In this mode, the other flags have no effect.

This extended form of WriteLine requires a greater storage space than that of the standard operation. In addition to the normal storage space required :

  • width*3 extra bytes are required for colour JPEGs
  • width extra bytes are required for monochrome JPEGs

CompressJPEG_CommentSWI &4A503
Add a comment to a JPEG being created
R0=JPEG tag
R1=Flags:
Bit(s)Meaning
0Data is a string, ignore length and use control termination (10 and 9 are accepted as non-control characters)
1-31Reserved, must be 0
R2=Pointer to comment data
R3=Length of comment data (if R1 bit 0 clear)
R0 - R3=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This SWI can be used to add a comment to a JPEG in the process of being created. It should be used immediately after CompressJPEG_Start. Comment data may contain multiple lines and/or binary data (although this is discouraged).

CompressJPEG_TranscodeSWI &4A510
Convert a JPEG from one form to another
R0=Flags:
Bit(s)Meaning
0Generate a progressive JPEG, described by R7
1-2Operation on 'unknown elements':
ValueMeaning
0Copy no additional elements
1Copy comments
2Undefined
3Copy all elements
3-6Transformation type:
ValueMeaning
0No transformation
1Flip horizontally
2Flip vertically
3Rotate 90 degrees clockwise
4Rotate 180 degrees
5Rotate 90 degrees anticlockwise
6Transpose (rotate 90 degrees clockwise + flip horizontally)
7Transverse transpose (rotate 90 degrees anticlockwise + flip vertically)
8-15Reserved
7Trim the edges of the output transform
8Generate greyscale output
9Optimise for a smaller image
R1=Pointer to original JPEG
R2=Length of original JPEG
R3=Pointer to output JPEG buffer
R4=Length of output JPEG buffer
R5=Pointer to workspace, or 0 to read the length
R6=Length of workspace
R7=Pointer to scan description block, or 0 for simple progressive (if R0 bit 0 set):
OffsetContents
0Number of scans present
4For each scan (repeated), the scan description:
OffsetContents
0Components within scan
4-16Component indices
20Spectral selection start (Ss)
24Spectral selection end (Se)
28Approximation high value (Ah)
32Approximation low value (Al)
None
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This SWI is used to transcode a JPEG - that is, convert a JPEG in one form to another form. The most common use for this call is to convert a multi-pass JPEG into a single-pass JPEG suitable for rendering with the built in renderer. For more details about the scan description block, consult the Independent JPEG Groups JPEG library version 6b document 'Experts'.

Error Messages

Errors use the error base &8183C0 for the core errors, but some errors use a base of &81A8C0 :

FIXME: The error base for the JPEG-specific errors is given here as &81A8C0, but the table of those errors is relative to &81A880; the correct base needs to be confirmed.

The core errors are:

Error numberMessage and meaning
&8183C0Bad number of bits per pixel passed to CompressJPEG. The pixel depth of the line is not understood by this version of the CompressJPEG module.
&8183C1Bad number of lines passed to CompressJPEG. Too many lines have been passed to the CompressJPEG module.
&8183C2Bad buffer or workspace block. Buffers or workspace is not aligned correctly, they overlap, or their lengths are too small.
&8183C3Bad width or height. Width or height are invalid for this version of CompressJPEG.

The JPEG-specific errors have the number &81A880+n. Not all of these are possible with the current version of the module.

nNameMessage
1ARITH_NOTIMPLSorry, there are legal restrictions on arithmetic coding
2BAD_ALIGN_TYPEALIGN_TYPE is wrong, please fix
3BAD_ALLOC_CHUNKMAX_ALLOC_CHUNK is wrong, please fix
4BAD_BUFFER_MODEBogus buffer control mode
5BAD_COMPONENT_IDInvalid component ID %d in SOS
6BAD_DCTSIZEIDCT output block size %d not supported
7BAD_IN_COLORSPACEBogus input colorspace
8BAD_J_COLORSPACEBogus JPEG colorspace
9BAD_LENGTHBogus marker length
10BAD_MCU_SIZESampling factors too large for interleaved scan
11BAD_POOL_IDInvalid memory pool code %d
12BAD_PRECISIONUnsupported JPEG data precision %d
13BAD_SAMPLINGBogus sampling factors
14BAD_STATEImproper call to JPEG library in state %d
15BAD_VIRTUAL_ACCESSBogus virtual array access
16BUFFER_SIZEBuffer passed to JPEG library is too small
17CANT_SUSPENDSuspension not allowed here
18CCIR601_NOTIMPLCCIR601 sampling not implemented yet
19COMPONENT_COUNTToo many color components: %d, max %d
20CONVERSION_NOTIMPLUnsupported color conversion request
21DAC_INDEXBogus DAC index %d
22DAC_VALUEBogus DAC value 0x%x
23DHT_INDEXBogus DHT index %d
24DQT_INDEXBogus DQT index %d
25EMPTY_IMAGEEmpty JPEG image (DNL not supported)
26EOI_EXPECTEDDidn't expect more than one scan
27FILE_READInput file read error
28FILE_WRITEOutput file write error --- out of disk space?
29FRACT_SAMPLE_NOTIMPLFractional sampling not implemented yet
30HUFF_CLEN_OVERFLOWHuffman code size table overflow
31HUFF_MISSING_CODEMissing Huffman code table entry
32IMAGE_TOO_BIGMaximum supported image dimension is %u pixels
33INPUT_EMPTYEmpty input file
34INPUT_EOFPremature end of input file
35NOTIMPLNot implemented yet
36NOT_COMPILEDRequested feature was omitted at compile time
37NO_BACKING_STOREBacking store not supported
38NO_HUFF_TABLEHuffman table 0x%02x was not defined
39NO_IMAGEJPEG datastream contains no image
40NO_QUANT_TABLEQuantization table 0x%02x was not defined
41NO_SOINot a JPEG file: starts with 0x%02x 0x%02x
42OUT_OF_MEMORYInsufficient memory (case %d)
43QUANT_COMPONENTSCannot quantize more than %d color components
44QUANT_FEW_COLORSCannot quantize to fewer than %d colors
45QUANT_MANY_COLORSCannot quantize to more than %d colors
46SOF_DUPLICATEInvalid JPEG file structure: two SOF markers
47SOF_NO_SOSInvalid JPEG file structure: missing SOS marker
48SOF_UNSUPPORTEDUnsupported JPEG process: SOF type 0x%02x
49SOI_DUPLICATEInvalid JPEG file structure: two SOI markers
50SOS_NO_SOFInvalid JPEG file structure: SOS before SOF
51TOO_LITTLE_DATAApplication transferred too few scanlines
52UNKNOWN_MARKERUnsupported marker type 0x%02x
53VIRTUAL_BUGVirtual array controller messed up
54WIDTH_OVERFLOWImage too wide for this implementation
55BAD_DCT_COEFDCT coefficient out of range
56BAD_HUFF_TABLEBogus Huffman table definition
57BAD_PROGRESSIONInvalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d
58BAD_PROG_SCRIPTInvalid progressive parameters at scan script entry %d
59BAD_SCAN_SCRIPTInvalid scan script at entry %d
60MISMATCHED_QUANT_TABLECannot transcode due to multiple use of quantization table %d
61MISSING_DATAScan script does not transmit all data
62MODE_CHANGEInvalid color quantization mode change
63WBUFFER_SIZEWorkspace buffer passed to JPEG library is too small