/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * filename: m-color.c * * * * UTIL C-source: Medical Image Conversion Utility * * * * purpose : make color palettes * * * * project : (X)MedCon by Erik Nolf * * * * Functions : MdcLoadLUT() - Load LUT file into RGB array * * MdcGrayScale() - Make gray palette * * MdcInvertedScale() - Make inverted gray palette * * MdcRainbowScale() - Make rainbow palette * * MdcCombinedScale() - Make combined palette * * MdcHotmetalScale() - Make hotmetal palette * * MdcGetColorMap() - Get the specified palette * * MdcSetPresentMap() - Preserve colormap in colored file * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* $Id: m-color.c,v 1.15 2007/05/21 20:16:10 enlf Exp $ */ /* Copyright (C) 1997-2007 by Erik Nolf 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, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Place - Suite 330, Boston, MA 02111-1307, USA. */ /**************************************************************************** H E A D E R S ****************************************************************************/ #include "m-depend.h" #include #ifdef HAVE_STRING_H #include #endif #ifdef HAVE_STRINGS_H #ifndef _WIN32 #include #endif #endif #include "m-defs.h" #include "m-global.h" #include "m-color.h" /**************************************************************************** D E F I N E S ****************************************************************************/ static Uint8 loaded_map[768], LOADED = MDC_NO; static Uint8 present_map[768]; /* map from file */ /* cti source */ struct {int n,r,g,b,dr,dg,db; } bitty[] = { {32,0,0,0,2,0,4}, /* violet to indigo */ {32,64,0,128,-2,0,4}, /* indigo to blue */ {32,0,0,255,0,8,-8}, /* blue to green */ {64,0,255,0,4,0,0}, /* green to yellow */ {32,255,255,0,0,-2,0}, /* yellow to orange */ {64,255,192,0,0,-3,0} }; /* orange to red */ /**************************************************************************** F U N C T I O N S ****************************************************************************/ int MdcLoadLUT(char *lutname) { FILE *fp; int s; LOADED = MDC_NO; if ((fp=fopen(lutname,"rb")) == NULL) return(MDC_NO); LOADED = MDC_YES; /* get red values */ for (s=0; s<768; s+=3) loaded_map[s] = (Uint8)fgetc(fp); /* get green values */ for (s=1; s<768; s+=3) loaded_map[s] = (Uint8)fgetc(fp); /* get blue values */ for (s=2; s<768; s+=3) loaded_map[s] = (Uint8)fgetc(fp); fclose(fp); return(MDC_YES); } void MdcGrayScale(Uint8 *palette) { int i; Uint8 gray; for (i=0; i<256; i++) { gray = (Uint8)i; palette[i*3]=palette[i*3+1]=palette[i*3+2]=gray; } } void MdcInvertedScale(Uint8 *palette) { int i; Uint8 gray; for (i=0; i<256; i++) { gray = 255 - (Uint8)i; palette[i*3]=palette[i*3+1]=palette[i*3+2]=gray; } } void MdcRainbowScale(Uint8 *palette) { int p=0,i,j,r,g,b; for (j=0;j<6;j++) { palette[p++]=r=bitty[j].r; palette[p++]=g=bitty[j].g; palette[p++]=b=bitty[j].b; for (i=1;i