| Martyn Capewell | f9e8ab0 | 2009-12-07 15:00:19 +0000 | [diff] [blame] | 1 | /* libs/pixelflinger/col32cb16blend.S | 
| Dave Butcher | ef18202 | 2010-08-19 12:31:34 +0100 | [diff] [blame] | 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 |  */ | 
| Martyn Capewell | f9e8ab0 | 2009-12-07 15:00:19 +0000 | [diff] [blame] | 17 |  | 
 | 18 |     .text | 
| Nikola Veljkovic | 1109f11 | 2016-07-13 22:08:18 +0200 | [diff] [blame] | 19 |     .balign 4 | 
| Martyn Capewell | f9e8ab0 | 2009-12-07 15:00:19 +0000 | [diff] [blame] | 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 |  | 
 | 39 | scanline_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 |  | 
 | 54 | 1: | 
 | 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 |  |