1 // Copyright 2019 The libgav1 Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "src/utils/segmentation_map.h"
16
17 #include <cassert>
18 #include <cstring>
19 #include <new>
20
21 namespace libgav1 {
22
Allocate(int32_t rows4x4,int32_t columns4x4)23 bool SegmentationMap::Allocate(int32_t rows4x4, int32_t columns4x4) {
24 rows4x4_ = rows4x4;
25 columns4x4_ = columns4x4;
26 segment_id_buffer_.reset(new (std::nothrow) int8_t[rows4x4_ * columns4x4_]);
27 if (segment_id_buffer_ == nullptr) return false;
28 segment_id_.Reset(rows4x4_, columns4x4_, segment_id_buffer_.get());
29 return true;
30 }
31
Clear()32 void SegmentationMap::Clear() {
33 memset(segment_id_buffer_.get(), 0, rows4x4_ * columns4x4_);
34 }
35
CopyFrom(const SegmentationMap & from)36 void SegmentationMap::CopyFrom(const SegmentationMap& from) {
37 assert(rows4x4_ == from.rows4x4_ && columns4x4_ == from.columns4x4_);
38 memcpy(segment_id_buffer_.get(), from.segment_id_buffer_.get(),
39 rows4x4_ * columns4x4_);
40 }
41
FillBlock(int row4x4,int column4x4,int block_width4x4,int block_height4x4,int8_t segment_id)42 void SegmentationMap::FillBlock(int row4x4, int column4x4, int block_width4x4,
43 int block_height4x4, int8_t segment_id) {
44 for (int y = 0; y < block_height4x4; ++y) {
45 memset(&segment_id_[row4x4 + y][column4x4], segment_id, block_width4x4);
46 }
47 }
48
49 } // namespace libgav1
50