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

saitoha / libsixel / 19765269522

28 Nov 2025 01:30PM UTC coverage: 39.983% (-1.6%) from 41.616%
19765269522

push

github

web-flow
Merge pull request #214 from saitoha/codex/add-logging-to-resize-processing

Limit scale logging and add timeline window controls

9788 of 35562 branches covered (27.52%)

9 of 63 new or added lines in 1 file covered. (14.29%)

281 existing lines in 19 files now uncovered.

12991 of 32491 relevant lines covered (39.98%)

619662.16 hits per line

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

67.35
/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(
346✔
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;
346✔
50
    size_t size;
51

52
    if (allocator == NULL) {
346!
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);
346✔
59
    }
60
    size = sizeof(sixel_output_t) + SIXEL_OUTPUT_PACKET_SIZE * 2;
346✔
61

62
    *output = (sixel_output_t *)sixel_allocator_malloc(allocator, size);
346✔
63
    if (*output == NULL) {
346!
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;
346✔
71
    (*output)->has_8bit_control = 0;
346✔
72
    (*output)->has_sdm_glitch = 0;
346✔
73
    (*output)->has_gri_arg_limit = 1;
346✔
74
    (*output)->skip_dcs_envelope = 0;
346✔
75
    (*output)->skip_header = 0;
346✔
76
    (*output)->palette_type = SIXEL_PALETTETYPE_AUTO;
346✔
77
    (*output)->colorspace = SIXEL_COLORSPACE_GAMMA;
346✔
78
    (*output)->source_colorspace = SIXEL_COLORSPACE_GAMMA;
346✔
79
    (*output)->pixelformat = SIXEL_PIXELFORMAT_RGB888;
346✔
80
    (*output)->fn_write = fn_write;
346✔
81
    (*output)->save_pixel = 0;
346✔
82
    (*output)->save_count = 0;
346✔
83
    (*output)->active_palette = (-1);
346✔
84
    (*output)->node_top = NULL;
346✔
85
    (*output)->node_free = NULL;
346✔
86
    (*output)->priv = priv;
346✔
87
    (*output)->pos = 0;
346✔
88
    (*output)->penetrate_multiplexer = 0;
346✔
89
    (*output)->encode_policy = SIXEL_ENCODEPOLICY_AUTO;
346✔
90
    (*output)->ormode = 0;
346✔
91
    (*output)->last_clock = 0;
346✔
92
    (*output)->allocator = allocator;
346✔
93

94
    status = SIXEL_OK;
346✔
95

96
end:
346✔
97
    return status;
346✔
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

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

117

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

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

131

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

140

141
/* decrease reference count of output context object (thread-unsafe) */
142
SIXELAPI void
143
sixel_output_unref(sixel_output_t *output)
672✔
144
{
145
    /* TODO: be thread-safe */
146
    if (output) {
672!
147
#if 0
148
        assert(output->ref > 0);
149
#endif
150
        output->ref--;
672✔
151
        if (output->ref == 0) {
672✔
152
            sixel_output_destroy(output);
346✔
153
        }
154
    }
155
}
672✔
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)
346✔
169
{
170
    output->has_8bit_control = availability;
346✔
171
}
346✔
172

173

174
/* set whether limit arguments of DECGRI('!') to 255 */
175
SIXELAPI void
176
sixel_output_set_gri_arg_limit(
346✔
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;
346✔
182
}
346✔
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)
346✔
188
{
189
    output->penetrate_multiplexer = penetrate;
346✔
190
}
346✔
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)
346✔
211
{
212
    output->palette_type = palettetype;
346✔
213
}
346✔
214

215

216
SIXELAPI void
217
sixel_output_set_ormode(sixel_output_t *output, int ormode)
346✔
218
{
219
    output->ormode = ormode;
346✔
220
}
346✔
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)
346✔
226
{
227
    output->encode_policy = encode_policy;
346✔
228
}
346✔
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