SkUnPreMultiply.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2008 The Android Open Source Project
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkUnPreMultiply_DEFINED
  8. #define SkUnPreMultiply_DEFINED
  9. #include "include/core/SkColor.h"
  10. class SK_API SkUnPreMultiply {
  11. public:
  12. typedef uint32_t Scale;
  13. // index this table with alpha [0..255]
  14. static const Scale* GetScaleTable() {
  15. return gTable;
  16. }
  17. static Scale GetScale(U8CPU alpha) {
  18. SkASSERT(alpha <= 255);
  19. return gTable[alpha];
  20. }
  21. /** Usage:
  22. const Scale* table = SkUnPreMultiply::GetScaleTable();
  23. for (...) {
  24. unsigned a = ...
  25. SkUnPreMultiply::Scale scale = table[a];
  26. red = SkUnPreMultiply::ApplyScale(scale, red);
  27. ...
  28. // now red is unpremultiplied
  29. }
  30. */
  31. static U8CPU ApplyScale(Scale scale, U8CPU component) {
  32. SkASSERT(component <= 255);
  33. return (scale * component + (1 << 23)) >> 24;
  34. }
  35. static SkColor PMColorToColor(SkPMColor c);
  36. private:
  37. static const uint32_t gTable[256];
  38. };
  39. #endif