xref: /aosp_15_r20/external/skia/src/codec/SkSampler.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 "src/codec/SkSampler.h"
9 
10 #include "include/codec/SkCodec.h"
11 #include "include/core/SkColorType.h"
12 #include "include/core/SkImageInfo.h"
13 #include "include/private/base/SkTemplates.h"
14 #include "src/codec/SkCodecPriv.h"
15 #include "src/core/SkMemset.h"
16 
17 #include <cstdint>
18 #include <cstring>
19 
Fill(const SkImageInfo & info,void * dst,size_t rowBytes,SkCodec::ZeroInitialized zeroInit)20 void SkSampler::Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
21                      SkCodec::ZeroInitialized zeroInit) {
22     SkASSERT(dst != nullptr);
23 
24     if (SkCodec::kYes_ZeroInitialized == zeroInit) {
25         return;
26     }
27 
28     const int width = info.width();
29     const int numRows = info.height();
30 
31     // Use the proper memset routine to fill the remaining bytes
32     switch (info.colorType()) {
33         case kRGBA_8888_SkColorType:
34         case kBGRA_8888_SkColorType: {
35             uint32_t* dstRow = (uint32_t*) dst;
36             for (int row = 0; row < numRows; row++) {
37                 SkOpts::memset32(dstRow, 0, width);
38                 dstRow = SkTAddOffset<uint32_t>(dstRow, rowBytes);
39             }
40             break;
41         }
42         case kRGB_565_SkColorType: {
43             uint16_t* dstRow = (uint16_t*) dst;
44             for (int row = 0; row < numRows; row++) {
45                 SkOpts::memset16(dstRow, 0, width);
46                 dstRow = SkTAddOffset<uint16_t>(dstRow, rowBytes);
47             }
48             break;
49         }
50         case kGray_8_SkColorType: {
51             uint8_t* dstRow = (uint8_t*) dst;
52             for (int row = 0; row < numRows; row++) {
53                 memset(dstRow, 0, width);
54                 dstRow = SkTAddOffset<uint8_t>(dstRow, rowBytes);
55             }
56             break;
57         }
58         case kRGBA_F16_SkColorType: {
59             uint64_t* dstRow = (uint64_t*) dst;
60             for (int row = 0; row < numRows; row++) {
61                 SkOpts::memset64(dstRow, 0, width);
62                 dstRow = SkTAddOffset<uint64_t>(dstRow, rowBytes);
63             }
64             break;
65         }
66         default:
67             SkCodecPrintf("Error: Unsupported dst color type for fill().  Doing nothing.\n");
68             SkASSERT(false);
69             break;
70     }
71 }
72