1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
/*
* This file is part of the XForms library package.
*
* XForms is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1, or
* (at your option) any later version.
*
* XForms 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with XForms. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* A color quantizer based on octree algorithm. The algorithm
* is implemented and copyright by Steve Lamont (spl@ucsd.edu)
* Copyright (C) 1998, Steve Lamont and the National Center for Microscopy
* and Imaging Research
*
* Contact Steve for the latest version of the quantization library.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "include/forms.h"
#include "flimage.h"
#include "flimage_int.h"
#include "quantize.h"
/***************************************
***************************************/
void fl_select_octree_quantizer( void )
{
flimage_quantize_rgb = fl_octree_quantize_rgb;
flimage_quantize_packed = fl_octree_quantize_packed;
}
/***************************************
***************************************/
int
fl_octree_quantize_rgb( unsigned char ** red,
unsigned char ** green,
unsigned char ** blue,
int w,
int h,
int max_color,
unsigned short ** ci,
int * actual_color,
int * red_lut,
int * green_lut,
int * blue_lut,
FL_IMAGE * im )
{
int i,
j;
unsigned int *rlut,
*glut,
*blut;
QuantizeDatabaseP database = QuantizeInitialize( max_color,
QuantizeStyleLeast );
if ( im )
{
im->completed = 0;
im->visual_cue( im, "Starting OctreeQuantizer ..." );
}
for ( i = 0; i < h; i++ )
for ( j = 0; j < w; j++ )
QuantizeColor( database,
red[ i ][ j ], green[ i ][ j ], blue[ i ][ j ] );
QuantizeCreateLUT( database, actual_color, &rlut, &glut, &blut);
for ( i = 0; i < *actual_color; i++ )
{
red_lut[ i ] = rlut[ i ];
green_lut[ i ] = glut[ i ];
blue_lut[ i ] = blut[ i ];
}
free( rlut );
free( glut );
free( blut );
for ( i = 0; i < h; i++ )
for ( j = 0; j < w; j++ )
ci[ i ][ j ] = QuantizeFindIndex( database, red[ i ][ j ],
green[ i ][ j ], blue[ i ][ j ] );
QuantizeDatabaseFree( database );
if ( im )
{
im->completed = im->total;
im->visual_cue( im, "Done OctreeQuantizer" );
}
return 0;
}
/***************************************
***************************************/
int
fl_octree_quantize_packed( unsigned int ** packed,
int w,
int h,
int max_color,
unsigned short ** ci,
int * actual_color,
int * red_lut,
int * green_lut,
int * blue_lut,
FL_IMAGE * im )
{
int i,
n = h * w;
unsigned int *p;
unsigned short *ind;
unsigned int *rlut,
*glut,
*blut;
QuantizeDatabaseP database = QuantizeInitialize( max_color,
QuantizeStyleLeast );
if ( im )
{
im->completed = 0;
im->visual_cue( im, "Starting OctreeQuantizer ..." );
}
for ( p = packed[ 0 ], i = 0; i < n; i++, p++ )
QuantizeColor( database, FL_GETR( *p ), FL_GETG( *p ), FL_GETB( *p ) );
QuantizeCreateLUT( database, actual_color, &rlut, &glut, &blut );
for ( i = 0; i < *actual_color; i++ )
{
red_lut[ i ] = rlut[ i ];
green_lut[ i ] = glut[ i ];
blue_lut[ i ] = blut[ i ];
}
free( rlut );
free( glut );
free( blut );
for ( ind = ci[ 0 ], p = packed[ 0 ], i = 0; i < n; i++, p++, ind++ )
*ind = QuantizeFindIndex( database, FL_GETR( *p ),
FL_GETG( *p ), FL_GETB( *p ) );
QuantizeDatabaseFree( database );
if ( im )
{
im->completed = im->total;
im->visual_cue( im, "Done OctreeQuantizer" );
}
return 0;
}
/*
* Local variables:
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/
|