1*09537850SAkhilesh Sanikop /* 2*09537850SAkhilesh Sanikop * Copyright 2019 The libgav1 Authors 3*09537850SAkhilesh Sanikop * 4*09537850SAkhilesh Sanikop * Licensed under the Apache License, Version 2.0 (the "License"); 5*09537850SAkhilesh Sanikop * you may not use this file except in compliance with the License. 6*09537850SAkhilesh Sanikop * You may obtain a copy of the License at 7*09537850SAkhilesh Sanikop * 8*09537850SAkhilesh Sanikop * http://www.apache.org/licenses/LICENSE-2.0 9*09537850SAkhilesh Sanikop * 10*09537850SAkhilesh Sanikop * Unless required by applicable law or agreed to in writing, software 11*09537850SAkhilesh Sanikop * distributed under the License is distributed on an "AS IS" BASIS, 12*09537850SAkhilesh Sanikop * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*09537850SAkhilesh Sanikop * See the License for the specific language governing permissions and 14*09537850SAkhilesh Sanikop * limitations under the License. 15*09537850SAkhilesh Sanikop */ 16*09537850SAkhilesh Sanikop 17*09537850SAkhilesh Sanikop #ifndef LIBGAV1_SRC_UTILS_SEGMENTATION_MAP_H_ 18*09537850SAkhilesh Sanikop #define LIBGAV1_SRC_UTILS_SEGMENTATION_MAP_H_ 19*09537850SAkhilesh Sanikop 20*09537850SAkhilesh Sanikop #include <cstdint> 21*09537850SAkhilesh Sanikop #include <memory> 22*09537850SAkhilesh Sanikop 23*09537850SAkhilesh Sanikop #include "src/utils/array_2d.h" 24*09537850SAkhilesh Sanikop #include "src/utils/compiler_attributes.h" 25*09537850SAkhilesh Sanikop 26*09537850SAkhilesh Sanikop namespace libgav1 { 27*09537850SAkhilesh Sanikop 28*09537850SAkhilesh Sanikop // SegmentationMap stores the segment id associated with each 4x4 block in the 29*09537850SAkhilesh Sanikop // frame. 30*09537850SAkhilesh Sanikop class SegmentationMap { 31*09537850SAkhilesh Sanikop public: 32*09537850SAkhilesh Sanikop SegmentationMap() = default; 33*09537850SAkhilesh Sanikop 34*09537850SAkhilesh Sanikop // Not copyable or movable 35*09537850SAkhilesh Sanikop SegmentationMap(const SegmentationMap&) = delete; 36*09537850SAkhilesh Sanikop SegmentationMap& operator=(const SegmentationMap&) = delete; 37*09537850SAkhilesh Sanikop 38*09537850SAkhilesh Sanikop // Allocates an internal buffer of the given dimensions to hold the 39*09537850SAkhilesh Sanikop // segmentation map. The memory in the buffer is not initialized. Returns 40*09537850SAkhilesh Sanikop // true on success, false on failure (for example, out of memory). 41*09537850SAkhilesh Sanikop LIBGAV1_MUST_USE_RESULT bool Allocate(int32_t rows4x4, int32_t columns4x4); 42*09537850SAkhilesh Sanikop segment_id(int row4x4,int column4x4)43*09537850SAkhilesh Sanikop int8_t segment_id(int row4x4, int column4x4) const { 44*09537850SAkhilesh Sanikop return segment_id_[row4x4][column4x4]; 45*09537850SAkhilesh Sanikop } 46*09537850SAkhilesh Sanikop 47*09537850SAkhilesh Sanikop // Sets every element in the segmentation map to 0. 48*09537850SAkhilesh Sanikop void Clear(); 49*09537850SAkhilesh Sanikop 50*09537850SAkhilesh Sanikop // Copies the entire segmentation map. |from| must be of the same dimensions. 51*09537850SAkhilesh Sanikop void CopyFrom(const SegmentationMap& from); 52*09537850SAkhilesh Sanikop 53*09537850SAkhilesh Sanikop // Sets the region of segmentation map covered by the block to |segment_id|. 54*09537850SAkhilesh Sanikop // The block is located at |row4x4|, |column4x4| and has dimensions 55*09537850SAkhilesh Sanikop // |block_width4x4| and |block_height4x4|. 56*09537850SAkhilesh Sanikop void FillBlock(int row4x4, int column4x4, int block_width4x4, 57*09537850SAkhilesh Sanikop int block_height4x4, int8_t segment_id); 58*09537850SAkhilesh Sanikop 59*09537850SAkhilesh Sanikop private: 60*09537850SAkhilesh Sanikop int32_t rows4x4_ = 0; 61*09537850SAkhilesh Sanikop int32_t columns4x4_ = 0; 62*09537850SAkhilesh Sanikop 63*09537850SAkhilesh Sanikop // segment_id_ is a rows4x4_ by columns4x4_ 2D array. The underlying data 64*09537850SAkhilesh Sanikop // buffer is dynamically allocated and owned by segment_id_buffer_. 65*09537850SAkhilesh Sanikop std::unique_ptr<int8_t[]> segment_id_buffer_; 66*09537850SAkhilesh Sanikop Array2DView<int8_t> segment_id_; 67*09537850SAkhilesh Sanikop }; 68*09537850SAkhilesh Sanikop 69*09537850SAkhilesh Sanikop } // namespace libgav1 70*09537850SAkhilesh Sanikop 71*09537850SAkhilesh Sanikop #endif // LIBGAV1_SRC_UTILS_SEGMENTATION_MAP_H_ 72