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,
14                      SkCodec::ZeroInitialized zeroInit) {
15     SkASSERT(dst != nullptr);
16 
17     if (SkCodec::kYes_ZeroInitialized == zeroInit) {
18         return;
19     }
20 
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()) {
26         case kRGBA_8888_SkColorType:
27         case kBGRA_8888_SkColorType: {
28             uint32_t* dstRow = (uint32_t*) dst;
29             for (int row = 0; row < numRows; row++) {
30                 sk_memset32(dstRow, 0, width);
31                 dstRow = SkTAddOffset<uint32_t>(dstRow, rowBytes);
32             }
33             break;
34         }
35         case kRGB_565_SkColorType: {
36             uint16_t* dstRow = (uint16_t*) dst;
37             for (int row = 0; row < numRows; row++) {
38                 sk_memset16(dstRow, 0, width);
39                 dstRow = SkTAddOffset<uint16_t>(dstRow, rowBytes);
40             }
41             break;
42         }
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             }
49             break;
50         }
51         case kRGBA_F16_SkColorType: {
52             uint64_t* dstRow = (uint64_t*) dst;
53             for (int row = 0; row < numRows; row++) {
54                 sk_memset64(dstRow, 0, width);
55                 dstRow = SkTAddOffset<uint64_t>(dstRow, rowBytes);
56             }
57             break;
58         }
59         default:
60             SkCodecPrintf("Error: Unsupported dst color type for fill().  Doing nothing.\n");
61             SkASSERT(false);
62             break;
63     }
64 }
65