| 246 | } |
| 247 | |
| 248 | void ImposterCapture::_separateAlpha( GBitmap *imposterOut ) |
| 249 | { |
| 250 | PROFILE_START(TSShapeInstance_snapshot_sb_separate); |
| 251 | |
| 252 | // TODO: Remove all this when we get rid of the 'render on black/white'. |
| 253 | |
| 254 | // now separate the color and alpha channels |
| 255 | GBitmap *bmp = new GBitmap; |
| 256 | bmp->allocateBitmap(mDim, mDim, false, GFXFormatR8G8B8A8); |
| 257 | U8 * wbmp = (U8*)mWhiteBmp->getBits(0); |
| 258 | U8 * bbmp = (U8*)mBlackBmp->getBits(0); |
| 259 | U8 * dst = (U8*)bmp->getBits(0); |
| 260 | |
| 261 | const U32 pixCount = mDim * mDim; |
| 262 | |
| 263 | // simpler, probably faster... |
| 264 | for ( U32 i=0; i < pixCount; i++ ) |
| 265 | { |
| 266 | // Shape on black background is alpha * color, shape on white |
| 267 | // background is alpha * color + (1-alpha) * 255 we want 255 * |
| 268 | // alpha, or 255 - (white - black). |
| 269 | // |
| 270 | // JMQ: or more verbosely: |
| 271 | // cB = alpha * color + (0 * (1 - alpha)) |
| 272 | // cB = alpha * color |
| 273 | // cW = alpha * color + (255 * (1 - alpha)) |
| 274 | // cW = cB + (255 * (1 - alpha)) |
| 275 | // solving for alpha |
| 276 | // cW - cB = 255 * (1 - alpha) |
| 277 | // (cW - cB)/255 = (1 - alpha) |
| 278 | // alpha = 1 - (cW - cB)/255 |
| 279 | // since we want alpha*255, multiply through by 255 |
| 280 | // alpha * 255 = 255 - cW - cB |
| 281 | U32 alpha = 255 - (wbmp[i*3+0] - bbmp[i*3+0]); |
| 282 | alpha += 255 - (wbmp[i*3+1] - bbmp[i*3+1]); |
| 283 | alpha += 255 - (wbmp[i*3+2] - bbmp[i*3+2]); |
| 284 | |
| 285 | if ( alpha != 0 ) |
| 286 | { |
| 287 | F32 floatAlpha = ((F32)alpha)/(3.0f*255.0f); |
| 288 | dst[i*4+0] = (U8)(bbmp[i*3+0] / floatAlpha); |
| 289 | dst[i*4+1] = (U8)(bbmp[i*3+1] / floatAlpha); |
| 290 | dst[i*4+2] = (U8)(bbmp[i*3+2] / floatAlpha); |
| 291 | |
| 292 | // Before we assign the alpha we "fizzle" the value |
| 293 | // if its greater than 84. This causes the imposter |
| 294 | // to dissolve instead of popping into view. |
| 295 | alpha /= 3; |
| 296 | dst[i*4+3] = (U8)alpha; |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | dst[i*4+0] = dst[i*4+1] = dst[i*4+2] = dst[i*4+3] = 0; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | PROFILE_END(); // TSShapeInstance_snapshot_sb_separate |
| 305 |
nothing calls this directly
no test coverage detected