From 5a422aba704c375a307a902bafe658342e209906 Mon Sep 17 00:00:00 2001 From: scuri Date: Fri, 17 Oct 2008 06:10:15 +0000 Subject: First commit - moving from LuaForge to SourceForge --- src/process/im_quantize.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/process/im_quantize.cpp (limited to 'src/process/im_quantize.cpp') diff --git a/src/process/im_quantize.cpp b/src/process/im_quantize.cpp new file mode 100644 index 0000000..9a65f4c --- /dev/null +++ b/src/process/im_quantize.cpp @@ -0,0 +1,65 @@ +/** \file + * \brief Additional Image Quantization Operations + * + * See Copyright Notice in im_lib.h + * $Id: im_quantize.cpp,v 1.1 2008/10/17 06:16:33 scuri Exp $ + */ + + +#include +#include +#include +#include + +#include "im_process_pon.h" + +#include +#include + + +void imProcessQuantizeRGBUniform(const imImage* src_image, imImage* dst_image, int dither) +{ + imbyte *dst_map=(imbyte*)dst_image->data[0], + *red_map=(imbyte*)src_image->data[0], + *green_map=(imbyte*)src_image->data[1], + *blue_map=(imbyte*)src_image->data[2]; + + long *palette = imPaletteUniform(); + imImageSetPalette(dst_image, palette, 256); + + for (int y = 0; y < src_image->height; y++) + { + for (int x = 0; x < src_image->width; x++) + { + if (dither) + *dst_map++ = (imbyte)imPaletteUniformIndexHalftoned(imColorEncode(*red_map++, *green_map++, *blue_map++), x, y); + else + *dst_map++ = (imbyte)imPaletteUniformIndex(imColorEncode(*red_map++, *green_map++, *blue_map++)); + } + } +} + +void imProcessQuantizeGrayUniform(const imImage* src_image, imImage* dst_image, int grays) +{ + int i, value; + + imbyte *dst_map=(imbyte*)dst_image->data[0], + *src_map=(imbyte*)src_image->data[0]; + + imbyte re_map[256]; + memset(re_map, 0, 256); + + float factor = (float)grays/256.0f; + float factor256 = 256.0f/(float)grays; + + for (i = 0; i < 256; i++) + { + value = imResample(i, factor); + value = imResample(value, factor256); + re_map[i] = (imbyte)IM_BYTECROP(value); + } + + int total_count = src_image->count*src_image->depth; + for (i = 0; i < total_count; i++) + dst_map[i] = re_map[src_map[i]]; +} -- cgit v1.2.3