File: fill_constants.cpp

package info (click to toggle)
mypaint 2.0.1-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,884 kB
  • sloc: python: 43,893; cpp: 6,931; xml: 2,475; sh: 473; makefile: 25
file content (43 lines) | stat: -rw-r--r-- 1,112 bytes parent folder | download | duplicates (4)
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
/* This file is part of MyPaint.
 * Copyright (C) 2019 by the MyPaint Development Team.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include "fill_constants.hpp"

PyObject* ConstTiles::_ALPHA_TRANSPARENT = nullptr;
PyObject* ConstTiles::_ALPHA_OPAQUE = nullptr;

void
ConstTiles::init()
{
    npy_intp dims[] = {N, N};
    PyObject* empty = PyArray_ZEROS(2, dims, NPY_USHORT, false);
    PyObject* full = PyArray_EMPTY(2, dims, NPY_USHORT, false);
    PixelBuffer<chan_t> buf{full};
    PixelRef<chan_t> ref = buf.get_pixel(0, 0);
    for (int i = 0; i < N * N; ++i, ref.move_x(1)) {
        ref.write(fix15_one);
    }
    _ALPHA_TRANSPARENT = empty;
    _ALPHA_OPAQUE = full;
}

PyObject*
ConstTiles::ALPHA_TRANSPARENT()
{
    if (!_ALPHA_TRANSPARENT) init();
    return _ALPHA_TRANSPARENT;
}

PyObject*
ConstTiles::ALPHA_OPAQUE()
{
    if (!_ALPHA_OPAQUE) init();
    return _ALPHA_OPAQUE;
}