-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquantize.h
63 lines (55 loc) · 2.5 KB
/
quantize.h
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
/*****************************************************************************
* "Gif-Lib" - Yet another gif library.
*
* Written by: Gershon Elber IBM PC Ver 0.1, Jun. 1989
******************************************************************************
* Module to quatize high resolution image into lower one. You may want to
* peek into the following article this code is based on:
* "Color Image Quantization for frame buffer Display", by Paul Heckbert
* SIGGRAPH 1982 page 297-307.
******************************************************************************
* History:
* 5 Jan 90 - Version 1.0 by Gershon Elber.
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#define GIF_ERROR 0
#define GIF_OK 1
typedef unsigned char GifPixelType;
typedef unsigned char GifByteType;
typedef struct GifColorType {
GifByteType Red, Green, Blue;
} GifColorType;
typedef struct QuantizedColorType {
GifByteType RGB[3];
GifByteType NewColorIndex;
long Count;
struct QuantizedColorType *Pnext;
} QuantizedColorType;
typedef struct NewColorMapType {
GifByteType RGBMin[3], RGBWidth[3];
unsigned int NumEntries; /* # of QuantizedColorType in linked list below */
unsigned long Count; /* Total number of pixels in all the entries */
QuantizedColorType *QuantizedColors;
} NewColorMapType;
/******************************************************************************
* Quantize high resolution image into lower one. Input image consists of a
* 2D array for each of the RGB colors with size Width by Height. There is no
* Color map for the input. Output is a quantized image with 2D array of
* indexes into the output color map.
* Note input image can be 24 bits at the most (8 for red/green/blue) and
* the output has 256 colors at the most (256 entries in the color map.).
* ColorMapSize specifies size of color map up to 256 and will be updated to
* real size before returning.
* Also non of the parameter are allocated by this routine.
* This function returns GIF_OK if succesfull, GIF_ERROR otherwise.
******************************************************************************/
int
QuantizeBuffer(unsigned int Width,
unsigned int Height,
int *ColorMapSize,
GifByteType * RedInput,
GifByteType * GreenInput,
GifByteType * BlueInput,
GifByteType * OutputBuffer,
GifColorType * OutputColorMap);