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