【图像处理高级编程】-基于小波的JPEG2000压缩

基于小波的JPEG2000压缩

提示:这里可以添加技术概要

请添加图片描述

核心源码

var
FormWavelet: TFormWavelet;

procedure wv_progress(Current, Maximum: Integer; UserData: Pointer); cdecl;

implementation

procedure wv_progress(Current, Maximum: Integer; UserData: Pointer); cdecl;
var
pr: PProgressRecord;
ofs: Integer;
begin
if (UserData <> nil) then
begin
pr := PProgressRecord(UserData);
ofs := (pr^.CurChannel * pr^.Bar.Max) div pr^.MaxChannel;
pr^.Bar.Position := ofs + (Current * pr^.Bar.Max) div (pr^.MaxChannel *
Maximum);
FormWavelet.Update();
Application.ProcessMessages();
end;
end;

{$R *.DFM}

procedure TFormWavelet.ButtonLoadClick(Sender: TObject);
begin
if (((NumChannels + 1 <= wv_MAX_CHANNELS) and CheckBoxGreyScale.Checked) or
((NumChannels + 3 <= wv_MAX_CHANNELS) and not CheckBoxGreyScale.Checked))
then
begin
if (OpenDialog1.Execute()) then
//开始加载图片
LoadSourceImage(OpenDialog1.FileName, CheckBoxGreyScale.Checked,
CheckBoxYCbCr.Checked);
end
else
//出错提示
MessageDlg(‘Not enough free channels!’, mtError, [mbOK], 0);
end;

procedure TFormWavelet.FormCreate(Sender: TObject);
var
tf: TFormImage;
i: Integer;
begin
for i := 0 to wv_MAX_CHANNELS - 1 do
with Channels[i] do
begin
Data := nil;
CData := nil;
Channel := nil;
end;
ImageWidth := 0;
ImageHeight := 0;
NumChannels := 0;
NumBlocks := 0;
ReorderTable := nil;
FormImage := TFormImage.Create(self);
FormImage.Caption := ‘Original Image’;
FormCImage := TFormImage.Create(self);
FormCImage.Caption := ‘Compressed Image’;

MaxSizeTrack := TrackBarSizeBPP.Max;
TrackBarSizeBPPChange(TrackBarSizeBPP);
TrackBarDeltaMSEChange(TrackBarDeltaMSE);
TrackBarPSNRChange(TrackBarPSNR);

// get size of scrollbars
tf := TFormImage.Create(self);
tf.Image.Width := 100;
tf.Image.Height := 100;
tf.FormStyle := fsNormal;
tf.AutoSize := true;
tf.Image.Stretch := true;

tf.ClientWidth := 10;
tf.ClientHeight := 10;
ScrollBarX := tf.Width - tf.ClientWidth;
ScrollBarY := tf.Height - tf.ClientHeight;
tf.Free();
end;

procedure TFormWavelet.FormDestroy(Sender: TObject);
var
i: Integer;
begin
if (FormImage <> nil) then
FormImage.Free();
if (FormCImage <> nil) then
FormCImage.Free();
for i := 0 to NumChannels - 1 do
with Channels[i] do
begin
if (Data <> nil) then
FreeMem(Data);
if (CData <> nil) then
FreeMem(CData);
if (Channel <> nil) then
wv_done_channel(Channel, Integer(i = 0));
end;
end;

procedure TFormWavelet.EnableUI();
begin
ButtonKompress.Enabled := NumChannels > 0;
ButtonLoad.Enabled := NumChannels < wv_MAX_CHANNELS;
ButtonClear.Enabled := True;
end;

procedure TFormWavelet.DisableUI();
begin
ButtonKompress.Enabled := False;
ButtonLoad.Enabled := False;
ButtonClear.Enabled := False;
end;

function TFormWavelet.GetBitmapChannel(NWidth, NHeight: Integer; Channel:
Integer; SourceImage: TBitmap): pawv_pel;
var
x, y: Integer;
row: PByteArray;
Data: pawv_pel;
begin
GetMem(Data, NHeight * NWidth * SizeOf(wv_pel));
for y := 0 to SourceImage.Height - 1 do
begin
row := SourceImage.ScanLine[y];
case (Channel) of
-1: for x := 0 to SourceImage.Width - 1 do
Data[y * NWidth + x] := (Integer(row[x * 3 + ofs_R]) * 19595 +
Integer(row[x * 3 + ofs_G]) * 38470 + Integer(row[x * 3 +
ofs_B]) *
7471 + 32768) shr 16;
0: for x := 0 to SourceImage.Width - 1 do
Data[y * NWidth + x] := row[x * 3 + 2]; // red
1: for x := 0 to SourceImage.Width - 1 do
Data[y * NWidth + x] := row[x * 3 + 1]; // green
2: for x := 0 to SourceImage.Width - 1 do
Data[y * NWidth + x] := row[x * 3 + 0]; // blue
end;
end;
// extend the channel, so that we don’t have ugly discontinuities
for y := 0 to SourceImage.Height - 1 do
for x := SourceImage.Width to NWidth - 1 do
Data[y * NWidth + x] := Data[y * NWidth + SourceImage.Width - 1];
for y := SourceImage.Height to NHeight - 1 do
Move(Data[(SourceImage.Height - 1) * NWidth], Data[y * NWidth],
SizeOf(wv_pel) * NWidth);
Result := Data;
end;

procedure TFormWavelet.ApplySettings(t: TSettingsSet; var c: TChannel);
//设置应用
begin
if (SMaxMSE in t) then
begin
if (TrackBarPSNR.Position = TrackBarPSNR.Min) then //如果处于最小位置
c.max_mse := 0.0 //强行置为0.0
else
c.max_mse := psnr_to_mse((TrackBarPSNR.Max - TrackBarPSNR.Position) /
TrackBarPSNR.PageSize); //将psnr(峰值信噪比)转换成mse(均方误差)
end;
if (SDeltaMSE in t) then
begin
c.delta_mse := (TrackBarDeltaMSE.Position - TrackBarDeltaMSE.Max div 2) /
1000.0;
end;
end;

procedure TFormWavelet.LoadSourceImage(const Name: TFileName; Greyscale, YCbCr:
Boolean);
const
//wv_MAX_CHANNELS=16;
channel_names: array[False…True, 0…wv_MAX_CHANNELS - 1] of string = ((‘R’,
‘G’, ‘B’, ‘A’, ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’,
‘11’),
(‘Y’, ‘Cb’, ‘Cr’, ‘A’, ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’,
‘10’, ‘11’));
var<

  • 23
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大龙软件研发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值