• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   if (rows4x4 * columns4x4 > rows4x4_ * columns4x4_) {
25     segment_id_buffer_.reset(new (std::nothrow) int8_t[rows4x4 * columns4x4]);
26   }
27 
28   rows4x4_ = rows4x4;
29   columns4x4_ = columns4x4;
30   if (segment_id_buffer_ == nullptr) return false;
31   segment_id_.Reset(rows4x4_, columns4x4_, segment_id_buffer_.get());
32   return true;
33 }
34 
Clear()35 void SegmentationMap::Clear() {
36   memset(segment_id_buffer_.get(), 0, rows4x4_ * columns4x4_);
37 }
38 
CopyFrom(const SegmentationMap & from)39 void SegmentationMap::CopyFrom(const SegmentationMap& from) {
40   assert(rows4x4_ == from.rows4x4_ && columns4x4_ == from.columns4x4_);
41   memcpy(segment_id_buffer_.get(), from.segment_id_buffer_.get(),
42          rows4x4_ * columns4x4_);
43 }
44 
FillBlock(int row4x4,int column4x4,int block_width4x4,int block_height4x4,int8_t segment_id)45 void SegmentationMap::FillBlock(int row4x4, int column4x4, int block_width4x4,
46                                 int block_height4x4, int8_t segment_id) {
47   for (int y = 0; y < block_height4x4; ++y) {
48     memset(&segment_id_[row4x4 + y][column4x4], segment_id, block_width4x4);
49   }
50 }
51 
52 }  // namespace libgav1
53