⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buffers.c

📁 傅立叶变换和小波变换是图像压缩的重要工具。该代大戏是利用小波变换进行图像压缩。
💻 C
字号:
#include "buffers.h"

#define ROWBUFFER_PAD	(2)

RowBuffer * RowBuffer_Create(int width,int numRows)
{
RowBuffer * tb;

	tb = new(*tb);

	RowBuffer_Init(tb,width,numRows);

return tb;
}

void RowBuffer_Init(RowBuffer * tb,int width,int numRows)
{
int i;
float * ptr;

	width += ROWBUFFER_PAD*2;

	tb->rowLen = width;
	tb->numRows = numRows;
	
	tb->rowMalloc = malloc( width * sizeof(float) * numRows );
	assert( tb->rowMalloc );

	ptr = tb->rowMalloc + ROWBUFFER_PAD;
	for(i=0;i<numRows;i++)
	{
		tb->rows[i] = ptr;
		ptr += width;
	}
	
	tb->rowCenter = tb->numRows;
}

void RowBuffer_Destroy(RowBuffer * tb)
{
	free( tb->rowMalloc );
	tb->rowMalloc = NULL;
	free( tb );
}

void RowBuffer_DeInit(RowBuffer * tb)
{
	free( tb->rowMalloc );
	tb->rowMalloc = NULL;
}

float * RowBuffer_Row(RowBuffer * tb, int i)
{
	assert( (i + tb->rowCenter) >= 0 );
return tb->rows[ (i + tb->rowCenter) % (tb->numRows) ];
}
float * RowBuffer_RawRow(RowBuffer * tb, int i)
{
	assert( i >= 0 );
return tb->rows[ (i) % (tb->numRows) ];
}

void RowBuffer_Clear(RowBuffer * rb,int width)
{
int i;	
	width += ROWBUFFER_PAD*2;
	assert( width <= rb->rowLen );
	for(i=0;i<(rb->numRows);i++)
	{
		memset( (rb->rows[i] - ROWBUFFER_PAD) , 0 , sizeof(float) * width);
	}
}

void PlaneBuffer_Copy(const PlaneBuffer * fm,PlaneBuffer * to)
{
float * toptr;
const float * fmptr;
int y;

	assert( to->width  == fm->width );
	assert( to->height == fm->height );

	fmptr = fm->plane;
	toptr = to->plane;

	for(y=0;y<(fm->height);y++)
	{
		memcpy(toptr,fmptr,sizeof(float)*(fm->width));
		fmptr += fm->stride;
		toptr += to->stride;
	}
}

void RowAbstract_Advance(RowAbstract *RA,int count)
{
	if ( RA->IsPlaneBuffer )
	{
		RA->PB.untransptr += RA->PB.stride * count;
	}
	else
	{
		RA->RB.rowCenter += count;
	}
}

float * RowAbstract_Row(RowAbstract *RA,int i)
{
	if ( RA->IsPlaneBuffer )
	{
		return (RA->PB.untransptr + i * RA->PB.stride);
	}
	else
	{
		return RowBuffer_Row( &(RA->RB),i );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -