summaryrefslogtreecommitdiffstats
path: root/third_party/jpeg-xl/lib/include/jxl/butteraugli.h
blob: 88b97f6d07bcc12aaf2366aa3f509ca5c98513b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* Copyright (c) the JPEG XL Project Authors. All rights reserved.
 *
 * Use of this source code is governed by a BSD-style
 * license that can be found in the LICENSE file.
 */

/** @addtogroup libjxl_butteraugli
 * @{
 * @file butteraugli.h
 * @brief Butteraugli API for JPEG XL.
 */

#ifndef JXL_BUTTERAUGLI_H_
#define JXL_BUTTERAUGLI_H_

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

#include <jxl/jxl_export.h>
#include <jxl/memory_manager.h>
#include <jxl/parallel_runner.h>
#include <jxl/types.h>

/**
 * Opaque structure that holds a butteraugli API.
 *
 * Allocated and initialized with JxlButteraugliApiCreate().
 * Cleaned up and deallocated with JxlButteraugliApiDestroy().
 */
typedef struct JxlButteraugliApiStruct JxlButteraugliApi;

/**
 * Opaque structure that holds intermediary butteraugli results.
 *
 * Allocated and initialized with JxlButteraugliCompute().
 * Cleaned up and deallocated with JxlButteraugliResultDestroy().
 */
typedef struct JxlButteraugliResultStruct JxlButteraugliResult;

/**
 * Deinitializes and frees JxlButteraugliResult instance.
 *
 * @param result instance to be cleaned up and deallocated.
 */
JXL_EXPORT void JxlButteraugliResultDestroy(JxlButteraugliResult* result);

/**
 * Creates an instance of JxlButteraugliApi and initializes it.
 *
 * @p memory_manager will be used for all the library dynamic allocations made
 * from this instance. The parameter may be NULL, in which case the default
 * allocator will be used. See jxl/memory_manager.h for details.
 *
 * @param memory_manager custom allocator function. It may be NULL. The memory
 *        manager will be copied internally.
 * @return @c NULL if the instance can not be allocated or initialized
 * @return pointer to initialized JxlEncoder otherwise
 */
JXL_EXPORT JxlButteraugliApi* JxlButteraugliApiCreate(
    const JxlMemoryManager* memory_manager);

/**
 * Set the parallel runner for multithreading.
 *
 * @param api api instance.
 * @param parallel_runner function pointer to runner for multithreading. A
 * multithreaded runner should be set to reach fast performance.
 * @param parallel_runner_opaque opaque pointer for parallel_runner.
 */
JXL_EXPORT void JxlButteraugliApiSetParallelRunner(
    JxlButteraugliApi* api, JxlParallelRunner parallel_runner,
    void* parallel_runner_opaque);

/**
 * Set the hf_asymmetry option for butteraugli.
 *
 * @param api api instance.
 * @param v new hf_asymmetry value.
 */
JXL_EXPORT void JxlButteraugliApiSetHFAsymmetry(JxlButteraugliApi* api,
                                                float v);

/**
 * Set the intensity_target option for butteraugli.
 *
 * @param api api instance.
 * @param v new intensity_target value.
 */
JXL_EXPORT void JxlButteraugliApiSetIntensityTarget(JxlButteraugliApi* api,
                                                    float v);

/**
 * Deinitializes and frees JxlButteraugliApi instance.
 *
 * @param api instance to be cleaned up and deallocated.
 */
JXL_EXPORT void JxlButteraugliApiDestroy(JxlButteraugliApi* api);

/**
 * Computes intermediary butteraugli result between an original image and a
 * distortion.
 *
 * @param api api instance for this computation.
 * @param xsize width of the compared images.
 * @param ysize height of the compared images.
 * @param pixel_format_orig pixel format for original image.
 * @param buffer_orig pixel data for original image.
 * @param size_orig size of buffer_orig in bytes.
 * @param pixel_format_dist pixel format for distortion.
 * @param buffer_dist pixel data for distortion.
 * @param size_dist size of buffer_dist in bytes.
 * @return @c NULL if the results can not be computed or initialized.
 * @return pointer to initialized and computed intermediary result.
 */
JXL_EXPORT JxlButteraugliResult* JxlButteraugliCompute(
    const JxlButteraugliApi* api, uint32_t xsize, uint32_t ysize,
    const JxlPixelFormat* pixel_format_orig, const void* buffer_orig,
    size_t size_orig, const JxlPixelFormat* pixel_format_dist,
    const void* buffer_dist, size_t size_dist);

/**
 * Computes butteraugli max distance based on an intermediary butteraugli
 * result.
 *
 * @param result intermediary result instance.
 * @return max distance.
 */
JXL_EXPORT float JxlButteraugliResultGetMaxDistance(
    const JxlButteraugliResult* result);

/**
 * Computes a butteraugli distance based on an intermediary butteraugli result.
 *
 * @param result intermediary result instance.
 * @param pnorm pnorm to calculate.
 * @return distance using the given pnorm.
 */
JXL_EXPORT float JxlButteraugliResultGetDistance(
    const JxlButteraugliResult* result, float pnorm);

/**
 * Get a pointer to the distmap in the result.
 *
 * @param result intermediary result instance.
 * @param buffer will be set to the distmap. The distance value for (x,y) will
 * be available at buffer + y * row_stride + x.
 * @param row_stride will be set to the row stride of the distmap.
 */
JXL_EXPORT void JxlButteraugliResultGetDistmap(
    const JxlButteraugliResult* result, const float** buffer,
    uint32_t* row_stride);

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif /* JXL_BUTTERAUGLI_H_ */

/** @}*/