blob: 39f94e164fcb77649d6b4321ef05149839f88a00 [file] [log] [blame]
bigbiff673c7ae2020-12-02 19:44:56 -05001/* libs/pixelflinger/col32cb16blend.S
2 *
3 * Copyright (C) 2009 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 .text
19 .balign 4
20
21 .global scanline_col32cb16blend_arm
22
23//
24// This function alpha blends a fixed color into a destination scanline, using
25// the formula:
26//
27// d = s + (((a + (a >> 7)) * d) >> 8)
28//
29// where d is the destination pixel,
30// s is the source color,
31// a is the alpha channel of the source color.
32//
33
34// r0 = destination buffer pointer
35// r1 = color value
36// r2 = count
37
38
39scanline_col32cb16blend_arm:
40 push {r4-r10, lr} // stack ARM regs
41
42 mov r5, r1, lsr #24 // shift down alpha
43 mov r9, #0xff // create mask
44 add r5, r5, r5, lsr #7 // add in top bit
45 rsb r5, r5, #256 // invert alpha
46 and r10, r1, #0xff // extract red
47 and r12, r9, r1, lsr #8 // extract green
48 and r4, r9, r1, lsr #16 // extract blue
49 mov r10, r10, lsl #5 // prescale red
50 mov r12, r12, lsl #6 // prescale green
51 mov r4, r4, lsl #5 // prescale blue
52 mov r9, r9, lsr #2 // create dest green mask
53
541:
55 ldrh r8, [r0] // load dest pixel
56 subs r2, r2, #1 // decrement loop counter
57 mov r6, r8, lsr #11 // extract dest red
58 and r7, r9, r8, lsr #5 // extract dest green
59 and r8, r8, #0x1f // extract dest blue
60
61 smlabb r6, r6, r5, r10 // dest red * alpha + src red
62 smlabb r7, r7, r5, r12 // dest green * alpha + src green
63 smlabb r8, r8, r5, r4 // dest blue * alpha + src blue
64
65 mov r6, r6, lsr #8 // shift down red
66 mov r7, r7, lsr #8 // shift down green
67 mov r6, r6, lsl #11 // shift red into 565
68 orr r6, r7, lsl #5 // shift green into 565
69 orr r6, r8, lsr #8 // shift blue into 565
70
71 strh r6, [r0], #2 // store pixel to dest, update ptr
72 bne 1b // if count != 0, loop
73
74 pop {r4-r10, pc} // return
75
76
77