Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef _TCM_H_
Toshihiro Shimizu 890ddd
#define _TCM_H_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tmacro.h"
Toshihiro Shimizu 890ddd
#include "avl.h"
Toshihiro Shimizu 890ddd
/* TCM = toonz color map/mapping/mapped/manager */
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
typedef struct {
Shinya Kitaoka 120a6e
  /*UCHAR    tone_offs; sempre 0 */
Shinya Kitaoka 120a6e
  UCHAR tone_bits;
Shinya Kitaoka 120a6e
  UCHAR color_offs;
Shinya Kitaoka 120a6e
  UCHAR color_bits;
Shinya Kitaoka 120a6e
  UCHAR pencil_offs;
Shinya Kitaoka 120a6e
  UCHAR pencil_bits;
Shinya Kitaoka 120a6e
  USHORT offset_mask; /* fa allo stesso tempo sia da offset che da maschera */
Shinya Kitaoka 120a6e
  USHORT default_val; /* da utilizzare, p.es., per pixel fuori dall'immagine */
Shinya Kitaoka 120a6e
  short n_tones;
Shinya Kitaoka 120a6e
  short n_colors;
Shinya Kitaoka 120a6e
  short n_pencils;
Toshihiro Shimizu 890ddd
} TCM_INFO;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static const TCM_INFO Tcm_old_default_info = {
Shinya Kitaoka 120a6e
    /*0,*/ 4, 4, 5, 9, 2, 0x0800, 0x080f, 16, 32, 4};
Shinya Kitaoka 120a6e
static const TCM_INFO Tcm_new_default_info = {
Shinya Kitaoka 120a6e
    /*0,*/ 4, 4, 7, 11, 5, 0x0000, 0x000f, 16, 128, 32};
Shinya Kitaoka 120a6e
static const TCM_INFO Tcm_24_default_info = {
Shinya Kitaoka 120a6e
    /*0,*/ 8, 8, 8, 16, 8, 0x0000, 0x00ff, 256, 256, 256};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_TONE_MASK(TCM) ((1U << (TCM).tone_bits) - 1U)
Shinya Kitaoka 120a6e
#define TCM_COLOR_MASK(TCM)                                                    \
Shinya Kitaoka 120a6e
  (((1U << (TCM).color_bits) - 1U) << (TCM).color_offs)
Shinya Kitaoka 120a6e
#define TCM_PENCIL_MASK(TCM)                                                   \
Shinya Kitaoka 120a6e
  (((1U << (TCM).pencil_bits) - 1U) << (TCM).pencil_offs)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_COLOR_INDEX(TCM, ID)                                               \
Shinya Kitaoka 120a6e
  ((ID) << (TCM).color_offs | ((TCM).n_tones - 1) | (TCM).offset_mask)
Shinya Kitaoka 120a6e
#define TCM_PENCIL_INDEX(TCM, ID)                                              \
Shinya Kitaoka 120a6e
  ((ID) << (TCM).pencil_offs | (TCM).offset_mask)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_INDEX_IS_COLOR_ONLY(TCM, INDEX)                                    \
Shinya Kitaoka 120a6e
  (((INDEX)&TCM_TONE_MASK(TCM)) == TCM_TONE_MASK(TCM))
Shinya Kitaoka 120a6e
#define TCM_INDEX_IS_PENCIL_ONLY(TCM, INDEX) (((INDEX)&TCM_TONE_MASK(TCM)) == 0)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_COLOR_ID(TCM, INDEX)                                               \
Shinya Kitaoka 120a6e
  ((int)(((INDEX) >> (TCM).color_offs) & ((1U << (TCM).color_bits) - 1U)))
Shinya Kitaoka 120a6e
#define TCM_PENCIL_ID(TCM, INDEX)                                              \
Shinya Kitaoka 120a6e
  ((int)(((INDEX) >> (TCM).pencil_offs) & ((1U << (TCM).pencil_bits) - 1U)))
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_MIN_CMAP_BUFFER_SIZE(TCM)                                          \
Shinya Kitaoka 120a6e
  ((((TCM).n_pencils - 1) << (TCM).pencil_offs |                               \
Shinya Kitaoka 120a6e
    ((TCM).n_colors - 1) << (TCM).color_offs | (TCM).n_tones - 1) +            \
Shinya Kitaoka 120a6e
   1)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_MIN_CMAP_COLBUFFER_SIZE(TCM) ((TCM).n_colors * (TCM).n_tones)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_MIN_CMAP_PENBUFFER_SIZE(TCM) ((TCM).n_pencils * (TCM).n_tones)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_CMAP_BUFFER_SIZE(TCM)                                              \
Shinya Kitaoka 120a6e
  (1 << ((TCM).pencil_bits + (TCM).color_bits + (TCM).tone_bits))
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_CMAP_COLBUFFER_SIZE(TCM) (1 << ((TCM).color_bits + (TCM).tone_bits))
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
#define TCM_CMAP_PENBUFFER_SIZE(TCM)                                           \
Shinya Kitaoka 120a6e
  (1 << ((TCM).pencil_bits + (TCM).tone_bits))
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TREE *cdb_decode_all(char *names_in_plt_file, TCM_INFO tcm);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
typedef struct {
Shinya Kitaoka 120a6e
  int index;
Shinya Kitaoka 120a6e
  char *group;
Shinya Kitaoka 120a6e
  char *name;
Shinya Kitaoka 120a6e
  char *accelerator;
Shinya Kitaoka 120a6e
  int num_effects;
Shinya Kitaoka 120a6e
  TREE *effects;
Toshihiro Shimizu 890ddd
} CDB_TREE_ITEM;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif