2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 3 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, see <https://www.gnu.org/licenses/>.
15 * Copyright (C) 2018 Ell
18 #include "test-common.h"
19 #include "buffer/gegl-compression.h"
25 load_png (const gchar
*path
,
30 GeglNode
*node_source
;
32 GeglBuffer
*buffer
= NULL
;
35 node
= gegl_node_new ();
37 node_source
= gegl_node_new_child (node
,
38 "operation", "gegl:load",
41 node_sink
= gegl_node_new_child (node
,
42 "operation", "gegl:buffer-sink",
46 gegl_node_link (node_source
, node_sink
);
48 gegl_node_process (node_sink
);
50 g_object_unref (node
);
52 *n
= gegl_buffer_get_width (buffer
) * gegl_buffer_get_height (buffer
);
53 data
= g_malloc (*n
* babl_format_get_bytes_per_pixel (format
));
55 gegl_buffer_get (buffer
, NULL
, 1.0, format
, data
,
56 GEGL_AUTO_ROWSTRIDE
, GEGL_ABYSS_NONE
);
58 g_object_unref (buffer
);
74 gint max_compressed_size
;
76 const gchar
**algorithms
;
78 gint result
= FAILURE
;
80 gegl_init (&argc
, &argv
);
82 format
= babl_format ("R'G'B'A u8");
83 bpp
= babl_format_get_bytes_per_pixel (format
);
85 path
= g_build_filename (g_getenv ("ABS_TOP_SRCDIR"),
86 "tests", "compositions", "data", "car-stack.png",
89 data
= load_png (path
, format
, &n
);
94 max_compressed_size
= 2 * n
* bpp
;
95 compressed
= g_malloc (max_compressed_size
);
96 decompressed
= g_malloc (size
);
98 algorithms
= gegl_compression_list ();
100 for (i
= 0; algorithms
[i
]; i
++)
102 const GeglCompression
*compression
= gegl_compression (algorithms
[i
]);
104 gint compressed_size
;
107 id
= g_strdup_printf ("%s compress", algorithms
[i
]);
110 for (j
= 0; j
< ITERATIONS
&& converged
< BAIL_COUNT
; j
++)
114 if (! gegl_compression_compress (compression
, format
,
116 compressed
, &compressed_size
,
117 max_compressed_size
))
125 test_end (id
, (gdouble
) size
* ITERATIONS
);
128 id
= g_strdup_printf ("%s decompress", algorithms
[i
]);
131 for (j
= 0; j
< ITERATIONS
&& converged
< BAIL_COUNT
; j
++)
135 if (! gegl_compression_decompress (compression
, format
,
137 compressed
, compressed_size
))
145 test_end (id
, (gdouble
) size
* ITERATIONS
);
155 g_free (decompressed
);