CFSI-JPEG 6.46 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; Sources.CFSI-JPEG
; This makes an image of assembler code that can be loaded in by ChangeFSI
; and then called, to decode a JPEG file.

; At the start of the image are defined entrypoints.
; Conditions for entering these are:
;   lr = return address
;   sp -> a useable stack
;   r0..r3 = arguments (could be more on stack)
; On exit:
;   r0 will contain a returned result, if defined
;   r1..r3, lr will be trashed
;   all other registers will be preserved

        B       cfsi_jpeg_scan_file
        B       cfsi_jpeg_find_line
        B       cfsi_find_image_dims
        B       cfsi_jpeg_scan_file_16
        DCD     3                        ; version number.

R0 RN 0
R1 RN 1
R2 RN 2
R3 RN 3
R4 RN 4
R5 RN 5
R6 RN 6
R7 RN 7
R8 RN 8
R9 RN 9
R10 RN 10
R11 RN 11
R12 RN 12
SP RN 13
LR RN 14
PC RN 15

r0 RN 0
r1 RN 1
r2 RN 2
r3 RN 3
r4 RN 4
r5 RN 5
r6 RN 6
r7 RN 7
r8 RN 8
r9 RN 9
r10 RN 10
r11 RN 11
r12 RN 12
r14 RN 14
sl RN 10
fp RN 11
ip RN 12
sp RN 13
lr RN 14
pc RN 15
        GET     sources.csupport
73 74 75 76 77 78 79 80
        GET     sources.psrstuff

; We cope with the whole 26/32-bit thing thus:

; All our C code is APCS-32. The routines like newline() and assert() called
; from our C thus are 32-bit. We don't know about the person using the generated
; CFSI-JPEG file, so we do a run-time check for whether to do a ^ or not on
; return, depending on current mode, in the outer wrapper.
Neil Turton's avatar
Neil Turton committed
81 82 83 84 85 86 87 88 89

cfsi_jpeg_scan_file
; Entry conditions: r0 -> space (word-aligned)
;                   r1 = size of space (bytes)
;                   r2 -> file image in store
;                   r3 = file image length
        STMDB   sp!,{r1-r12,lr}
        MOV     sl,sp                 ; used to remember panic exit point
        BL      do_jpeg_scan_file
90 91 92 93 94
        MOV     r1,#0
        mrs    ,r1,CPSR
        TST     r1,#2_11100
        LDMEQIA sp!,{r1-r12,pc}^
        LDMIA   sp!,{r1-r12,pc}
Neil Turton's avatar
Neil Turton committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
; All registers preserved except r0. r0=error code, 0 for OK or other for some error.
; On exit the workspace has some interesting fields at the front:
;struct decompress_info_struct {
;        int error_code;         /* Returned err code, 0 if no error */
;        int error_argument1;    /* Supplementary error data */
;        int error_argument2;    /* Supplementary error data */
;        int a;                        /* don't touch this */
;        int b;                        /* don't touch this */
;        int /*long*/ image_width;     /* overall image width */
;        int /*long*/ image_height;    /* overall image height */
;        COLOR_SPACE jpeg_color_space; /* colorspace of JPEG file */
; ... never mind about the rest
; If all is well on exit then error_code will be 0.
; Otherwise it (and r0) is one of:
;#define E_PRE_NOT_8         1            /* Data precision not 8 */
;#define E_RESTART           2            /* Restart interval not 0 */
;#define E_MULTI_SCAN        3            /* Multi-scan file */
;#define E_TOO_HIGH          4            /* Image too high, max is %i pixels */
;#define E_BAD_SAMPLE        5            /* Bad sample factor */
;#define E_COLOUR            8            /* Bad colour space (%i), not grey or YUV */
;#define E_COMPONENTS        9            /* Bad number (%i) of components, only 1 or 3 allowed */
;#define E_TOO_WIDE          10           /* Image too wide, max is %i pixels */
; The colour space will be 1 for greyscale, 3 for YUV.

cfsi_jpeg_scan_file_16
; Entry conditions: r0 -> space (word-aligned)
;                   r1 = size of space (bytes)
;                   r2 -> file image in store
;                   r3 = file image length
        STMDB   sp!,{r1-r12,lr}
        MOV     sl,sp                 ; used to remember panic exit point
        BL      do_jpeg_scan_file_16
127 128 129 130 131
        MOV     r1,#0
        mrs    ,r1,CPSR
        TST     r1,#2_11100
        LDMEQIA sp!,{r1-r12,pc}^
        LDMIA   sp!,{r1-r12,pc}
Neil Turton's avatar
Neil Turton committed
132 133 134 135 136 137 138 139 140 141
; Simply call this instead of cfsi_jpeg_scan_file, and subsequent calls to
; cfsi_jpeg_find_line will generate pointers to lines of 16bpp pixels, instead
; of 32bpp ones.

cfsi_jpeg_find_line
; Entry conditions: r0 -> workspace
;                   r1 = required y coordinate (in 0..image_size-1)
        STMDB   sp!,{r1-r12,lr}
        MOV     sl,sp                 ; used to remember panic exit point
        BL      jpeg_find_line
142 143 144 145 146
        MOV     r1,#0
        mrs    ,r1,CPSR
        TST     r1,#2_11100
        LDMEQIA sp!,{r1-r12,pc}^
        LDMIA   sp!,{r1-r12,pc}
Neil Turton's avatar
Neil Turton committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
; On exit r0 will point to the required scan line, one word per pixel, as VIDC20 RGB pixels.

cfsi_find_image_dims
; Entry conditions: r0 -> JPEG data
;                   r1 -> word in which to put image width
;                   r2 -> word in which to put image height
;                   r3 -> word in which to put image type - 1=mono, 3=YUV
;                   r4 -> word in which to put recommended size of workspace for jpeg_scan_file
; On exit, r0=0 if everything is OK, r0=1 if this data does not look
; like JPEG.
        STMDB   sp!,{r1-r12,lr}
        MOV     sl,sp                 ; used to remember panic exit point
        STMDB   sp!,{r4}              ; fifth arg to C, placed on stack
        BL      find_image_dims
        ADD     sp,sp,#4
162 163 164 165 166
        MOV     r1,#0
        mrs    ,r1,CPSR
        TST     r1,#2_11100
        LDMEQIA sp!,{r1-r12,pc}^
        LDMIA   sp!,{r1-r12,pc}
Neil Turton's avatar
Neil Turton committed
167 168 169 170 171 172 173

; Panic exit from C code. we rely on sl being preserved through
; the c code, and use it to fetch back our call registers.
; On entry here r0 has a panic code.
exit
dividebyzero
        MOV     sp,sl
174 175 176 177
        MOV     r1,#0
        mrs    ,r1,CPSR
        TST     r1,#2_11100
        LDMEQIA sp!,{r1-r12,pc}^
Neil Turton's avatar
Neil Turton committed
178 179 180 181 182
        LDMIA   sp!,{r1-r12,pc}

; Hope the asserts are OK!
newline
assert
183
        MOV     pc,lr
Neil Turton's avatar
Neil Turton committed
184 185 186 187 188 189 190 191 192 193 194 195 196

; now the actual included stuff
        GBLL    cfsi_jpeg
cfsi_jpeg SETL  {TRUE}

        GET     sources.jdhuff
        GET     sources.jrevdct
        GET     sources.jcconv
XOS_CLI                  * &5     + (1:SHL:17)
        GET     sources.diffuse
        GET     s.rojpeg

        END