📄 jccolor.c
字号:
/*
* jccolor.c
*
* Copyright (C) 1991-1996, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains input colorspace conversion routines.
*/
#include "commondecls.h"
#define MAXJSAMPLE 255
#define SCALEBITS 16 /* speediest right-shift on some machines */
#define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
#define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
/* We allocate one big table and divide it up into three parts, instead of
* doing eight alloc_small requests. This lets us use a single table base
* address, which can be held in a register in the inner loops on many
* machines (more than can hold all eight addresses, anyway).
*/
#define R_Y_OFF 0 /* offset to R => Y section */
#define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
#define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
/*
* Initialize for RGB->YCC colorspace conversion.
*/
void
jinit_color_transform (bmp_source_ptr sinfo)
{
INT32 * rgb_gray_tab;
INT32 i;
/* Allocate and fill in the conversion tables. */
sinfo->rgb_gray_tab = rgb_gray_tab = (INT32 *)
alloc_one_row ( ((size_t) (3*256))* SIZEOF(INT32));
for (i = 0; i <= MAXJSAMPLE; i++) {
rgb_gray_tab[i+R_Y_OFF] = FIX(0.29900) * i;
rgb_gray_tab[i+G_Y_OFF] = FIX(0.58700) * i;
rgb_gray_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
}
}
void
rgb_gray_convert (bmp_source_ptr sinfo,bmp_destination_ptr dinfo)
{
register int r, g, b;
register INT32 * ctab = sinfo->rgb_gray_tab;
register JSAMPROW inptr=sinfo->rgb_buffer;
register JSAMPROW outptr=dinfo->buffer;
register JDIMENSION col;
JDIMENSION num_cols = dinfo->image_width;
for (col = 0; col < num_cols; col++) {
r = (INT32)(inptr[0]);
g = (INT32)(inptr[1]);
b = (INT32)(inptr[2]);
inptr += 3;
/* Y */
outptr[col] = (JSAMPLE)
((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
>> SCALEBITS);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -