Repository navigation
Expand file tree
/
Copy pathpicture.S
More file actions
194 lines (184 loc) · 5.67 KB
/
Copy pathpicture.S
File metadata and controls
194 lines (184 loc) · 5.67 KB
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
#include "firmware.h"
#include "abi.h"
#include "hooks.h"
.syntax unified
.arm
.text
/* Picture processing hooks for effect extensions. They link into the Framing
region. */
#ifdef HOOK_MODULE_GAMMA_DIRTY
// Z=1 only for an owned record in r0. Preserves all registers.
picture_owned:
push {r0-r3, lr}
ldr r1, =GRKIT_HEADER_REFERENCE
ldr r2, [r1, #GRKIT_HOST_COUNT]
ldr r1, [r1, #GRKIT_HOST_RECORDS]
cmp r2, #0
beq 2f
1: cmp r0, r1
beq 3f
add r1, r1, #GRKIT_RECORD_SIZE
subs r2, r2, #1
bne 1b
2: movs r3, #1
3: pop {r0-r3, pc}
// Replaces `ldrb r3, [r4, #0xe]` (the gamma stage flag) in the live-view diff.
.global module_gamma_dirty
module_gamma_dirty:
push {r0-r2, r12, lr}
ldrb r3, [r4, #0xe]
ldr r0, [r5, #8]
bl picture_owned
movne r0, #0
// The native diff sets the stage flags from native inputs only. When the
// live-view record or the adjustments of a private record change, rebuild
// the curves now, and the color matrix (+5, the monochrome weights and the
// saturation) and the YCbCr matrix (+7, the post matrix) on the next
// update: their stages have already run. This hook runs only for
// ImageTuningLiveview.
ldr r1, =GRKIT_HEADER_REFERENCE
ldr r2, [r1, #GRKIT_HOST_LIVE_RECORD]
str r0, [r1, #GRKIT_HOST_LIVE_RECORD]
subs r2, r2, r0
movne r2, #1
ldr r12, [r1, #GRKIT_HOST_PARAMETER_CHANGES]
ldr lr, [r1, #GRKIT_HOST_LIVE_PARAMETER_CHANGES]
str r12, [r1, #GRKIT_HOST_LIVE_PARAMETER_CHANGES]
cmp r12, lr
cmpne r0, #0
movne r2, #1
cmp r2, #0
strbne r2, [r4, #5]
strbne r2, [r4, #7]
// Private records and record changes always rebuild the curves.
orrs r2, r2, r0
bne dirty_on
// Native curves must also be rebuilt when leaving a private record.
ldrb r0, [r5, #0x9b]
cmp r0, #0
bne dirty_resume
ldr r0, [r4, #0x17c]
add r0, r0, #(GAMMA_BUILT & ~0xff)
ldr r2, [r0, #(GAMMA_BUILT & 0xff)]
cmp r2, #0
bne dirty_resume
dirty_on:
mov r3, #1
dirty_resume:
pop {r0-r2, r12, lr}
ldr pc, =HOOK_MODULE_GAMMA_DIRTY_RESUME
#endif
/* Grain: the native grain stage of DigitalFilterProcess, which runs for
recorded pictures only. SetEffectParameter reads the grain settings from the
shot settings (r4 on GR IV, r5 on GR III); these hooks replace each load with
the Grain level, and Off keeps the native value. The stage gate ignores grain
for Standard, so the gate wrapper turns the stage on for any level. */
#if defined(HOOK_GRAIN_ENABLE) || defined(HOOK_GRAIN_PARTICLE)
// r3 = the level minus 1, or a value above 2 for Off. Flags change.
grain_level:
ldr r3, =GRKIT_HEADER_REFERENCE
ldr r3, [r3, #GRKIT_PLUGIN_GRAIN_LEVEL]
sub r3, r3, #1
cmp r3, #2
bx lr
// Replaces the BL to the stage gate. r0 = plan, r1 = shot settings. The caller
// reloads r0 and r1 after the call.
.global grain_gate
grain_gate:
push {r0, lr}
ldr r12, =HOOK_GRAIN_GATE_TARGET
blx r12
bl grain_level
pop {r0, lr}
movls r3, #1
strbls r3, [r0, #GRAIN_GATE_FLAG]
bx lr
#endif
#ifdef HOOK_GRAIN_ENABLE
// GR IV replaces `ldrb r3, [r4, #0x7b5]` (grain on). A cmp of r3 follows each
// replaced load, so the hooks may change the flags.
.global grain_enable
grain_enable:
push {lr}
bl grain_level
pop {lr}
movls r3, #1
ldrbhi r3, [r4, #0x7b5]
bx lr
// Replaces `ldrb r3, [r4, #0x7b7]` (strength 0..2): weak, medium, strong.
.global grain_strength
grain_strength:
push {lr}
bl grain_level
pop {lr}
ldrbhi r3, [r4, #0x7b7]
bx lr
// Replaces `ldrb r3, [r4, #0x7b6]` (size 0..2). The size follows the ISO of
// the shot: small to ISO 400, medium to ISO 800, large above. +0xba0 holds the
// float APEX Sv that the EXIF ISO uses. The native ISO index is
// round((Sv - 1) * 3), so ISO 400 ends at Sv 43/6 and ISO 800 at Sv 49/6.
// For a positive float, the bit patterns compare as the values. A negative
// value, an infinity, or a NaN gives small grain.
.global grain_size
grain_size:
push {lr}
bl grain_level
pop {lr}
ldrbhi r3, [r4, #0x7b6]
bxhi lr
ldr r12, [r4, #0xba0]
ldr r3, =0x7f800000
cmp r12, r3
movhs r3, #0
bxhs lr
ldr r3, =0x40e55555
cmp r12, r3
movlo r3, #0
bxlo lr
ldr r3, =0x4102aaab
cmp r12, r3
movlo r3, #1
movhs r3, #2
bx lr
#endif
#ifdef HOOK_GRAIN_PARTICLE
// GR III replaces `ldrb r3, [r5, #0x795]` (Particle 0..3). The granulation
// scales the noise amplitude by 256, 128, or 64 for Particle 1, 2, or 3
// (0x5367ae28), so level 1..3 maps to Particle 3..1.
.global grain_particle
grain_particle:
push {lr}
bl grain_level
pop {lr}
rsbls r3, r3, #3
ldrbhi r3, [r5, #0x795]
bx lr
#endif
/* Capture: record the effect of this shot as the Image Control tag. Replaces
the ImageTone BL in PentaxMakernoteEntryDataSetter. r1 is the IFD entry, and
r2 the shot settings. FW_IFD_SET_SHORT(entry, 0, value) stores the u16 tag
value. A shot without a private record keeps the native tag. */
.global picture_capture_tone
picture_capture_tone:
push {r0-r4, lr}
mov r0, r2
bl picture_capture_record
mov r12, r0
pop {r0-r4, lr}
cmp r12, #0
ldreq pc, =HOOK_PICTURE_CAPTURE_TONE_TARGET
mov r0, r1
mov r1, #0
add r12, r12, #(GRKIT_RECORD_CODE & ~0xff)
ldrh r2, [r12, #(GRKIT_RECORD_CODE & 0xff)]
ldr pc, =FW_IFD_SET_SHORT
// JpegEncodeMacroProcess::Execute entry: r0 = process, r1 = message. The stub
// keeps every argument and replays the displaced `mov ip, sp`.
.global picture_encode_entry
picture_encode_entry:
push {r0-r3, r12, lr}
bl picture_encode
pop {r0-r3, r12, lr}
mov r12, sp
ldr pc, =HOOK_PICTURE_ENCODE_ENTRY_RESUME
.ltorg