-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdjust.s
211 lines (135 loc) · 5.1 KB
/
Adjust.s
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
AREA MotionBlur, CODE, READONLY
PRESERVE8
IMPORT main
IMPORT getPicAddr
IMPORT putPic
IMPORT getPicWidth
IMPORT getPicHeight
EXPORT start
start
BL getPicAddr ;load the start address of the image in R4
MOV R4, R0 ;r4=pic adr.
BL getPicHeight ;load the height of the image (rows) in R5
MOV R5, R0 ;r5=height
BL getPicWidth ;load the width of the image (columns) in R6
MOV R6, R0 ;r6= width
MUL R7,R5,R6 ;size of the image
LDR R8,=0 ;pixel count =0
nextPixel
LDR R0,=0 ;red value
LDR R1,=0 ;green value
LDR R2,=0 ;blue value
LDR R3,=0 ;pixel value
CMP R8,R7 ;while pixelCount<pixel size
BHS finish
LDR R9,=0 ;pixel value=0
LDR R9,[R4,R8,LSL#2] ;R9=pixel value
MOV R3,R9 ;R3=PIXEL VALUE----dont change
BL getRed ;get back r0-red
MOV R2,R0 ;R2=red value
BL update
MOV R0,R2 ;r0 is red value
BL getGreen ;get back r1-green
MOV R2,R1 ;R2=green value
BL update
MOV R1,R2
BL getBlue ;get back r2-blue
MOV R2,R2
BL update
;MOV R2,R2
BL recombineColors ;ro-recombined colors
STR R0,[R4,R8,LSL#2]
;store pixel value
ADD R8,R8,#1
B nextPixel
;------------------------------------------------------------------------------------------------------------------------------------
;update pixel subroutine
;updates the given pixel value
;parameters passed R2-value to be updated
;parameters returned R2-updated value
update
STMFD sp!,{R4-R12,lr}
MOV R4,R2 ;R4=value to be updated.
LDR R5,=30 ;brightness=30
LDR R6,=20 ;contrast=20
LDR R7,=0 ;updated value
LDR R8,=0
MUL R7,R4,R6 ;updated value = RED * contrast
MOV R8,R7,LSR#4 ; (updated value = updated value * contrast)/16
ADD R8,R8,R5 ;updated value + brightness
CMP R8,#255
BLS done
MOV R8,#255
done
MOV R2,R8 ;return the updated value
LDMFD sp!,{R4-R12,pc}
;----------------------------------------------------------------------------------------------------------------------------------------------
;extracts the red value fromt the given pixel value
;getRed subroutine
;parameters passed R3=pixel value
;parameters returned R0-red value
getRed
STMFD sp!,{R4-R12,lr}
MOV R5,#0 ;red value -0
MOV R4,#0 ;restart registers
MOV R4,R3 ;R4=pixel value
BIC R5,R4,#0xFF00FFFF ;R5 = red value in its postion
MOV R5,R5,LSR#16 ;shift red value by 16 bits to the right to do some calculations
MOV R0,R5 ;pass parametere red value in correct position
LDMFD sp!,{R4-R12,pc}
;------------------------------------------------------------------------------
;extracts the green value fromt the given pixel value
;getGreen subroutine
;parameters passed R3=pixel value
;parameters returned R1-green value
getGreen
STMFD sp!,{R4-R12,lr}
MOV R5,#0 ;green value -0
MOV R4,#0 ;restart registers.
MOV R4,R3 ;R4=pixel value
BIC R5,R4,#0xFFFF00FF ;R5 = red value in its postion
MOV R5,R5,LSR#8 ;shift red value by 16 bits to the right to do some calculations
MOV R1,R5 ;pass parametere red value in position of least significant bit.
LDMFD sp!,{R4-R12,pc}
;----------------------------------------------------------------------------------------------------------------------------------------------------
;extracts the blue value fromt the given pixel value
;getBlue subroutine
;parameters passed R3=pixel value
;parameters returned R2-blue value
getBlue
STMFD sp!,{R4-R12,lr}
MOV R5,#0 ;green value -0
MOV R4,#0 ;restart registers
MOV R4,R3 ;R4=pixel value
BIC R5,R4,#0xFFFFFF00 ;R5 = red value in its postion
MOV R2,R5 ;pass parametere red value in position of least significant bit.
LDMFD sp!,{R4-R12,pc}
;-------------------------------------------------------------------------------------------------------------------------------------------------------
;--------------------------------------------------------------------------------------------------------------------------------------------------------------
;recombine funcion
;recombines the average colors
;parameters passed r0=updated red
;parameters passed r1-updated green
;parametrs passed r2-updated blue
;parameters returned r0-updated pixel value
recombineColors
STMFD sp!,{R4-R12,lr}
MOV R7,#0
MOV R4,R0 ;R4-red
MOV R5,R1 ;R5-green
MOV R6,R2 ;R6-blue
;move red into its correct position.MSB
MOV R4,R4,LSL#16
;move green into its correct pos.
MOV R5,R5,LSL#8
;blue value already in its correct pos. r6
ORR R7,R4,R5 ;ORing red and green
ORR R7,R7,R6 ;ORing red and green and blue
;R0-recombined value
MOV R0,R7 ;pass the recombined RGB pixel value to main.
LDMFD sp!,{R4-R12,pc}
;-------------------------------------------------------------------------------------------------
finish
BL putPic ; re-display the updated image
stop B stop
END