Checksum-Code.txt
上传用户:gzsuper
上传日期:2020-05-06
资源大小:1k
文件大小:1k
- // Checksum Generate for an array of chars//
- //Important Decleratiorn
- uint16_t image_array[2];
- image_array[0]=0;
- image_array[1]=0;
- //The Functions
- bool picture_compare (int width, int height, const unsigned char *pixels)
- // Get pixels array with size (height*width same as sizeof(pixels))
- // Return -> True - in case same as the last picture
- // False - in case diff picture
- {
- image_array[1]=checksum16(pixels,sizeof (pixels),0);
- if (image_array[0]==image_array[1])
- return true;
- else
- {
- image_array[0]=image_array[1];
- return false;
- }
- }
- uint16_t checksum16(const void *buffer, size_t size, uint16_t start)
- // Create and Return the SUM of chars within the buffer
- {
- uint16_t sum = 0;
- const unsigned char *byte = buffer;
- while ( size-- )
- {
- sum += *byte++;
- }
- return sum;
- }