1 #pragma once
2 
3 #ifndef _TCM_H_
4 #define _TCM_H_
5 
6 #include "tmacro.h"
7 #include "avl.h"
8 /* TCM = toonz color map/mapping/mapped/manager */
9 
10 typedef struct {
11   /*UCHAR    tone_offs; sempre 0 */
12   UCHAR tone_bits;
13   UCHAR color_offs;
14   UCHAR color_bits;
15   UCHAR pencil_offs;
16   UCHAR pencil_bits;
17   USHORT offset_mask; /* fa allo stesso tempo sia da offset che da maschera */
18   USHORT default_val; /* da utilizzare, p.es., per pixel fuori dall'immagine */
19   short n_tones;
20   short n_colors;
21   short n_pencils;
22 } TCM_INFO;
23 
24 static const TCM_INFO Tcm_old_default_info = {
25     /*0,*/ 4, 4, 5, 9, 2, 0x0800, 0x080f, 16, 32, 4};
26 static const TCM_INFO Tcm_new_default_info = {
27     /*0,*/ 4, 4, 7, 11, 5, 0x0000, 0x000f, 16, 128, 32};
28 static const TCM_INFO Tcm_24_default_info = {
29     /*0,*/ 8, 8, 8, 16, 8, 0x0000, 0x00ff, 256, 256, 256};
30 
31 #define TCM_TONE_MASK(TCM) ((1U << (TCM).tone_bits) - 1U)
32 #define TCM_COLOR_MASK(TCM)                                                    \
33   (((1U << (TCM).color_bits) - 1U) << (TCM).color_offs)
34 #define TCM_PENCIL_MASK(TCM)                                                   \
35   (((1U << (TCM).pencil_bits) - 1U) << (TCM).pencil_offs)
36 
37 #define TCM_COLOR_INDEX(TCM, ID)                                               \
38   ((ID) << (TCM).color_offs | ((TCM).n_tones - 1) | (TCM).offset_mask)
39 #define TCM_PENCIL_INDEX(TCM, ID)                                              \
40   ((ID) << (TCM).pencil_offs | (TCM).offset_mask)
41 
42 #define TCM_INDEX_IS_COLOR_ONLY(TCM, INDEX)                                    \
43   (((INDEX)&TCM_TONE_MASK(TCM)) == TCM_TONE_MASK(TCM))
44 #define TCM_INDEX_IS_PENCIL_ONLY(TCM, INDEX) (((INDEX)&TCM_TONE_MASK(TCM)) == 0)
45 
46 #define TCM_COLOR_ID(TCM, INDEX)                                               \
47   ((int)(((INDEX) >> (TCM).color_offs) & ((1U << (TCM).color_bits) - 1U)))
48 #define TCM_PENCIL_ID(TCM, INDEX)                                              \
49   ((int)(((INDEX) >> (TCM).pencil_offs) & ((1U << (TCM).pencil_bits) - 1U)))
50 
51 #define TCM_MIN_CMAP_BUFFER_SIZE(TCM)                                          \
52   ((((TCM).n_pencils - 1) << (TCM).pencil_offs |                               \
53     ((TCM).n_colors - 1) << (TCM).color_offs | (TCM).n_tones - 1) +            \
54    1)
55 
56 #define TCM_MIN_CMAP_COLBUFFER_SIZE(TCM) ((TCM).n_colors * (TCM).n_tones)
57 
58 #define TCM_MIN_CMAP_PENBUFFER_SIZE(TCM) ((TCM).n_pencils * (TCM).n_tones)
59 
60 #define TCM_CMAP_BUFFER_SIZE(TCM)                                              \
61   (1 << ((TCM).pencil_bits + (TCM).color_bits + (TCM).tone_bits))
62 
63 #define TCM_CMAP_COLBUFFER_SIZE(TCM) (1 << ((TCM).color_bits + (TCM).tone_bits))
64 
65 #define TCM_CMAP_PENBUFFER_SIZE(TCM)                                           \
66   (1 << ((TCM).pencil_bits + (TCM).tone_bits))
67 
68 TREE *cdb_decode_all(char *names_in_plt_file, TCM_INFO tcm);
69 
70 typedef struct {
71   int index;
72   char *group;
73   char *name;
74   char *accelerator;
75   int num_effects;
76   TREE *effects;
77 } CDB_TREE_ITEM;
78 
79 #endif
80