/* * Copyright (c) 2009 M Joonas Pihlaja * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. */ /* Reference implementation using divisions. Since the slow path is * so very slow this version specialises runs of constant or solid * pixels. */ #include #include /* Pixel format config for a 32 bit pixel with 8 bit components. Only * the location of alpha matters. */ #ifndef ASHIFT # define ASHIFT 24 #endif #define RSHIFT ((24 + ASHIFT) % 32) #define GSHIFT ((16 + ASHIFT) % 32) #define BSHIFT (( 8 + ASHIFT) % 32) #define AMASK (255 << ASHIFT) #define RMASK (255 << RSHIFT) #define GMASK (255 << GSHIFT) #define BMASK (255 << BSHIFT) void unpremultiply_with_div( uint32_t * restrict dst, uint32_t const * restrict src, size_t n) { size_t i; for (i=0; i> ASHIFT) & 0xFF; uint32_t r = (rgba >> RSHIFT) & 0xFF; uint32_t g = (rgba >> GSHIFT) & 0xFF; uint32_t b = (rgba >> BSHIFT) & 0xFF; r = r*255 / a; g = g*255 / a; b = b*255 / a; dst[i] = (r<