| 1 | /* |
| 2 | * Texture Filtering |
| 3 | * Version: 1.0 |
| 4 | * |
| 5 | * Copyright (C) 2007 Hiroshi Morii All Rights Reserved. |
| 6 | * Email koolsmoky(at)users.sourceforge.net |
| 7 | * Web http://www.3dfxzone.it/koolsmoky |
| 8 | * |
| 9 | * this is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * this is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with GNU Make; see the file COPYING. If not, write to |
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | */ |
| 23 | |
| 24 | /* Based on Derek Liauw Kie Fa and Rice1964 Super2xSaI code */ |
| 25 | |
| 26 | #include "TextureFilters.h" |
| 27 | |
| 28 | #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D)) |
| 29 | |
| 30 | void Super2xSaI_8888(uint32 *srcPtr, uint32 *destPtr, uint32 width, uint32 height, uint32 pitch) |
| 31 | { |
| 32 | #define SAI_INTERPOLATE_8888(A, B) ((A & 0xFEFEFEFE) >> 1) + ((B & 0xFEFEFEFE) >> 1) + (A & B & 0x01010101) |
| 33 | #define SAI_Q_INTERPOLATE_8888(A, B, C, D) ((A & 0xFCFCFCFC) >> 2) + ((B & 0xFCFCFCFC) >> 2) + ((C & 0xFCFCFCFC) >> 2) + ((D & 0xFCFCFCFC) >> 2) \ |
| 34 | + ((((A & 0x03030303) + (B & 0x03030303) + (C & 0x03030303) + (D & 0x03030303)) >> 2) & 0x03030303) |
| 35 | |
| 36 | #define SAI_INTERPOLATE SAI_INTERPOLATE_8888 |
| 37 | #define SAI_Q_INTERPOLATE SAI_Q_INTERPOLATE_8888 |
| 38 | |
| 39 | uint32 destWidth = width << 1; |
| 40 | |
| 41 | uint32 color4, color5, color6; |
| 42 | uint32 color1, color2, color3; |
| 43 | uint32 colorA0, colorA1, colorA2, colorA3; |
| 44 | uint32 colorB0, colorB1, colorB2, colorB3; |
| 45 | uint32 colorS1, colorS2; |
| 46 | uint32 product1a, product1b, product2a, product2b; |
| 47 | |
| 48 | #include "TextureFilters_2xsai.h" |
| 49 | |
| 50 | #undef SAI_INTERPOLATE |
| 51 | #undef SAI_Q_INTERPOLATE |
| 52 | } |
| 53 | |
| 54 | #if !_16BPP_HACK |
| 55 | void Super2xSaI_4444(uint16 *srcPtr, uint16 *destPtr, uint32 width, uint32 height, uint32 pitch) |
| 56 | { |
| 57 | #define SAI_INTERPOLATE_4444(A, B) ((A & 0xEEEE) >> 1) + ((B & 0xEEEE) >> 1) + (A & B & 0x1111) |
| 58 | #define SAI_Q_INTERPOLATE_4444(A, B, C, D) ((A & 0xCCCC) >> 2) + ((B & 0xCCCC) >> 2) + ((C & 0xCCCC) >> 2) + ((D & 0xCCCC) >> 2) \ |
| 59 | + ((((A & 0x3333) + (B & 0x3333) + (C & 0x3333) + (D & 0x3333)) >> 2) & 0x3333) |
| 60 | |
| 61 | #define SAI_INTERPOLATE SAI_INTERPOLATE_4444 |
| 62 | #define SAI_Q_INTERPOLATE SAI_Q_INTERPOLATE_4444 |
| 63 | |
| 64 | uint32 destWidth = width << 1; |
| 65 | uint32 destHeight = height << 1; |
| 66 | |
| 67 | uint16 color4, color5, color6; |
| 68 | uint16 color1, color2, color3; |
| 69 | uint16 colorA0, colorA1, colorA2, colorA3; |
| 70 | uint16 colorB0, colorB1, colorB2, colorB3; |
| 71 | uint16 colorS1, colorS2; |
| 72 | uint16 product1a, product1b, product2a, product2b; |
| 73 | |
| 74 | #include "TextureFilters_2xsai.h" |
| 75 | |
| 76 | #undef SAI_INTERPOLATE |
| 77 | #undef SAI_Q_INTERPOLATE |
| 78 | } |
| 79 | |
| 80 | void Super2xSaI_1555(uint16 *srcPtr, uint16 *destPtr, uint32 width, uint32 height, uint32 pitch) |
| 81 | { |
| 82 | #define SAI_INTERPOLATE_1555(A, B) ((A & 0x7BDE) >> 1) + ((B & 0x7BDE) >> 1) + (A & B & 0x8421) |
| 83 | #define SAI_Q_INTERPOLATE_1555(A, B, C, D) ((A & 0x739C) >> 2) + ((B & 0x739C) >> 2) + ((C & 0x739C) >> 2) + ((D & 0x739C) >> 2) \ |
| 84 | + ((((A & 0x8C63) + (B & 0x8C63) + (C & 0x8C63) + (D & 0x8C63)) >> 2) & 0x8C63) |
| 85 | |
| 86 | #define SAI_INTERPOLATE SAI_INTERPOLATE_1555 |
| 87 | #define SAI_Q_INTERPOLATE SAI_Q_INTERPOLATE_1555 |
| 88 | |
| 89 | uint32 destWidth = width << 1; |
| 90 | uint32 destHeight = height << 1; |
| 91 | |
| 92 | uint16 color4, color5, color6; |
| 93 | uint16 color1, color2, color3; |
| 94 | uint16 colorA0, colorA1, colorA2, colorA3; |
| 95 | uint16 colorB0, colorB1, colorB2, colorB3; |
| 96 | uint16 colorS1, colorS2; |
| 97 | uint16 product1a, product1b, product2a, product2b; |
| 98 | |
| 99 | #include "TextureFilters_2xsai.h" |
| 100 | |
| 101 | #undef SAI_INTERPOLATE |
| 102 | #undef SAI_Q_INTERPOLATE |
| 103 | } |
| 104 | |
| 105 | void Super2xSaI_565(uint16 *srcPtr, uint16 *destPtr, uint32 width, uint32 height, uint32 pitch) |
| 106 | { |
| 107 | #define SAI_INTERPOLATE_565(A, B) ((A & 0xF7DE) >> 1) + ((B & 0xF7DE) >> 1) + (A & B & 0x0821) |
| 108 | #define SAI_Q_INTERPOLATE_565(A, B, C, D) ((A & 0xE79C) >> 2) + ((B & 0xE79C) >> 2) + ((C & 0xE79C) >> 2) + ((D & 0xE79C) >> 2) \ |
| 109 | + ((((A & 0x1863) + (B & 0x1863) + (C & 0x1863) + (D & 0x1863)) >> 2) & 0x1863) |
| 110 | |
| 111 | #define SAI_INTERPOLATE SAI_INTERPOLATE_565 |
| 112 | #define SAI_Q_INTERPOLATE SAI_Q_INTERPOLATE_565 |
| 113 | |
| 114 | uint32 destWidth = width << 1; |
| 115 | uint32 destHeight = height << 1; |
| 116 | |
| 117 | uint16 color4, color5, color6; |
| 118 | uint16 color1, color2, color3; |
| 119 | uint16 colorA0, colorA1, colorA2, colorA3; |
| 120 | uint16 colorB0, colorB1, colorB2, colorB3; |
| 121 | uint16 colorS1, colorS2; |
| 122 | uint16 product1a, product1b, product2a, product2b; |
| 123 | |
| 124 | #include "TextureFilters_2xsai.h" |
| 125 | |
| 126 | #undef SAI_INTERPOLATE |
| 127 | #undef SAI_Q_INTERPOLATE |
| 128 | } |
| 129 | |
| 130 | void Super2xSaI_8(uint8 *srcPtr, uint8 *destPtr, uint32 width, uint32 height, uint32 pitch) |
| 131 | { |
| 132 | #define SAI_INTERPOLATE_8(A, B) ((A & 0xFE) >> 1) + ((B & 0xFE) >> 1) + (A & B & 0x01) |
| 133 | #define SAI_Q_INTERPOLATE_8(A, B, C, D) ((A & 0xFC) >> 2) + ((B & 0xFC) >> 2) + ((C & 0xFC) >> 2) + ((D & 0xFC) >> 2) \ |
| 134 | + ((((A & 0x03) + (B & 0x03) + (C & 0x03) + (D & 0x03)) >> 2) & 0x03) |
| 135 | |
| 136 | #define SAI_INTERPOLATE SAI_INTERPOLATE_8 |
| 137 | #define SAI_Q_INTERPOLATE SAI_Q_INTERPOLATE_8 |
| 138 | |
| 139 | uint32 destWidth = width << 1; |
| 140 | uint32 destHeight = height << 1; |
| 141 | |
| 142 | uint8 color4, color5, color6; |
| 143 | uint8 color1, color2, color3; |
| 144 | uint8 colorA0, colorA1, colorA2, colorA3; |
| 145 | uint8 colorB0, colorB1, colorB2, colorB3; |
| 146 | uint8 colorS1, colorS2; |
| 147 | uint8 product1a, product1b, product2a, product2b; |
| 148 | |
| 149 | #include "TextureFilters_2xsai.h" |
| 150 | |
| 151 | #undef SAI_INTERPOLATE |
| 152 | #undef SAI_Q_INTERPOLATE |
| 153 | } |
| 154 | #endif /* !_16BPP_HACK */ |