blob: d580786f9a89b397470e543022c602b0a0f45da3 [file] [log] [blame]
msarette6dd0042015-10-09 11:07:34 -07001/*
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
13void SkSampler::Fill(const SkImageInfo& info, void* dst, size_t rowBytes,
Leon Scroggins IIIe643a9e2018-08-03 16:15:04 -040014 SkCodec::ZeroInitialized zeroInit) {
msarette6dd0042015-10-09 11:07:34 -070015 SkASSERT(dst != nullptr);
16
Leon Scroggins IIIe643a9e2018-08-03 16:15:04 -040017 if (SkCodec::kYes_ZeroInitialized == zeroInit) {
18 return;
19 }
20
msarette6dd0042015-10-09 11:07:34 -070021 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()) {
msarett34e0ec42016-04-22 16:27:24 -070026 case kRGBA_8888_SkColorType:
27 case kBGRA_8888_SkColorType: {
msarettf7eb6fc2016-09-13 09:04:11 -070028 uint32_t* dstRow = (uint32_t*) dst;
29 for (int row = 0; row < numRows; row++) {
Nigel Taofddc6fa2018-08-31 09:37:34 +100030 sk_memset32(dstRow, 0, width);
msarettf7eb6fc2016-09-13 09:04:11 -070031 dstRow = SkTAddOffset<uint32_t>(dstRow, rowBytes);
msarette6dd0042015-10-09 11:07:34 -070032 }
33 break;
34 }
35 case kRGB_565_SkColorType: {
msarettf7eb6fc2016-09-13 09:04:11 -070036 uint16_t* dstRow = (uint16_t*) dst;
37 for (int row = 0; row < numRows; row++) {
Nigel Taofddc6fa2018-08-31 09:37:34 +100038 sk_memset16(dstRow, 0, width);
msarettf7eb6fc2016-09-13 09:04:11 -070039 dstRow = SkTAddOffset<uint16_t>(dstRow, rowBytes);
msarette6dd0042015-10-09 11:07:34 -070040 }
41 break;
42 }
Nigel Taofddc6fa2018-08-31 09:37:34 +100043 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 }
msarette6dd0042015-10-09 11:07:34 -070049 break;
Nigel Taofddc6fa2018-08-31 09:37:34 +100050 }
msarettf7eb6fc2016-09-13 09:04:11 -070051 case kRGBA_F16_SkColorType: {
msarettf7eb6fc2016-09-13 09:04:11 -070052 uint64_t* dstRow = (uint64_t*) dst;
53 for (int row = 0; row < numRows; row++) {
Nigel Taofddc6fa2018-08-31 09:37:34 +100054 sk_memset64(dstRow, 0, width);
msarettf7eb6fc2016-09-13 09:04:11 -070055 dstRow = SkTAddOffset<uint64_t>(dstRow, rowBytes);
56 }
57 break;
58 }
msarette6dd0042015-10-09 11:07:34 -070059 default:
60 SkCodecPrintf("Error: Unsupported dst color type for fill(). Doing nothing.\n");
61 SkASSERT(false);
62 break;
63 }
64}