April 3th Tuesday (四月 三日 火曜日)

  I go on reading that source of LZ77.  Today I met another function.  Although there are comment,
I still manage my best to understand it.  Let's look at that function firstly.

void CopyBits(BYTE* memDest, int nDestPos,
       BYTE* memSrc, int nSrcPos, int nBits)
{
 int iByteDest = 0, iBitDest;
 int iByteSrc = 0, iBitSrc = nSrcPos;

 int nBitsToFill, nBitsCanFill;

 while (nBits > 0)
 {
  // get the number of bits need filling.
  nBitsToFill = min(nBits, iByteDest ? 8 : 8 - nDestPos);
  // get the index of those bits need filling.
  iBitDest = iByteDest ? 0 : nDestPos;

  // get how many bits can fill at a time
  nBitsCanFill = min(nBitsToFill, 8 - iBitSrc);

  // copy bits in a byte.
  CopyBitsInAByte(memDest + iByteDest, iBitDest,
   memSrc + iByteSrc, iBitSrc, nBitsCanFill);

  // fill remaining bits.
  if (nBitsToFill > nBitsCanFill)
  {
   iByteSrc++; iBitSrc = 0; iBitDest += nBitsCanFill;
   CopyBitsInAByte(memDest + iByteDest, iBitDest,
     memSrc + iByteSrc, iBitSrc,
     nBitsToFill - nBitsCanFill);
   iBitSrc += nBitsToFill - nBitsCanFill;
  }
  else
  {
   iBitSrc += nBitsCanFill;
   if (iBitSrc >= 8)
   {
    iByteSrc++; iBitSrc = 0;
   }
  }

  nBits -= nBitsToFill;
  iByteDest++;
 } 
}

  As a matter of fact, it is not hard to understand this function.  However, I made a mistake. I
ignored of the main body, and began to study statements line by line.  In addition, there are two
bad variable names as parameter -- "nDestPos", "nSrcPos".  They puzzled me long time.  In fact,
they are used to store the index of bits.  The function "CopyBitsInAByte()" mentioned yesterday
is used to copy bits in a byte.  Now there are more than one byte needed copying.  So, there is a
"while" loop statement.  "CopyBitsInAByte(memDest + iByteDest, iBitDest, memSrc + iByteSrc,
iBitSrc, nBitsCanFill);"  This statement copy some bits into a destination byte.  Perhaps, there
are some remaining.  "if (nBitsToFill > nBitsCanFill)" is used to check whether that case is.  If
yes, copy those remaining bits into the destination byte; otherwise, work out the next source byte
and its bit index.

  OK.  Let's look at those statement ahead of the loop body.  How to get the number of bits needed
filling.  "8 - nDestPos" can get how many bits is from the specified location to the end.  It means
the maximum  number of bits can fill.  However, real number of bits needed copying can be less than
the maximum.  So, the function "min()" is used to compute the real number.  If "iByteDest" is more
than 0, it means began to copying remaining bit in a new destination byte.  So, the maximum is 8.

  The "nBitsCanFill" represents how many bits can be copy in a dest byte.  The "8 - iBitSrc" means
how many bits wait copy in a source byte.  So, the value of "nBitsCanFill" must be a less number
between "8 - iBitSrc" and "nBitsToFill". 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数字图像处理是指使用计算机对数字图像进行处理和分析的技术。它包括对图像进行增强、恢复、去噪、压缩、分割和识别等操作。数字图像处理的主要目标是通过算法和技术改进图像质量,以便更好地满足人类视觉系统的需求。 在数字图像处理的第三版中,介绍了一些新的发展和进展。首先,该版本讨论了更多的图像增强技术,例如空域增强、频域增强和直方图均衡化。这些技术可以改善图像的亮度、对比度和清晰度,使得人们更容易观察和分析图像。 其次,该版本还加入了对图像压缩和编码的深入讨论。图像压缩是为了减少图像数据的存储和传输所占用的空间和时间。在这一版中,介绍了各种压缩算法,例如无损压缩和有损压缩。这些算法使得图像在保持较好质量的同时,能够更有效地传输和存储。 此外,该版本还包括了一些最新的图像分割和识别技术。图像分割是将图像划分为不同的区域或对象的过程,而图像识别是通过训练模型来辨别和分类图像中的对象。这些技术在计算机视觉、医学影像和安全监测等领域有着广泛的应用。 总之,数字图像处理的第三版是一个全面介绍了数字图像处理技术和应用的参考书籍。它不仅包括了基本的概念和原理,还介绍了一些最新的算法和技术。对于计算机科学、图像工程和人工智能领域的学生和专业人士来说,这本书是一个宝贵的资料和学习工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值