javascript to generate crc code for thumbnails.

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
forumReader Offline
Junior Member
Posts: 3
Joined: Mar 2010
Reputation: 0
Post: #11
Found the error: (by reading in the xbmc:wiki)
the thumbnail is often generated by the folder name (if you use folder.jpg).
but in some cases the thumbnail is extra created for files to.
find quote
Nick8888 Offline
Fan
Posts: 716
Joined: Jan 2007
Reputation: 0
Post: #12
PHP Version - http://forum.xbmc.org/showthread.php?tid=85445
find quote
baderj Offline
Junior Member
Posts: 9
Joined: Feb 2012
Reputation: 0
Post: #13
forumReader Wrote:123456789 returns 376e6e7
should return:
0376e6e7

The function
Code:
CRC.toString(16);
doesn't do padding with leading zeros.

Here's the revised Code:
Code:
Number.prototype.unsign = function(bytes) {
    return this >= 0 ? this : Math.pow(256, bytes || 4) + this;
};

function FindCRC(data) {
    var CRC = 0xffffffff;
    data = data.toLowerCase();
    for ( var j = 0; j < data.length; j++) {
        var c = data.charCodeAt(j);
        CRC ^= c << 24;
        for ( var i = 0; i < 8; i++) {
            if (CRC.unsign(8) & 0x80000000) {
                CRC = (CRC << 1) ^ 0x04C11DB7;
            } else {
                CRC <<= 1;
            }
        }
    }
    if (CRC < 0)
        CRC = CRC >>> 0;
    var CRC_str = CRC.toString(16);
    while (CRC_str.length < 8) {
        CRC_str = '0' + CRC_str;
    }
    return CRC_str;
}
find quote
Post Reply