jdcenc.m

来自「JPEG图像压缩及解压 适用于MATLAB」· M 代码 · 共 64 行

M
64
字号
function b=jdcenc(x)% Usage: b=jdcenc(x)% Hoffman encoding of DC coefficients in JPEG% copyright(c) 1997 by Yu Hen Hu%% category c = floor(log2(abs(x)))+1% append code is the binary representation of abs(x) if x>0% of the 1's complement of bianry rep of abs(x) if x < 0% created: 11/25/97% first figure out category numberif x ==0,   %b=[0 1 0];   b=[0 0];   return % doneelse   c = floor(log2(abs(x)))+1;end% Hoffman tabletbl=[3 0 1 0 0 0 0 0 0 0     3 0 1 1 0 0 0 0 0 0     3 1 0 0 0 0 0 0 0 0     2 0 0 0 0 0 0 0 0 0     3 1 0 1 0 0 0 0 0 0     5 1 1 0 0 0 0 0 0 0     4 1 1 1 0 0 0 0 0 0     5 1 1 1 1 0 0 0 0 0     6 1 1 1 1 1 0 0 0 0     7 1 1 1 1 1 1 0 0 0     8 1 1 1 1 1 1 1 0 0     9 1 1 1 1 1 1 1 1 0];  % This table is in the pdf file, print out taken % Modified 27 sept 2003, 2325 Hrs tab=[2 0 0 0 0 0 0 0 0 0     3 0 1 0 0 0 0 0 0 0     3 0 1 1 0 0 0 0 0 0     3 1 0 0 0 0 0 0 0 0     3 1 0 1 0 0 0 0 0 0     3 1 1 0 0 0 0 0 0 0     4 1 1 1 0 0 0 0 0 0     5 1 1 1 1 0 0 0 0 0     6 1 1 1 1 1 0 0 0 0     7 1 1 1 1 1 1 0 0 0     8 1 1 1 1 1 1 1 0 0     9 1 1 1 1 1 1 1 1 0];  tbl=tab; % This is changed by Ravi Lakkundib=tbl(c+1,2:tbl(c+1,1)+1);tmp=int2bin(x,c);  % tmp is 1 by c+1 vector containing sign-mag% representation of x, first bit is sign bit.if tmp(1)==0, % if x > 0   b=[b tmp(2:c+1)];elseif tmp(1)==1, % if x < 0   b=[b ones(1,c)-tmp(2:c+1)];end

⌨️ 快捷键说明

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