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