Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <stdio.h></stdio.h>
Toshihiro Shimizu 890ddd
#include <stdlib.h></stdlib.h>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
#include <assert.h></assert.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz.h"
Toshihiro Shimizu 890ddd
#include "tmsg.h"
Toshihiro Shimizu 890ddd
#include "file.h"
Toshihiro Shimizu 890ddd
#include "tiff.h"
Toshihiro Shimizu 890ddd
#include "tiffio.h"
Toshihiro Shimizu 890ddd
#include "version.h"
Toshihiro Shimizu 890ddd
#include "history.h"
Toshihiro Shimizu 890ddd
#include "colorsdb.h"
Toshihiro Shimizu 890ddd
#include "ImageP/img_security.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define LATEST_PLT_TYPE 4
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
static int Next_img_read_plt_without_buffer = FALSE;
Shinya Kitaoka 120a6e
static int Read_without_buffer              = FALSE;
Shinya Kitaoka 120a6e
#define SET_READ_WITHOUT_BUFFER                                                \
Shinya Kitaoka 120a6e
  {                                                                            \
Shinya Kitaoka 120a6e
    Read_without_buffer              = Next_img_read_plt_without_buffer;       \
Shinya Kitaoka 120a6e
    Next_img_read_plt_without_buffer = FALSE;                                  \
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
static char *build_string_names(IMAGE *image);
Toshihiro Shimizu 890ddd
static void set_color_names(IMAGE *image, char *names);
Toshihiro Shimizu 890ddd
static char *plt_find_color_name(IMAGE *img, int color);
Toshihiro Shimizu 890ddd
static char *plt_find_pencil_name(IMAGE *img, int color);
Toshihiro Shimizu 890ddd
static void plt_set_color_name(IMAGE *img, int color, char *name);
Toshihiro Shimizu 890ddd
static void plt_set_pencil_name(IMAGE *img, int pencil, char *name);
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int img_write_plt(char *filename, IMAGE *image) {
Shinya Kitaoka 120a6e
  TIFF *tfp;
Shinya Kitaoka 120a6e
  UCHAR *buffer;
Shinya Kitaoka 120a6e
  int i, j, scanline, width, rows_per_strip;
Shinya Kitaoka 120a6e
  LPIXEL *cmap, *color, *pencil;
Shinya Kitaoka 120a6e
  USHORT palette[TOONZPALETTE_COUNT];
Shinya Kitaoka 120a6e
  char *names, *history;
Shinya Kitaoka 120a6e
  int plt_type, cmap_size;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CHECK_IMAGEDLL_LICENSE_AND_GET_IMG_LICENSE_ATTR
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  names = NIL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (image->type != CMAP) return FALSE;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tfp = TIFFOpen(filename, "w");
Shinya Kitaoka 120a6e
  if (!tfp) return FALSE;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  plt_type = (image->cmap.offset > 0) ? 4 : 3;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!image->cmap.info.n_colors) {
Shinya Kitaoka 120a6e
    assert(plt_type == 4);
Shinya Kitaoka 120a6e
    image->cmap.info           = Tcm_old_default_info;
Shinya Kitaoka 120a6e
    image->cmap.info.n_colors  = image->cmap.color_n;
Shinya Kitaoka 120a6e
    image->cmap.info.n_pencils = image->cmap.pencil_n;
Shinya Kitaoka 120a6e
    cmap_size                  = TCM_MIN_CMAP_BUFFER_SIZE(image->cmap.info);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    cmap_size = TCM_CMAP_BUFFER_SIZE(image->cmap.info);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  palette[0]  = plt_type;
Shinya Kitaoka 120a6e
  palette[1]  = image->cmap.offset;
Shinya Kitaoka 120a6e
  palette[2]  = cmap_size <= 0xffff ? cmap_size : 0;
Shinya Kitaoka 120a6e
  palette[3]  = 0 /* image->cmap.info.tone_offs */;
Shinya Kitaoka 120a6e
  palette[4]  = image->cmap.info.tone_bits;
Shinya Kitaoka 120a6e
  palette[5]  = image->cmap.info.color_offs;
Shinya Kitaoka 120a6e
  palette[6]  = image->cmap.info.color_bits;
Shinya Kitaoka 120a6e
  palette[7]  = image->cmap.info.pencil_offs;
Shinya Kitaoka 120a6e
  palette[8]  = image->cmap.info.pencil_bits;
Shinya Kitaoka 120a6e
  palette[9]  = image->cmap.info.offset_mask;
Shinya Kitaoka 120a6e
  palette[10] = image->cmap.info.n_colors;
Shinya Kitaoka 120a6e
  palette[11] = image->cmap.info.n_pencils;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 12; i < TOONZPALETTE_COUNT - 1; i++) palette[i] = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  palette[TOONZPALETTE_COUNT - 1] = (Img_license_attr & TA_TOONZ_EDU) != 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_TOONZPALETTE, palette);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (plt_type == 3) {
Shinya Kitaoka 120a6e
    assert(image->cmap.color && image->cmap.pencil);
Shinya Kitaoka 120a6e
    width = image->cmap.color_n + image->cmap.pencil_n;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (image->cmap.color && image->cmap.pencil)
Shinya Kitaoka 120a6e
      width = cmap_size + image->cmap.color_n + image->cmap.pencil_n;
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      width = cmap_size;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_BITSPERSAMPLE, 8);
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_SAMPLESPERPIXEL, 4);
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_IMAGEWIDTH, width);
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_IMAGELENGTH, 1);
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  names_pointer = (TREE *)image->cmap.names;
Shinya Kitaoka 120a6e
  image->cmap.names =
Shinya Kitaoka 120a6e
      cdb_encode_names((TREE *)image->cmap.names, &(image->cmap.names_max));
Shinya Kitaoka 120a6e
  str                  = build_string_names(image);
Shinya Kitaoka 120a6e
  names_string_pointer = (char *)image->cmap.names;
Shinya Kitaoka 120a6e
  image->cmap.names    = (USHORT *)names_pointer;
Shinya Kitaoka 120a6e
  if (names_string_pointer) free(names_string_pointer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  names = cdb_encode_all(image->cmap.names);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_TOONZCOLORNAMES, names);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* Aggiungo History */
Shinya Kitaoka 120a6e
  history = build_history();
Shinya Kitaoka 120a6e
  if (image->history) {
Shinya Kitaoka 120a6e
    switch (check_history(image->history, history)) {
Shinya Kitaoka 120a6e
      CASE APPEND : image->history = append_history(image->history, history);
Shinya Kitaoka 120a6e
      CASE REPLACE : image->history =
Shinya Kitaoka 120a6e
          replace_last_history(image->history, history);
Shinya Kitaoka 120a6e
    DEFAULT:
Shinya Kitaoka 120a6e
      printf("Internal error: bad history type; aborting...\n");
Shinya Kitaoka 120a6e
      abort();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    free(history);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    image->history = history;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_TOONZHISTORY, image->history);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  scanline = TIFFScanlineSize(tfp);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
* massima lunghezza di bytes in una strip e' 8k
Shinya Kitaoka 120a6e
* vedi Graphics File Formats pag.48
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  rows_per_strip = (8 * 1024) / scanline;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFSetField(tfp, TIFFTAG_ROWSPERSTRIP,
Shinya Kitaoka 120a6e
               rows_per_strip == 0 ? 1L : rows_per_strip);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TMALLOC(buffer, scanline);
Shinya Kitaoka 120a6e
  cmap   = image->cmap.buffer;
Shinya Kitaoka 120a6e
  color  = image->cmap.color;
Shinya Kitaoka 120a6e
  pencil = image->cmap.pencil;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (plt_type) {
Shinya Kitaoka 120a6e
    CASE 1
Shinya Kitaoka 120a6e
        : printf(
Shinya Kitaoka 120a6e
              "img_rwite_plt error: type 1 .plt's are not written any more\n");
Shinya Kitaoka 120a6e
    abort();
Shinya Kitaoka 120a6e
    CASE 2 : __OR 4 : for (i = 0, j = 0; i < cmap_size; i++, j += 4) {
Shinya Kitaoka 120a6e
      buffer[j + 0] = cmap[i].r;
Shinya Kitaoka 120a6e
      buffer[j + 1] = cmap[i].g;
Shinya Kitaoka 120a6e
      buffer[j + 2] = cmap[i].b;
Shinya Kitaoka 120a6e
      buffer[j + 3] = cmap[i].m;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (width > cmap_size) {
Shinya Kitaoka 120a6e
      for (i = 0; i < image->cmap.color_n; i++, j += 4) {
Shinya Kitaoka 120a6e
        buffer[j + 0] = color[i].r;
Shinya Kitaoka 120a6e
        buffer[j + 1] = color[i].g;
Shinya Kitaoka 120a6e
        buffer[j + 2] = color[i].b;
Shinya Kitaoka 120a6e
        buffer[j + 3] = color[i].m;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      for (i = 0; i < image->cmap.pencil_n; i++, j += 4) {
Shinya Kitaoka 120a6e
        buffer[j + 0] = pencil[i].r;
Shinya Kitaoka 120a6e
        buffer[j + 1] = pencil[i].g;
Shinya Kitaoka 120a6e
        buffer[j + 2] = pencil[i].b;
Shinya Kitaoka 120a6e
        buffer[j + 3] = pencil[i].m;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    CASE 3 : for (i = 0, j = 0; i < image->cmap.color_n; i++, j += 4) {
Shinya Kitaoka 120a6e
      buffer[j + 0] = color[i].m; /* different from type 2 */
Shinya Kitaoka 120a6e
      buffer[j + 1] = color[i].b;
Shinya Kitaoka 120a6e
      buffer[j + 2] = color[i].g;
Shinya Kitaoka 120a6e
      buffer[j + 3] = color[i].r;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    for (i = 0; i < image->cmap.pencil_n; i++, j += 4) {
Shinya Kitaoka 120a6e
      buffer[j + 0] = pencil[i].m;
Shinya Kitaoka 120a6e
      buffer[j + 1] = pencil[i].b;
Shinya Kitaoka 120a6e
      buffer[j + 2] = pencil[i].g;
Shinya Kitaoka 120a6e
      buffer[j + 3] = pencil[i].r;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  DEFAULT:
Shinya Kitaoka 120a6e
    assert(!"bad palette type");
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (TIFFWriteScanline(tfp, buffer, 0, 0) < 0) goto bad;
Shinya Kitaoka 120a6e
  TFREE(buffer);
Shinya Kitaoka 120a6e
  TIFFClose(tfp);
Shinya Kitaoka 120a6e
  TFREE(names);
Shinya Kitaoka 120a6e
  return TRUE;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bad:
Shinya Kitaoka 120a6e
  TFREE(buffer);
Shinya Kitaoka 120a6e
  TIFFClose(tfp);
Shinya Kitaoka 120a6e
  TFREE(names);
Shinya Kitaoka 120a6e
  return FALSE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*===========================================================================*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void next_img_read_plt_without_buffer(void) {
Shinya Kitaoka 120a6e
  Next_img_read_plt_without_buffer = TRUE;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
IMAGE *img_read_plt(char *filename) {
Shinya Kitaoka 120a6e
  int with_cmap_buffer;
Shinya Kitaoka 120a6e
  IMAGE *image = NIL;
Shinya Kitaoka 120a6e
  TIFF *tfp;
Shinya Kitaoka 120a6e
  UCHAR *buffer = NIL;
Shinya Kitaoka 120a6e
  int i, j, scanline;
Shinya Kitaoka 120a6e
  LPIXEL *cmap;
Shinya Kitaoka 120a6e
  USHORT *palette; /*  [TOONZPALETTE_COUNT] */
Shinya Kitaoka 120a6e
  USHORT spp, bps, comp, plan_con, photom;
Shinya Kitaoka 120a6e
  int width, height;
Shinya Kitaoka 120a6e
  char *names;
Shinya Kitaoka 120a6e
  int plt_type, m, cmap_file_size, cmap_alloc_size;
Shinya Kitaoka 120a6e
  int colpen_cmap, colbuf_alloc_size, penbuf_alloc_size;
Shinya Kitaoka 120a6e
  int max_n_colors, max_n_pencils;
Shinya Kitaoka 120a6e
  int act_n_colors, act_n_pencils, index;
Shinya Kitaoka 120a6e
  LPIXEL grey, black;
Shinya Kitaoka 120a6e
  TBOOL edu_file;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CHECK_IMAGEDLL_LICENSE_AND_GET_IMG_LICENSE_ATTR
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  SET_READ_WITHOUT_BUFFER
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tfp = TIFFOpen(filename, "r");
Shinya Kitaoka 120a6e
  if (!tfp) return NIL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_TOONZPALETTE, &palette);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_TOONZCOLORNAMES, &names);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_BITSPERSAMPLE, &bps);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_SAMPLESPERPIXEL, &spp);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_IMAGEWIDTH, &width);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_IMAGELENGTH, &height);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_COMPRESSION, &comp);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_PLANARCONFIG, &plan_con);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_PHOTOMETRIC, &photom);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (photom != PHOTOMETRIC_RGB || plan_con != PLANARCONFIG_CONTIG) goto bad;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  edu_file = palette[TOONZPALETTE_COUNT - 1] & 1;
Shinya Kitaoka 120a6e
  if (edu_file && !(Img_license_attr & TA_TOONZ_EDU)) {
Shinya Kitaoka 120a6e
    char str[1024];
Shinya Kitaoka 120a6e
    BUILD_EDU_ERROR_STRING(str)
Shinya Kitaoka 120a6e
    tmsg_error(str);
Shinya Kitaoka 120a6e
    goto bad;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  scanline = TIFFScanlineSize(tfp);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  image = new_img();
Shinya Kitaoka 120a6e
  if (!image) goto bad;
Shinya Kitaoka 120a6e
  image->type = CMAP;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* Leggo history */
Shinya Kitaoka 120a6e
  if (!TIFFGetField(tfp, TIFFTAG_TOONZHISTORY, &image->history))
Shinya Kitaoka 120a6e
    image->history = "";
Shinya Kitaoka 120a6e
  image->history   = strsave(image->history);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  plt_type             = palette[0];
Shinya Kitaoka 120a6e
  image->cmap.offset   = palette[1];
Shinya Kitaoka 120a6e
  image->cmap.color_n  = palette[10];
Shinya Kitaoka 120a6e
  image->cmap.pencil_n = palette[11];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  image->cmap.info = Tcm_old_default_info;
Shinya Kitaoka 120a6e
  if (palette[6]) {
Shinya Kitaoka 120a6e
    /*image->cmap.info.tone_offs   = palette[3]; */
Shinya Kitaoka 120a6e
    image->cmap.info.tone_bits   = palette[4];
Shinya Kitaoka 120a6e
    image->cmap.info.color_offs  = palette[5];
Shinya Kitaoka 120a6e
    image->cmap.info.color_bits  = palette[6];
Shinya Kitaoka 120a6e
    image->cmap.info.pencil_offs = palette[7];
Shinya Kitaoka 120a6e
    image->cmap.info.pencil_bits = palette[8];
Shinya Kitaoka 120a6e
    image->cmap.info.offset_mask = palette[9];
Shinya Kitaoka 120a6e
    image->cmap.info.n_tones     = 1 << palette[4];
Shinya Kitaoka 120a6e
    image->cmap.info.n_colors    = palette[10];
Shinya Kitaoka 120a6e
    image->cmap.info.n_pencils   = palette[11];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  image->cmap.info.default_val =
Shinya Kitaoka 120a6e
      (image->cmap.info.n_tones - 1) | image->cmap.info.offset_mask;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  cmap_alloc_size   = TCM_CMAP_BUFFER_SIZE(image->cmap.info);
Shinya Kitaoka 120a6e
  cmap_file_size    = palette[2] ? palette[2] : cmap_alloc_size;
Shinya Kitaoka 120a6e
  colpen_cmap       = image->cmap.info.n_tones > 16;
Shinya Kitaoka 120a6e
  colbuf_alloc_size = TCM_CMAP_COLBUFFER_SIZE(image->cmap.info);
Shinya Kitaoka 120a6e
  penbuf_alloc_size = TCM_CMAP_PENBUFFER_SIZE(image->cmap.info);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TMALLOC(buffer, scanline);
Shinya Kitaoka 120a6e
  if (!buffer) goto bad;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  with_cmap_buffer = !Read_without_buffer || (plt_type <= 2) || (plt_type == 4);
Shinya Kitaoka 120a6e
  if (with_cmap_buffer) {
Shinya Kitaoka 120a6e
    if (colpen_cmap) {
Shinya Kitaoka 120a6e
      TMALLOC(image->cmap.colbuffer, colbuf_alloc_size);
Shinya Kitaoka 120a6e
      TMALLOC(image->cmap.penbuffer, penbuf_alloc_size);
Shinya Kitaoka 120a6e
      if (!image->cmap.colbuffer || !image->cmap.penbuffer) goto bad;
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      TMALLOC(image->cmap.buffer, cmap_alloc_size);
Shinya Kitaoka 120a6e
      if (!image->cmap.buffer) goto bad;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  TCALLOC(image->cmap.color, 1 << image->cmap.info.color_bits);
Shinya Kitaoka 120a6e
  if (!image->cmap.color) goto bad;
Shinya Kitaoka 120a6e
  TCALLOC(image->cmap.pencil, 1 << image->cmap.info.pencil_bits);
Shinya Kitaoka 120a6e
  if (!image->cmap.pencil) goto bad;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (TIFFReadScanline(tfp, buffer, 0, 0) < 0) goto bad;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  switch (plt_type) {
Shinya Kitaoka 120a6e
    CASE 1 : if (!with_cmap_buffer) {
Shinya Kitaoka 120a6e
      TCALLOC(image->cmap.buffer, cmap_alloc_size)
Shinya Kitaoka 120a6e
      if (!image->cmap.buffer) goto bad;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    for (i = 0, j = 0; i < cmap_file_size; i++, j += 4) {
Shinya Kitaoka 120a6e
      image->cmap.buffer[i].r = buffer[j + 0];
Shinya Kitaoka 120a6e
      image->cmap.buffer[i].g = buffer[j + 1];
Shinya Kitaoka 120a6e
      image->cmap.buffer[i].b = buffer[j + 2];
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    to_new_cmap(&image->cmap);
Shinya Kitaoka 120a6e
    set_colors_and_pencils(&image->cmap);
Shinya Kitaoka 120a6e
    if (!with_cmap_buffer) TFREE(image->cmap.buffer)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    CASE 2 : __OR 4
Shinya Kitaoka 120a6e
             : if (with_cmap_buffer) for (i = 0, j = 0; i < cmap_file_size;
Shinya Kitaoka 120a6e
                                          i++, j += 4) {
Shinya Kitaoka 120a6e
      image->cmap.buffer[i].r = buffer[j + 0];
Shinya Kitaoka 120a6e
      image->cmap.buffer[i].g = buffer[j + 1];
Shinya Kitaoka 120a6e
      image->cmap.buffer[i].b = buffer[j + 2];
Shinya Kitaoka 120a6e
      image->cmap.buffer[i].m = buffer[j + 3];
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    else j = 4 * cmap_file_size;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (width > cmap_file_size) {
Shinya Kitaoka 120a6e
      for (i = 0; i < image->cmap.color_n; i++, j += 4) {
Shinya Kitaoka 120a6e
        image->cmap.color[i].r = buffer[j + 0];
Shinya Kitaoka 120a6e
        image->cmap.color[i].g = buffer[j + 1];
Shinya Kitaoka 120a6e
        image->cmap.color[i].b = buffer[j + 2];
Shinya Kitaoka 120a6e
        image->cmap.color[i].m = buffer[j + 3];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      for (i = 0; i < image->cmap.pencil_n; i++, j += 4) {
Shinya Kitaoka 120a6e
        image->cmap.pencil[i].r = buffer[j + 0];
Shinya Kitaoka 120a6e
        image->cmap.pencil[i].g = buffer[j + 1];
Shinya Kitaoka 120a6e
        image->cmap.pencil[i].b = buffer[j + 2];
Shinya Kitaoka 120a6e
        image->cmap.pencil[i].m = buffer[j + 3];
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      set_colors_and_pencils(&image->cmap);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    CASE 3 : for (i = 0, j = 0; i < image->cmap.color_n; i++, j += 4) {
Shinya Kitaoka 120a6e
      image->cmap.color[i].m = buffer[j + 0]; /* different from type 2 */
Shinya Kitaoka 120a6e
      image->cmap.color[i].b = buffer[j + 1];
Shinya Kitaoka 120a6e
      image->cmap.color[i].g = buffer[j + 2];
Shinya Kitaoka 120a6e
      image->cmap.color[i].r = buffer[j + 3];
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    for (i = 0; i < image->cmap.pencil_n; i++, j += 4) {
Shinya Kitaoka 120a6e
      image->cmap.pencil[i].m = buffer[j + 0];
Shinya Kitaoka 120a6e
      image->cmap.pencil[i].b = buffer[j + 1];
Shinya Kitaoka 120a6e
      image->cmap.pencil[i].g = buffer[j + 2];
Shinya Kitaoka 120a6e
      image->cmap.pencil[i].r = buffer[j + 3];
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (with_cmap_buffer)
Shinya Kitaoka 120a6e
      if (colpen_cmap) {
Shinya Kitaoka 120a6e
        memset(image->cmap.colbuffer, 0, colbuf_alloc_size * sizeof(LPIXEL));
Shinya Kitaoka 120a6e
        memset(image->cmap.penbuffer, 0, penbuf_alloc_size * sizeof(LPIXEL));
Shinya Kitaoka 120a6e
        fill_cmap_colbuffer(image->cmap.colbuffer, image->cmap.info,
Shinya Kitaoka 120a6e
                            image->cmap.color, FALSE);
Shinya Kitaoka 120a6e
        fill_cmap_penbuffer(image->cmap.penbuffer, image->cmap.info,
Shinya Kitaoka 120a6e
                            image->cmap.pencil, FALSE);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        memset(image->cmap.buffer, 0, cmap_alloc_size * sizeof(LPIXEL));
Shinya Kitaoka 120a6e
        fill_cmap_buffer(image->cmap.buffer, image->cmap.info,
Shinya Kitaoka 120a6e
                         image->cmap.color, image->cmap.pencil, FALSE);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
  DEFAULT:
Shinya Kitaoka 120a6e
    goto bad;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  set_color_names(image, names);
Shinya Kitaoka 120a6e
  names_pointer = image->cmap.names;
Shinya Kitaoka 120a6e
  image->cmap.names =
Shinya Kitaoka 120a6e
      (USHORT *)cdb_decode_names(image->cmap.names, image->cmap.names_max);
Shinya Kitaoka 120a6e
  TFREE(names_pointer);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  image->cmap.names = cdb_decode_all(names, image->cmap.info);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* estendo la palette */
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  max_n_colors  = 1 << image->cmap.info.color_bits;
Shinya Kitaoka 120a6e
  max_n_pencils = 1 << image->cmap.info.pencil_bits;
Shinya Kitaoka 120a6e
  if (max_n_colors > image->cmap.info.n_colors ||
Shinya Kitaoka 120a6e
      max_n_pencils > image->cmap.info.n_pencils) {
Shinya Kitaoka 120a6e
    act_n_colors               = image->cmap.info.n_colors;
Shinya Kitaoka 120a6e
    act_n_pencils              = image->cmap.info.n_pencils;
Shinya Kitaoka 120a6e
    image->cmap.info.n_colors  = max_n_colors;
Shinya Kitaoka 120a6e
    image->cmap.info.n_pencils = max_n_pencils;
Shinya Kitaoka 120a6e
    image->cmap.color_n        = image->cmap.info.n_colors;
Shinya Kitaoka 120a6e
    image->cmap.pencil_n       = image->cmap.info.n_pencils;
Shinya Kitaoka 120a6e
    grey.r = grey.g = grey.b = 127;
Shinya Kitaoka 120a6e
    grey.m                   = 255;
Shinya Kitaoka 120a6e
    black.r = black.g = black.b = 0;
Shinya Kitaoka 120a6e
    black.m                     = 255;
Shinya Kitaoka 120a6e
    for (i = act_n_colors; i < max_n_colors; i++) {
Shinya Kitaoka 120a6e
      image->cmap.color[i] = grey;
Shinya Kitaoka 120a6e
      index                = TCM_COLOR_INDEX(image->cmap.info, i);
Shinya Kitaoka 120a6e
      cdb_set_group(image, index, UNUSED_COLOR_PAGE_NAME);
Shinya Kitaoka 120a6e
      if (with_cmap_buffer && colpen_cmap)
Shinya Kitaoka 120a6e
        fill_cmap_colramp(image->cmap.colbuffer, image->cmap.info,
Shinya Kitaoka 120a6e
                          image->cmap.color[i], i, FALSE);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    for (i = act_n_pencils; i < max_n_pencils; i++) {
Shinya Kitaoka 120a6e
      image->cmap.pencil[i] = black;
Shinya Kitaoka 120a6e
      index                 = TCM_PENCIL_INDEX(image->cmap.info, i);
Shinya Kitaoka 120a6e
      cdb_set_group(image, index, UNUSED_COLOR_PAGE_NAME);
Shinya Kitaoka 120a6e
      if (with_cmap_buffer && colpen_cmap)
Shinya Kitaoka 120a6e
        fill_cmap_penramp(image->cmap.penbuffer, image->cmap.info,
Shinya Kitaoka 120a6e
                          image->cmap.pencil[i], i, FALSE);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (with_cmap_buffer && !colpen_cmap)
Shinya Kitaoka 120a6e
      fill_cmap_buffer(image->cmap.buffer, image->cmap.info, image->cmap.color,
Shinya Kitaoka 120a6e
                       image->cmap.pencil, FALSE);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (buffer) TFREE(buffer);
Shinya Kitaoka 120a6e
  TIFFClose(tfp);
Shinya Kitaoka 120a6e
  return image;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bad:
Shinya Kitaoka 120a6e
  if (image) free_img(image);
Shinya Kitaoka 120a6e
  TFREE(buffer);
Shinya Kitaoka 120a6e
  TIFFClose(tfp);
Shinya Kitaoka 120a6e
  return NIL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
IMAGE *img_read_plt_info(char *filename) {
Shinya Kitaoka 120a6e
  IMAGE *image = NIL;
Shinya Kitaoka 120a6e
  TIFF *tfp;
Shinya Kitaoka 120a6e
  USHORT *palette; /*  [TOONZPALETTE_COUNT] */
Shinya Kitaoka 120a6e
  USHORT plan_con, photom;
Shinya Kitaoka 120a6e
  char *names;
Shinya Kitaoka 120a6e
  int max_n_colors, max_n_pencils;
Shinya Kitaoka 120a6e
  TBOOL edu_file;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CHECK_IMAGEDLL_LICENSE_AND_GET_IMG_LICENSE_ATTR
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  tfp = TIFFOpen(filename, "r");
Shinya Kitaoka 120a6e
  if (!tfp) return NIL;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_TOONZPALETTE, &palette);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_TOONZCOLORNAMES, &names);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_PLANARCONFIG, &plan_con);
Shinya Kitaoka 120a6e
  TIFFGetField(tfp, TIFFTAG_PHOTOMETRIC, &photom);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (photom != PHOTOMETRIC_RGB || plan_con != PLANARCONFIG_CONTIG) goto bad;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  edu_file = palette[TOONZPALETTE_COUNT - 1] & 1;
Shinya Kitaoka 120a6e
  if (edu_file && !(Img_license_attr & TA_TOONZ_EDU)) {
Shinya Kitaoka 120a6e
    char str[1024];
Shinya Kitaoka 120a6e
    BUILD_EDU_ERROR_STRING(str)
Shinya Kitaoka 120a6e
    tmsg_warning(str);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  image = new_img();
Shinya Kitaoka 120a6e
  if (!image) goto bad;
Shinya Kitaoka 120a6e
  image->type = CMAP;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (palette[0] < 1 || palette[0] > LATEST_PLT_TYPE) goto bad;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  image->cmap.offset   = palette[1];
Shinya Kitaoka 120a6e
  image->cmap.color_n  = palette[10];
Shinya Kitaoka 120a6e
  image->cmap.pencil_n = palette[11];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  image->cmap.info = Tcm_old_default_info;
Shinya Kitaoka 120a6e
  if (palette[6]) {
Shinya Kitaoka 120a6e
    /*image->cmap.info.tone_offs   = palette[3]; */
Shinya Kitaoka 120a6e
    image->cmap.info.tone_bits   = palette[4];
Shinya Kitaoka 120a6e
    image->cmap.info.color_offs  = palette[5];
Shinya Kitaoka 120a6e
    image->cmap.info.color_bits  = palette[6];
Shinya Kitaoka 120a6e
    image->cmap.info.pencil_offs = palette[7];
Shinya Kitaoka 120a6e
    image->cmap.info.pencil_bits = palette[8];
Shinya Kitaoka 120a6e
    image->cmap.info.offset_mask = palette[9];
Shinya Kitaoka 120a6e
    image->cmap.info.n_tones     = 1 << palette[4];
Shinya Kitaoka 120a6e
    image->cmap.info.n_colors    = palette[10];
Shinya Kitaoka 120a6e
    image->cmap.info.n_pencils   = palette[11];
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  image->cmap.info.default_val =
Shinya Kitaoka 120a6e
      (image->cmap.info.n_tones - 1) | image->cmap.info.offset_mask;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* Leggo history */
Shinya Kitaoka 120a6e
  if (!TIFFGetField(tfp, TIFFTAG_TOONZHISTORY, &image->history))
Shinya Kitaoka 120a6e
    image->history = "";
Shinya Kitaoka 120a6e
  image->history   = strsave(image->history);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  /* estendo la palette */
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  max_n_colors  = 1 << image->cmap.info.color_bits;
Shinya Kitaoka 120a6e
  max_n_pencils = 1 << image->cmap.info.pencil_bits;
Shinya Kitaoka 120a6e
  if (max_n_colors > image->cmap.info.n_colors ||
Shinya Kitaoka 120a6e
      max_n_pencils > image->cmap.info.n_pencils) {
Shinya Kitaoka 120a6e
    image->cmap.info.n_colors  = max_n_colors;
Shinya Kitaoka 120a6e
    image->cmap.info.n_pencils = max_n_pencils;
Shinya Kitaoka 120a6e
    image->cmap.color_n        = image->cmap.info.n_colors;
Shinya Kitaoka 120a6e
    image->cmap.pencil_n       = image->cmap.info.n_pencils;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  image->cmap.names = cdb_decode_all(names, image->cmap.info);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TIFFClose(tfp);
Shinya Kitaoka 120a6e
  return image;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bad:
Shinya Kitaoka 120a6e
  if (image) free_img(image);
Shinya Kitaoka 120a6e
  TIFFClose(tfp);
Shinya Kitaoka 120a6e
  return NIL;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/* Attenzione: se si modifica questa funzione, occore riportare le
Toshihiro Shimizu 890ddd
 *             variazioni nella libreria line x line (simg_plt.c)
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static char *plt_find_color_name(IMAGE *img, int color) {
Shinya Kitaoka 120a6e
  char *name;
Shinya Kitaoka 120a6e
  int index;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  index = TCM_COLOR_INDEX(img->cmap.info, color);
Shinya Kitaoka 120a6e
  name  = find_color_name(img, index);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return name;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/* Attenzione: se si modifica questa funzione, occore riportare le
Toshihiro Shimizu 890ddd
 *             variazioni nella libreria line x line (simg_plt.c)
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static char *plt_find_pencil_name(IMAGE *img, int pencil) {
Shinya Kitaoka 120a6e
  char *name;
Shinya Kitaoka 120a6e
  int index;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  index = TCM_PENCIL_INDEX(img->cmap.info, pencil);
Shinya Kitaoka 120a6e
  name  = find_color_name(img, index);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return name;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/* Attenzione: se si modifica questa funzione, occore riportare le
Toshihiro Shimizu 890ddd
 *             variazioni nella libreria line x line (simg_plt.c)
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static void plt_set_color_name(IMAGE *img, int color, char *name) {
Shinya Kitaoka 120a6e
  int index;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  index = TCM_COLOR_INDEX(img->cmap.info, color);
Shinya Kitaoka 120a6e
  set_color_name(img, index, name);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/* Attenzione: se si modifica questa funzione, occore riportare le
Toshihiro Shimizu 890ddd
 *             variazioni nella libreria line x line (simg_plt.c)
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static void plt_set_pencil_name(IMAGE *img, int pencil, char *name) {
Shinya Kitaoka 120a6e
  int index;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  index = TCM_PENCIL_INDEX(img->cmap.info, pencil);
Shinya Kitaoka 120a6e
  set_color_name(img, index, name);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/* Attenzione: se si modifica questa funzione, occore riportare le
Toshihiro Shimizu 890ddd
 *             variazioni nella libreria line x line (simg_plt.c)
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static char *build_string_names(IMAGE *image) {
Shinya Kitaoka 120a6e
  char *str, *name;
Shinya Kitaoka 120a6e
  int i, maxsize = 1000, ptr, len;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  str = (char *)malloc(maxsize);
Shinya Kitaoka 120a6e
  ptr = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < image->cmap.color_n; i++) {
Shinya Kitaoka 120a6e
    name = plt_find_color_name(image, i);
Shinya Kitaoka 120a6e
    if (name && *name) {
Shinya Kitaoka 120a6e
      len = strlen(name);
Shinya Kitaoka 120a6e
      if ((len + ptr) >= maxsize) {
Shinya Kitaoka 120a6e
        maxsize += 200;
Shinya Kitaoka 120a6e
        str = (char *)realloc(str, maxsize);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      memmove(str + ptr, name, len);
Shinya Kitaoka 120a6e
      ptr += len;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (ptr + 1 >= maxsize) {
Shinya Kitaoka 120a6e
      maxsize += 200;
Shinya Kitaoka 120a6e
      str = (char *)realloc(str, maxsize);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    memmove(str + ptr, "|", 1);
Shinya Kitaoka 120a6e
    ptr++;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < image->cmap.pencil_n; i++) {
Shinya Kitaoka 120a6e
    name = plt_find_pencil_name(image, i);
Shinya Kitaoka 120a6e
    if (name && *name) {
Shinya Kitaoka 120a6e
      len = strlen(name);
Shinya Kitaoka 120a6e
      if ((len + ptr) >= maxsize) {
Shinya Kitaoka 120a6e
        maxsize += 200;
Shinya Kitaoka 120a6e
        str = (char *)realloc(str, maxsize);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      memmove(str + ptr, name, len);
Shinya Kitaoka 120a6e
      ptr += len;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (ptr + 1 >= maxsize) {
Shinya Kitaoka 120a6e
      maxsize += 200;
Shinya Kitaoka 120a6e
      str = (char *)realloc(str, maxsize);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    memmove(str + ptr, "|", 1);
Shinya Kitaoka 120a6e
    ptr++;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  str[ptr] = 0;
Shinya Kitaoka 120a6e
  return str;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
/*---------------------------------------------------------------------------*/
Toshihiro Shimizu 890ddd
/* Attenzione: se si modifica questa funzione, occore riportare le
Toshihiro Shimizu 890ddd
 *             variazioni nella libreria line x line (simg_plt.c)
Toshihiro Shimizu 890ddd
 */
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef VECCHIA_MANIERA
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
static void set_color_names(IMAGE *image, char *names) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  char *s, *name;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  s = names;
Shinya Kitaoka 120a6e
  i = 0;
Shinya Kitaoka 120a6e
  while (*s) {
Shinya Kitaoka 120a6e
    name = NULL;
Shinya Kitaoka 120a6e
    if (*s != '|') {
Shinya Kitaoka 120a6e
      name = s;
Shinya Kitaoka 120a6e
      while (*s && *s != '|') s++;
Shinya Kitaoka 120a6e
      *s = 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (name) {
Shinya Kitaoka 120a6e
      if (i < image->cmap.info.n_colors)
Shinya Kitaoka 120a6e
        plt_set_color_name(image, i, name);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        plt_set_pencil_name(image, i - image->cmap.info.n_colors, name);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    i++;
Shinya Kitaoka 120a6e
    s++;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif