📄 gif_smooth.c
字号:
//----------------------------------------------------------------------
// File Name : giflzw.c
// Project : gif_smooth.c
// Module :
// Memo :
// Author Date Description
// -----------------------------------------------
// dts 2004.3.10
//
//----------------------------------------------------------------------
#include "gif_read.h"
#include "gif_error.h"
int Template_Smooth_Gauss[9]={1,2,1,2,4,2,1,2,1};
//====================================================================================
// Function Name: void smooth (decompress_info_ptr cinfo, uchar* input_data, uchar* output_data_ptr)
// Purpose : smooth/ the function only can be used when data saved by ycbcr(2:1) rgb
// data is not suitable
// Parameter :
// Return : none
// Remarks :
// Change Log :
// Author Date Description
// -----------------------------------------------
//=====================================================================================
void smooth (decompress_info_ptr cinfo, uchar* input_data, uchar* output_data_ptr)
{
uchar* output_data = output_data_ptr;
register JSAMPROW inptr0, inptr1, outptr;
#if BITS_IN_JSAMPLE == 8
register int thiscolsum, lastcolsum, nextcolsum;
#else
register INT32 thiscolsum, lastcolsum, nextcolsum;
#endif
register JDIMENSION colctr;
int inrow, v;
uint outrow;
int ci;
for(ci = 0; ci < cinfo->out_color_components; ci ++)
{
inrow = outrow = 0;
while (outrow < cinfo->output_height -1)
{
for (v = 0; v < 2; v++)
{
/* inptr0 points to nearest input row, inptr1 points to next nearest */
inptr0 = (uchar*)(input_data + inrow * 3 * cinfo->output_width +ci);
if (v == 0) /* next nearest is row above */
{
inptr1 = (uchar*)(input_data + (inrow-1) * 3 * cinfo->output_width +ci);
}
else /* next nearest is row below */
{
inptr1 = (uchar*)(input_data + (inrow+1) * 3 * cinfo->output_width + ci);
}
outptr =(uchar*)( output_data + outrow * 3 * cinfo->output_width + ci);
outrow += 1;
// outptr = output_data[outrow++];
/* Special case for first column */
thiscolsum = GETJSAMPLE(*inptr0) * 3 + GETJSAMPLE(*inptr1);
inptr0 += 3;
inptr1 += 3;
nextcolsum = GETJSAMPLE(*inptr0) * 3 + GETJSAMPLE(*inptr1);
inptr0 += 3;
inptr1 += 3;
*outptr = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
outptr += 3;
*outptr = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
outptr += 3;
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
for (colctr = cinfo->output_width - 2; colctr > 0; colctr--)
{
/* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
/* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
nextcolsum = GETJSAMPLE(*inptr0) * 3 + GETJSAMPLE(*inptr1);
inptr0 += 3;
inptr1 += 3;
*outptr = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
outptr += 3;
*outptr = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
outptr += 3;
lastcolsum = thiscolsum; thiscolsum = nextcolsum;
}
/* Special case for last column */
*outptr = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
outptr += 3;
*outptr = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
outptr += 3;
}
inrow++;
}
}
}
//====================================================================================
// Function Name: void smooth_guess (decompress_info_ptr cinfo, uchar* input_data, uchar* output_data_ptr)
// Purpose : smooth/ the function only can be used when data saved by rgb
// Parameter :
// Return : none
// Remarks :
// Change Log :
// Author Date Description
// -----------------------------------------------
//=====================================================================================
void smooth_guess (decompress_info_ptr cinfo, uchar* input_data, uchar* output_data_ptr)
{
int TempNum;
uint y, x, ci;
register JSAMPROW inptr, outptr;
for(ci = 0; ci < (uint)(cinfo->out_color_components); ci ++)
{
for( y = 1; y < cinfo->output_height - 1; y++ )
{
for( x = 1; x < cinfo->output_width - 1; x++ )
{
inptr = (uchar*)( input_data + y * 3 * cinfo->output_width +ci + x * 3);
outptr = (uchar*)(output_data_ptr + y * 3 * cinfo->output_width +ci + x * 3);
TempNum=(int)((unsigned char)*(inptr + cinfo->output_width * 3 -3))*Template_Smooth_Gauss[0];
TempNum+=(int)((unsigned char)*(inptr + cinfo->output_width * 3))*Template_Smooth_Gauss[1];
TempNum+=(int)((unsigned char)*(inptr + cinfo->output_width * 3+3))*Template_Smooth_Gauss[2];
TempNum+=(int)((unsigned char)*(inptr -3))*Template_Smooth_Gauss[3];
TempNum+=(int)((unsigned char)*inptr)*Template_Smooth_Gauss[4];
TempNum+=(int)((unsigned char)*(inptr +3))*Template_Smooth_Gauss[5];
TempNum+=(int)((unsigned char)*(inptr - cinfo->output_width * 3 -3))*Template_Smooth_Gauss[6];
TempNum+=(int)((unsigned char)*(inptr - cinfo->output_width * 3))*Template_Smooth_Gauss[7];
TempNum+=(int)((unsigned char)*(inptr - cinfo->output_width * 3 + 3))*Template_Smooth_Gauss[8];
TempNum >>= 4;
if(TempNum>255)
{
*outptr=255;
}
else if(TempNum<0)
{
*outptr= -TempNum;
}
else
{
*outptr=(uchar)TempNum;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -