msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 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 | |
| 8 | #include "SkCodec.h" |
| 9 | #include "SkCodecPriv.h" |
| 10 | #include "SkSampler.h" |
| 11 | #include "SkUtils.h" |
| 12 | |
| 13 | void SkSampler::Fill(const SkImageInfo& info, void* dst, size_t rowBytes, |
Leon Scroggins III | e643a9e | 2018-08-03 16:15:04 -0400 | [diff] [blame] | 14 | SkCodec::ZeroInitialized zeroInit) { |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 15 | SkASSERT(dst != nullptr); |
| 16 | |
Leon Scroggins III | e643a9e | 2018-08-03 16:15:04 -0400 | [diff] [blame] | 17 | if (SkCodec::kYes_ZeroInitialized == zeroInit) { |
| 18 | return; |
| 19 | } |
| 20 | |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 21 | const int width = info.width(); |
| 22 | const int numRows = info.height(); |
| 23 | |
| 24 | // Use the proper memset routine to fill the remaining bytes |
| 25 | switch (info.colorType()) { |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 26 | case kRGBA_8888_SkColorType: |
| 27 | case kBGRA_8888_SkColorType: { |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 28 | uint32_t* dstRow = (uint32_t*) dst; |
| 29 | for (int row = 0; row < numRows; row++) { |
Nigel Tao | fddc6fa | 2018-08-31 09:37:34 +1000 | [diff] [blame] | 30 | sk_memset32(dstRow, 0, width); |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 31 | dstRow = SkTAddOffset<uint32_t>(dstRow, rowBytes); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 32 | } |
| 33 | break; |
| 34 | } |
| 35 | case kRGB_565_SkColorType: { |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 36 | uint16_t* dstRow = (uint16_t*) dst; |
| 37 | for (int row = 0; row < numRows; row++) { |
Nigel Tao | fddc6fa | 2018-08-31 09:37:34 +1000 | [diff] [blame] | 38 | sk_memset16(dstRow, 0, width); |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 39 | dstRow = SkTAddOffset<uint16_t>(dstRow, rowBytes); |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 40 | } |
| 41 | break; |
| 42 | } |
Nigel Tao | fddc6fa | 2018-08-31 09:37:34 +1000 | [diff] [blame] | 43 | case kGray_8_SkColorType: { |
| 44 | uint8_t* dstRow = (uint8_t*) dst; |
| 45 | for (int row = 0; row < numRows; row++) { |
| 46 | memset(dstRow, 0, width); |
| 47 | dstRow = SkTAddOffset<uint8_t>(dstRow, rowBytes); |
| 48 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 49 | break; |
Nigel Tao | fddc6fa | 2018-08-31 09:37:34 +1000 | [diff] [blame] | 50 | } |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 51 | case kRGBA_F16_SkColorType: { |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 52 | uint64_t* dstRow = (uint64_t*) dst; |
| 53 | for (int row = 0; row < numRows; row++) { |
Nigel Tao | fddc6fa | 2018-08-31 09:37:34 +1000 | [diff] [blame] | 54 | sk_memset64(dstRow, 0, width); |
msarett | f7eb6fc | 2016-09-13 09:04:11 -0700 | [diff] [blame] | 55 | dstRow = SkTAddOffset<uint64_t>(dstRow, rowBytes); |
| 56 | } |
| 57 | break; |
| 58 | } |
msarett | e6dd004 | 2015-10-09 11:07:34 -0700 | [diff] [blame] | 59 | default: |
| 60 | SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n"); |
| 61 | SkASSERT(false); |
| 62 | break; |
| 63 | } |
| 64 | } |