Checksum-Code.txt
上传用户:gzsuper
上传日期:2020-05-06
资源大小:1k
文件大小:1k
源码类别:

Internet/网络编程

开发平台:

Unix_Linux

  1. // Checksum Generate for an array of chars//
  2. //Important Decleratiorn
  3. uint16_t image_array[2];
  4. image_array[0]=0;
  5. image_array[1]=0;
  6. //The Functions
  7. bool picture_compare (int width, int height, const unsigned char *pixels)
  8. // Get pixels array with size (height*width same as sizeof(pixels))
  9. // Return -> True - in case same as the last picture
  10. //      False - in case diff picture
  11. {
  12. image_array[1]=checksum16(pixels,sizeof (pixels),0);
  13. if (image_array[0]==image_array[1])
  14. return true;
  15. else
  16. {
  17. image_array[0]=image_array[1];
  18. return false;
  19. }
  20. }
  21. uint16_t checksum16(const void *buffer, size_t size, uint16_t start)
  22. // Create and Return the SUM of chars within the buffer
  23. {
  24.    uint16_t sum = 0;
  25.    const unsigned char *byte = buffer;
  26.    while ( size-- )
  27.    {
  28.       sum += *byte++;
  29.    }
  30.    return sum;
  31. }