• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

saitoha / libsixel / 19918707358

04 Dec 2025 05:12AM UTC coverage: 38.402% (-4.0%) from 42.395%
19918707358

push

github

saitoha
tests: fix meson msys dll lookup

9738 of 38220 branches covered (25.48%)

12841 of 33438 relevant lines covered (38.4%)

782420.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

69.39
/src/output.c
1
/*
2
 * SPDX-License-Identifier: MIT
3
 *
4
 * Copyright (c) 2025 libsixel developers. See `AUTHORS`.
5
 * Copyright (c) 2014-2019 Hayaki Saito
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8
 * this software and associated documentation files (the "Software"), to deal in
9
 * the Software without restriction, including without limitation the rights to
10
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11
 * the Software, and to permit persons to whom the Software is furnished to do so,
12
 * subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in all
15
 * copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
 */
24

25
#include "config.h"
26

27
/* STDC_HEADERS */
28
# include <stdio.h>
29
# include <stdlib.h>
30

31
#if 0
32
#if HAVE_ASSERT_H
33
# include <assert.h>
34
#endif  /* HAVE_ASSERT_H */
35
#endif
36

37
#include <sixel.h>
38
#include "output.h"
39

40

41
/* create new output context object */
42
SIXELAPI SIXELSTATUS
43
sixel_output_new(
519✔
44
    sixel_output_t          /* out */ **output,
45
    sixel_write_function    /* in */  fn_write,
46
    void                    /* in */  *priv,
47
    sixel_allocator_t       /* in */  *allocator)
48
{
49
    SIXELSTATUS status = SIXEL_FALSE;
519✔
50
    size_t size;
519✔
51

52
    if (allocator == NULL) {
519!
53
        status = sixel_allocator_new(&allocator, NULL, NULL, NULL, NULL);
×
54
        if (SIXEL_FAILED(status)) {
×
55
            goto end;
×
56
        }
57
    } else {
58
        sixel_allocator_ref(allocator);
519✔
59
    }
60
    size = sizeof(sixel_output_t) + SIXEL_OUTPUT_PACKET_SIZE * 2;
519✔
61

62
    *output = (sixel_output_t *)sixel_allocator_malloc(allocator, size);
519✔
63
    if (*output == NULL) {
519!
64
        sixel_helper_set_additional_message(
×
65
            "sixel_output_new: sixel_allocator_malloc() failed.");
66
        status = SIXEL_BAD_ALLOCATION;
×
67
        goto end;
×
68
    }
69

70
    (*output)->ref = 1;
519✔
71
    (*output)->has_8bit_control = 0;
519✔
72
    (*output)->has_sdm_glitch = 0;
519✔
73
    (*output)->has_gri_arg_limit = 1;
519✔
74
    (*output)->skip_dcs_envelope = 0;
519✔
75
    (*output)->skip_header = 0;
519✔
76
    (*output)->palette_type = SIXEL_PALETTETYPE_AUTO;
519✔
77
    (*output)->colorspace = SIXEL_COLORSPACE_GAMMA;
519✔
78
    (*output)->source_colorspace = SIXEL_COLORSPACE_GAMMA;
519✔
79
    (*output)->pixelformat = SIXEL_PIXELFORMAT_RGB888;
519✔
80
    (*output)->fn_write = fn_write;
519✔
81
    (*output)->save_pixel = 0;
519✔
82
    (*output)->save_count = 0;
519✔
83
    (*output)->active_palette = (-1);
519✔
84
    (*output)->node_top = NULL;
519✔
85
    (*output)->node_free = NULL;
519✔
86
    (*output)->priv = priv;
519✔
87
    (*output)->pos = 0;
519✔
88
    (*output)->penetrate_multiplexer = 0;
519✔
89
    (*output)->encode_policy = SIXEL_ENCODEPOLICY_AUTO;
519✔
90
    (*output)->ormode = 0;
519✔
91
    (*output)->last_clock = 0;
519✔
92
    (*output)->allocator = allocator;
519✔
93

94
    status = SIXEL_OK;
519✔
95

96
end:
519✔
97
    return status;
519✔
98
}
99

100

101
/* deprecated: create an output object */
102
SIXELAPI sixel_output_t *
103
sixel_output_create(sixel_write_function fn_write, void *priv)
×
104
{
105
    SIXELSTATUS status = SIXEL_FALSE;
×
106
    sixel_output_t *output = NULL;
×
107

108
    status = sixel_output_new(&output, fn_write, priv, NULL);
×
109
    if (SIXEL_FAILED(status)) {
×
110
        goto end;
111
    }
112

113
end:
×
114
    return output;
×
115
}
116

117

118
/* destroy output context object */
119
SIXELAPI void
120
sixel_output_destroy(sixel_output_t *output)
519✔
121
{
122
    sixel_allocator_t *allocator;
519✔
123

124
    if (output) {
519!
125
        allocator = output->allocator;
519✔
126
        sixel_allocator_free(allocator, output);
519✔
127
        sixel_allocator_unref(allocator);
519✔
128
    }
129
}
519✔
130

131

132
/* increase reference count of output context object (thread-unsafe) */
133
SIXELAPI void
134
sixel_output_ref(sixel_output_t *output)
489✔
135
{
136
    /* TODO: be thread-safe */
137
    ++output->ref;
489✔
138
}
489✔
139

140

141
/* decrease reference count of output context object (thread-unsafe) */
142
SIXELAPI void
143
sixel_output_unref(sixel_output_t *output)
1,008✔
144
{
145
    /* TODO: be thread-safe */
146
    if (output) {
1,008!
147
#if 0
148
        assert(output->ref > 0);
149
#endif
150
        output->ref--;
1,008✔
151
        if (output->ref == 0) {
1,008✔
152
            sixel_output_destroy(output);
519✔
153
        }
154
    }
155
}
1,008✔
156

157

158
/* get 8bit output mode which indicates whether it uses C1 control characters */
159
SIXELAPI int
160
sixel_output_get_8bit_availability(sixel_output_t *output)
×
161
{
162
    return output->has_8bit_control;
×
163
}
164

165

166
/* set 8bit output mode state */
167
SIXELAPI void
168
sixel_output_set_8bit_availability(sixel_output_t *output, int availability)
519✔
169
{
170
    output->has_8bit_control = availability;
519✔
171
}
519✔
172

173

174
/* set whether limit arguments of DECGRI('!') to 255 */
175
SIXELAPI void
176
sixel_output_set_gri_arg_limit(
519✔
177
    sixel_output_t /* in */ *output, /* output context */
178
    int            /* in */ value)   /* 0: don't limit arguments of DECGRI
179
                                        1: limit arguments of DECGRI to 255 */
180
{
181
    output->has_gri_arg_limit = value;
519✔
182
}
519✔
183

184

185
/* set GNU Screen penetration feature enable or disable */
186
SIXELAPI void
187
sixel_output_set_penetrate_multiplexer(sixel_output_t *output, int penetrate)
519✔
188
{
189
    output->penetrate_multiplexer = penetrate;
519✔
190
}
519✔
191

192

193
/* set whether we skip DCS envelope */
194
SIXELAPI void
195
sixel_output_set_skip_dcs_envelope(sixel_output_t *output, int skip)
×
196
{
197
    output->skip_dcs_envelope = skip;
×
198
}
×
199

200

201
SIXELAPI void
202
sixel_output_set_skip_header(sixel_output_t *output, int skip)
×
203
{
204
    output->skip_header = skip;
×
205
}
×
206

207

208
/* set palette type: RGB or HLS */
209
SIXELAPI void
210
sixel_output_set_palette_type(sixel_output_t *output, int palettetype)
519✔
211
{
212
    output->palette_type = palettetype;
519✔
213
}
519✔
214

215

216
SIXELAPI void
217
sixel_output_set_ormode(sixel_output_t *output, int ormode)
519✔
218
{
219
    output->ormode = ormode;
519✔
220
}
519✔
221

222

223
/* set encodeing policy: auto, fast or size */
224
SIXELAPI void
225
sixel_output_set_encode_policy(sixel_output_t *output, int encode_policy)
519✔
226
{
227
    output->encode_policy = encode_policy;
519✔
228
}
519✔
229

230

231
SIXELAPI SIXELSTATUS
232
sixel_output_convert_colorspace(sixel_output_t *output,
×
233
                                unsigned char *pixels,
234
                                size_t size)
235
{
236
    SIXELSTATUS status = SIXEL_FALSE;
×
237

238
    if (output == NULL || pixels == NULL) {
×
239
        sixel_helper_set_additional_message(
×
240
            "sixel_output_convert_colorspace: invalid argument.");
241
        return SIXEL_BAD_ARGUMENT;
×
242
    }
243

244
    status = sixel_helper_convert_colorspace(pixels,
×
245
                                             size,
246
                                             output->pixelformat,
247
                                             output->source_colorspace,
248
                                             output->colorspace);
249
    if (SIXEL_FAILED(status)) {
×
250
        return status;
251
    }
252

253
    output->source_colorspace = output->colorspace;
×
254

255
    return SIXEL_OK;
×
256
}
257

258
/* emacs Local Variables:      */
259
/* emacs mode: c               */
260
/* emacs tab-width: 4          */
261
/* emacs indent-tabs-mode: nil */
262
/* emacs c-basic-offset: 4     */
263
/* emacs End:                  */
264
/* vim: set expandtab ts=4 sts=4 sw=4 : */
265
/* EOF */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc