1 #ifndef IMAGE_H_
2 #define IMAGE_H_
3 /*****************************************************************************
4  * This file is part of Kvazaar HEVC encoder.
5  *
6  * Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modification,
10  * are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright notice, this
13  *   list of conditions and the following disclaimer.
14  *
15  * * Redistributions in binary form must reproduce the above copyright notice, this
16  *   list of conditions and the following disclaimer in the documentation and/or
17  *   other materials provided with the distribution.
18  *
19  * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
20  *   contributors may be used to endorse or promote products derived from
21  *   this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
33  ****************************************************************************/
34 
35 /**
36  * \ingroup DataStructures
37  * \file
38  * A reference counted YUV pixel buffer.
39  */
40 
41 #include "global.h" // IWYU pragma: keep
42 
43 #include "kvazaar.h"
44 #include "strategies/optimized_sad_func_ptr_t.h"
45 
46 
47 typedef struct {
48   kvz_pixel y[LCU_LUMA_SIZE];
49   kvz_pixel u[LCU_CHROMA_SIZE];
50   kvz_pixel v[LCU_CHROMA_SIZE];
51   enum kvz_chroma_format chroma_format;
52 } lcu_yuv_t;
53 
54 typedef struct {
55   int size;
56   int16_t *y;
57   int16_t *u;
58   int16_t *v;
59 } hi_prec_buf_t;
60 
61 typedef struct {
62   int size;
63   kvz_pixel *y;
64   kvz_pixel *u;
65   kvz_pixel *v;
66 } yuv_t;
67 
68 
69 kvz_picture *kvz_image_alloc_420(const int32_t width, const int32_t height);
70 kvz_picture *kvz_image_alloc(enum kvz_chroma_format chroma_format, const int32_t width, const int32_t height);
71 
72 void kvz_image_free(kvz_picture *im);
73 
74 kvz_picture *kvz_image_copy_ref(kvz_picture *im);
75 
76 kvz_picture *kvz_image_make_subimage(kvz_picture *const orig_image,
77                              const unsigned x_offset,
78                              const unsigned y_offset,
79                              const unsigned width,
80                              const unsigned height);
81 
82 yuv_t * kvz_yuv_t_alloc(int luma_size, int chroma_size);
83 void kvz_yuv_t_free(yuv_t * yuv);
84 
85 hi_prec_buf_t * kvz_hi_prec_buf_t_alloc(int luma_size);
86 void kvz_hi_prec_buf_t_free(hi_prec_buf_t * yuv);
87 
88 
89 //Algorithms
90 unsigned kvz_image_calc_sad(const kvz_picture *pic,
91                             const kvz_picture *ref,
92                             int pic_x,
93                             int pic_y,
94                             int ref_x,
95                             int ref_y,
96                             int block_width,
97                             int block_height,
98                             optimized_sad_func_ptr_t optimized_sad);
99 
100 
101 unsigned kvz_image_calc_satd(const kvz_picture *pic,
102                              const kvz_picture *ref,
103                              int pic_x,
104                              int pic_y,
105                              int ref_x,
106                              int ref_y,
107                              int block_width,
108                              int block_height);
109 
110 
111 void kvz_pixels_blit(const kvz_pixel* orig, kvz_pixel *dst,
112                          unsigned width, unsigned height,
113                          unsigned orig_stride, unsigned dst_stride);
114 
115 
116 #endif
117