SkSampler.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2015 Google Inc.
  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. #include "include/codec/SkCodec.h"
  8. #include "src/codec/SkCodecPriv.h"
  9. #include "src/codec/SkSampler.h"
  10. #include "src/core/SkUtils.h"
  11. void SkSampler::Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
  12. SkCodec::ZeroInitialized zeroInit) {
  13. SkASSERT(dst != nullptr);
  14. if (SkCodec::kYes_ZeroInitialized == zeroInit) {
  15. return;
  16. }
  17. const int width = info.width();
  18. const int numRows = info.height();
  19. // Use the proper memset routine to fill the remaining bytes
  20. switch (info.colorType()) {
  21. case kRGBA_8888_SkColorType:
  22. case kBGRA_8888_SkColorType: {
  23. uint32_t* dstRow = (uint32_t*) dst;
  24. for (int row = 0; row < numRows; row++) {
  25. sk_memset32(dstRow, 0, width);
  26. dstRow = SkTAddOffset<uint32_t>(dstRow, rowBytes);
  27. }
  28. break;
  29. }
  30. case kRGB_565_SkColorType: {
  31. uint16_t* dstRow = (uint16_t*) dst;
  32. for (int row = 0; row < numRows; row++) {
  33. sk_memset16(dstRow, 0, width);
  34. dstRow = SkTAddOffset<uint16_t>(dstRow, rowBytes);
  35. }
  36. break;
  37. }
  38. case kGray_8_SkColorType: {
  39. uint8_t* dstRow = (uint8_t*) dst;
  40. for (int row = 0; row < numRows; row++) {
  41. memset(dstRow, 0, width);
  42. dstRow = SkTAddOffset<uint8_t>(dstRow, rowBytes);
  43. }
  44. break;
  45. }
  46. case kRGBA_F16_SkColorType: {
  47. uint64_t* dstRow = (uint64_t*) dst;
  48. for (int row = 0; row < numRows; row++) {
  49. sk_memset64(dstRow, 0, width);
  50. dstRow = SkTAddOffset<uint64_t>(dstRow, rowBytes);
  51. }
  52. break;
  53. }
  54. default:
  55. SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
  56. SkASSERT(false);
  57. break;
  58. }
  59. }