xref: /aosp_15_r20/external/libdav1d/include/common/dump.h (revision c09093415860a1c2373dacd84c4fde00c507cdfd)
1*c0909341SAndroid Build Coastguard Worker /*
2*c0909341SAndroid Build Coastguard Worker  * Copyright © 2018, VideoLAN and dav1d authors
3*c0909341SAndroid Build Coastguard Worker  * Copyright © 2018, Two Orioles, LLC
4*c0909341SAndroid Build Coastguard Worker  * All rights reserved.
5*c0909341SAndroid Build Coastguard Worker  *
6*c0909341SAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
7*c0909341SAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions are met:
8*c0909341SAndroid Build Coastguard Worker  *
9*c0909341SAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright notice, this
10*c0909341SAndroid Build Coastguard Worker  *    list of conditions and the following disclaimer.
11*c0909341SAndroid Build Coastguard Worker  *
12*c0909341SAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright notice,
13*c0909341SAndroid Build Coastguard Worker  *    this list of conditions and the following disclaimer in the documentation
14*c0909341SAndroid Build Coastguard Worker  *    and/or other materials provided with the distribution.
15*c0909341SAndroid Build Coastguard Worker  *
16*c0909341SAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17*c0909341SAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18*c0909341SAndroid Build Coastguard Worker  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19*c0909341SAndroid Build Coastguard Worker  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20*c0909341SAndroid Build Coastguard Worker  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21*c0909341SAndroid Build Coastguard Worker  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22*c0909341SAndroid Build Coastguard Worker  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23*c0909341SAndroid Build Coastguard Worker  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24*c0909341SAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25*c0909341SAndroid Build Coastguard Worker  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*c0909341SAndroid Build Coastguard Worker  */
27*c0909341SAndroid Build Coastguard Worker 
28*c0909341SAndroid Build Coastguard Worker #ifndef DAV1D_COMMON_DUMP_H
29*c0909341SAndroid Build Coastguard Worker #define DAV1D_COMMON_DUMP_H
30*c0909341SAndroid Build Coastguard Worker 
31*c0909341SAndroid Build Coastguard Worker #include <stddef.h>
32*c0909341SAndroid Build Coastguard Worker #include <stdint.h>
33*c0909341SAndroid Build Coastguard Worker #include <stdio.h>
34*c0909341SAndroid Build Coastguard Worker 
35*c0909341SAndroid Build Coastguard Worker #include "common/bitdepth.h"
36*c0909341SAndroid Build Coastguard Worker 
append_plane_to_file(const pixel * buf,ptrdiff_t stride,int w,int h,const char * const file)37*c0909341SAndroid Build Coastguard Worker static inline void append_plane_to_file(const pixel *buf, ptrdiff_t stride,
38*c0909341SAndroid Build Coastguard Worker                                         int w, int h, const char *const file)
39*c0909341SAndroid Build Coastguard Worker {
40*c0909341SAndroid Build Coastguard Worker     FILE *const f = fopen(file, "ab");
41*c0909341SAndroid Build Coastguard Worker     while (h--) {
42*c0909341SAndroid Build Coastguard Worker         fwrite(buf, w * sizeof(pixel), 1, f);
43*c0909341SAndroid Build Coastguard Worker         buf += PXSTRIDE(stride);
44*c0909341SAndroid Build Coastguard Worker     }
45*c0909341SAndroid Build Coastguard Worker     fclose(f);
46*c0909341SAndroid Build Coastguard Worker }
47*c0909341SAndroid Build Coastguard Worker 
hex_fdump(FILE * out,const pixel * buf,ptrdiff_t stride,int w,int h,const char * what)48*c0909341SAndroid Build Coastguard Worker static inline void hex_fdump(FILE *out, const pixel *buf, ptrdiff_t stride,
49*c0909341SAndroid Build Coastguard Worker                              int w, int h, const char *what)
50*c0909341SAndroid Build Coastguard Worker {
51*c0909341SAndroid Build Coastguard Worker     fprintf(out, "%s\n", what);
52*c0909341SAndroid Build Coastguard Worker     while (h--) {
53*c0909341SAndroid Build Coastguard Worker         int x;
54*c0909341SAndroid Build Coastguard Worker         for (x = 0; x < w; x++)
55*c0909341SAndroid Build Coastguard Worker             fprintf(out, " " PIX_HEX_FMT, buf[x]);
56*c0909341SAndroid Build Coastguard Worker         buf += PXSTRIDE(stride);
57*c0909341SAndroid Build Coastguard Worker         fprintf(out, "\n");
58*c0909341SAndroid Build Coastguard Worker     }
59*c0909341SAndroid Build Coastguard Worker }
60*c0909341SAndroid Build Coastguard Worker 
hex_dump(const pixel * buf,ptrdiff_t stride,int w,int h,const char * what)61*c0909341SAndroid Build Coastguard Worker static inline void hex_dump(const pixel *buf, ptrdiff_t stride,
62*c0909341SAndroid Build Coastguard Worker                             int w, int h, const char *what)
63*c0909341SAndroid Build Coastguard Worker {
64*c0909341SAndroid Build Coastguard Worker     hex_fdump(stdout, buf, stride, w, h, what);
65*c0909341SAndroid Build Coastguard Worker }
66*c0909341SAndroid Build Coastguard Worker 
coef_dump(const coef * buf,const int w,const int h,const int len,const char * what)67*c0909341SAndroid Build Coastguard Worker static inline void coef_dump(const coef *buf, const int w, const int h,
68*c0909341SAndroid Build Coastguard Worker                              const int len, const char *what)
69*c0909341SAndroid Build Coastguard Worker {
70*c0909341SAndroid Build Coastguard Worker     int y;
71*c0909341SAndroid Build Coastguard Worker     printf("%s\n", what);
72*c0909341SAndroid Build Coastguard Worker     for (y = 0; y < h; y++) {
73*c0909341SAndroid Build Coastguard Worker         int x;
74*c0909341SAndroid Build Coastguard Worker         for (x = 0; x < w; x++)
75*c0909341SAndroid Build Coastguard Worker             printf(" %*d", len, buf[x]);
76*c0909341SAndroid Build Coastguard Worker         buf += w;
77*c0909341SAndroid Build Coastguard Worker         printf("\n");
78*c0909341SAndroid Build Coastguard Worker     }
79*c0909341SAndroid Build Coastguard Worker }
80*c0909341SAndroid Build Coastguard Worker 
ac_dump(const int16_t * buf,int w,int h,const char * what)81*c0909341SAndroid Build Coastguard Worker static inline void ac_dump(const int16_t *buf, int w, int h, const char *what)
82*c0909341SAndroid Build Coastguard Worker {
83*c0909341SAndroid Build Coastguard Worker     printf("%s\n", what);
84*c0909341SAndroid Build Coastguard Worker     while (h--) {
85*c0909341SAndroid Build Coastguard Worker         for (int x = 0; x < w; x++)
86*c0909341SAndroid Build Coastguard Worker             printf(" %03d", buf[x]);
87*c0909341SAndroid Build Coastguard Worker         buf += w;
88*c0909341SAndroid Build Coastguard Worker         printf("\n");
89*c0909341SAndroid Build Coastguard Worker     }
90*c0909341SAndroid Build Coastguard Worker }
91*c0909341SAndroid Build Coastguard Worker 
92*c0909341SAndroid Build Coastguard Worker #endif /* DAV1D_COMMON_DUMP_H */
93