Wrong CRC calculation
#1
Hi all,

I am trying to develop a batch image thumbnail generator and I got stuck on hash calculation.

I took the C# sample source code from wiki and tested hashes I get from xbmc log:

Code:
Caching image 'smb://htpc:htpc@mediaserver/Documents/Media/Pictures/martina/DSC04128.JPG' as '7/7a8f2adb.JPG'

The actual xbmc cache is 7a8f2adb.
C# application returns cb785ff2.

Any ideas what am I missing?
Reply
#2
It may be that the code in the wiki is incorrect (though I'd be surprised). Basically we have a utf8 string, we lower case it (assuming ascii), and then crc32. There's a bunch of different ways to do crc32 (seed, methods etc.).

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
The wiki code for Hash calculation is OK, I've updated it some times ago to correct bugs.

The main problem is to find what XBMC will use to do the calculation Smile

And for image no luck they use another system Smile (Remark : half of the things for calculation are exception needing code reading to find :p )

Quote:CStdString CTextureCache::GetImageHash(const CStdString &url) const
299 {
300 struct __stat64 st;
301 if (CFile::Stat(url, &st) == 0)
302 {
303 int64_t time = st.st_mtime;
304 if (!time)
305 time = st.st_ctime;
306 if (time || st.st_size)
307 {
308 CStdString hash;
309 hash.Format("d%"PRId64"s%"PRId64, time, st.st_size);
310 return hash;
311 }
312 }
313 CLog::Log(LOGDEBUG, "%s - unable to stat url %s", __FUNCTION__, url.c_str());
314 return "";
315 }


Since i don't use image in my software i don't have c# equivalent but you should be able to convert.

The main problem will be to access the file to be able to stats the files Smile

You should check the Textures.db if you use a recent XBMC since it seems it contains the correct data.
Reply
#4
That is not the hash that you're looking for.

See the GetCacheFile or some such in the same .cpp.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#5
I think I understand how picture thumbnails are generated/cached/hashed:

It calculates crc32 from the url in format of:
thumb://<URLSAFE_path_to_image><URLSAFE_image_name>/<image_name>
URLSAFE means that all non letters&numbers ![a-zA-Z0-9] are converted to corresponding hex codes.

So my original example would become:
Code:
smb://htpc:htpc@mediaserver/Documents/Media/Pictures/martina/DSC04128.JPG
thumb://smb%3a%2f%2fhtpc%3ahtpc%40mediaserver%2fDocuments%2fMedia%2fPictures%2fmartina%2fDSC04128%2eJPG/DSC04128.JPG

I haven't found yet where exactly in code this is done, but I traced it now to (TextureCache.cpp) CTextureCache::CheckAndCacheImage()

The most helpful hint was to go check the Textures.db database, where you can see full url which was used for hashing.

Now I only need to find what does the image hash stand for in the texture table and then I think I will be able to develop batch image thumbnail generator.
Reply
#6
Unless you update the database, XBMC will re-cache those images either way.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#7
OK, imagehash is also solved, it takes the format d<seconds_since_epoch_of_file_modified>d<file_size_in_bytes>

@jmarshall: I have tons of pictures on network drive, and when browse to them it takes ages for my ATV to create&display thumbnails. So I decided, to make a batch procedure, which I'd run during the night and get all my thumbs ready to display.
Reply

Logout Mark Read Team Forum Stats Members Help
Wrong CRC calculation0