summaryrefslogtreecommitdiff
blob: 85b88a23257536f65e93e3a09f95cf737e91d378 (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
/* Copyright (C) 2015-2021 Artifex Software, Inc.
   All Rights Reserved.

   This software is provided AS-IS with no warranty, either express or
   implied.

   This software is distributed under license and may not be copied,
   modified or distributed except as expressly authorized under the terms
   of the license contained in the file LICENSE in this distribution.

   Refer to licensing information at http://www.artifex.com or contact
   Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
   CA 94945, U.S.A., +1(415)492-9861, for further information.
*/

#include "claptrap.h"
#include "claptrap-impl.h"

ClapTrap *ClapTrap_Init(gs_memory_t     *mem,
                        int              width,
                        int              height,
                        int              num_comps,
                        const int       *comp_order,
                        int              max_x_offset,
                        int              max_y_offset,
                        ClapTrap_LineFn *get_line,
                        void            *get_line_arg)
{
    ClapTrap *ct;

    ct = (ClapTrap *)gs_alloc_bytes(mem, sizeof(*ct), "ClapTrap");
    if (ct == NULL)
        return NULL;

    ct->width        = width;
    ct->height       = height;
    ct->num_comps    = num_comps;
    ct->comp_order   = comp_order;
    ct->max_x_offset = max_x_offset;
    ct->max_y_offset = max_y_offset;
    ct->get_line     = get_line;
    ct->get_line_arg = get_line_arg;
    ct->lines_in_buf = max_y_offset * 2 + 1;
    ct->lines_read   = 0;
    ct->y            = 0;
    ct->span         = width * num_comps;

    ct->linebuf      = gs_alloc_bytes(mem, (size_t)ct->span * ct->lines_in_buf, "ClapTrap linebuf");
    ct->process      = gs_alloc_bytes(mem, (size_t)ct->width * ct->lines_in_buf, "ClapTrap process");
    if (ct->linebuf == NULL || ct->process == NULL)
    {
        gs_free_object(mem, ct->linebuf, "ClapTrap linebuf");
        gs_free_object(mem, ct->process, "ClapTrap process");
        gs_free_object(mem, ct, "ClapTrap");
        return NULL;
    }

    return ct;
}

void ClapTrap_Fin(gs_memory_t *mem, ClapTrap *ct)
{
    if (ct)
    {
        gs_free_object(mem, ct->linebuf, "ClapTrap linebuf");
        gs_free_object(mem, ct->process, "ClapTrap process");
    }
    gs_free_object(mem, ct, "ClapTrap");
}