Results 1 to 15 of 15

Thread: Generate image checksum

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Qt products
    Qt4 Qt5
    Thanks
    98
    Thanked 3 Times in 3 Posts

    Default Re: Generate image checksum

    What is the maximum size of such pixmap?
    No maximum size.

    Is the checksum valid only during a single session or you want to keep it after user closes the application?
    Valid during a given session.

    Is it important for you that two exactly the same pixmaps that come from two different sources have the same checksum?
    Yes it is, it speeds up the display that I don't regenerate the pixmap.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: Generate image checksum

    I use md5 to check image stream or to stop connection param if the same as last..

    Qt Code:
    1. static inline QByteArray fastmd5( const QString xml )
    2. {
    3. QCryptographicHash formats( QCryptographicHash::Md5 );
    4. formats.addData(xml.toUtf8());
    5. return formats.result();
    6. }
    7.  
    8. static inline QByteArray fastmd5( const QByteArray xml )
    9. {
    10. QCryptographicHash formats( QCryptographicHash::Md5 );
    11. formats.addData(xml);
    12. return formats.result();
    13. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /* fill params */
    2. /* take qmenu from other layer edit or same as last? */
    3. void PageWindow::PlayOn()
    4. {
    5. TextLayer *iter = CurrentView->LayerModel();
    6. const int LayID = iter->data(ObjectNameEditor).toInt();
    7. const QString editable = LayID == 0 ? "no" : "yes";
    8. bool canedit = LayID == 0 ? false : true;
    9. const QString Pmyhash = QString("%1-%2-%3-%4-%5").arg(editable) /* can edit area */
    10. .arg(Clang) /* language */
    11. .arg(wdoc->ID()) /* document nr .*/
    12. .arg(LayID) /* layer nummer*/
    13. .arg(iter->textCursor().position()); /* cursor position */
    14. emit menupage(canedit,fastmd5(Pmyhash));
    15. }
    16.  
    17.  
    18. void Gui_Main::editor( bool e , const QByteArray hashpage )
    19. {
    20. if (LastHash == hashpage) {
    21. /* not make job ist the same edit status as last! */
    22. return;
    23. } else {
    24. LastHash = hashpage;
    25. }
    26. /* continue ok*/
    To copy to clipboard, switch view to plain text mode 



    My QImage cache work in this way to compose Multiple Animated Portable Network Graphics APNG... and all frame is unique...

    http://www.qt-apps.org/content/show....?content=82221


    Qt Code:
    1. class StreamFile
    2. {
    3. public:
    4. StreamFile()
    5. :d(new QBuffer())
    6. {
    7. d->open(QIODevice::ReadWrite);
    8. start();
    9. }
    10. ~StreamFile()
    11. {
    12. d->close();
    13. }
    14. bool clear()
    15. {
    16. d->write(QByteArray());
    17. return d->bytesAvailable() == 0 ? true : false;
    18. }
    19. void start() {
    20. d->seek(0);
    21. }
    22. bool LoadFile( const QString file ) {
    23. if (clear()) {
    24. QFile f(file);
    25. if (f.exists()) {
    26. if (f.open(QFile::ReadOnly)) {
    27. d->write(f.readAll());
    28. f.close();
    29. start();
    30. return true;
    31. }
    32. }
    33. }
    34. return false;
    35. }
    36. bool PutOnFile( const QString file ) {
    37. QFile f(file);
    38. if (f.open(QFile::WriteOnly)) {
    39. uint bi = f.write(d->readAll());
    40. start();
    41. return bi > 0 ? true : false;
    42. }
    43. return false;
    44. }
    45. QBuffer *device() { return d; }
    46. bool isValid() { return img.loadFromData(stream()); }
    47. QByteArray stream() { return d->data(); }
    48. QImage img;
    49. QBuffer *d;
    50. };
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to patrik08 for this useful post:

    bunjee (9th June 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Generate image checksum

    Quote Originally Posted by bunjee View Post
    Valid during a given session.
    Ok, so this reduces the chance of a collision.

    Quote Originally Posted by bunjee View Post
    No maximum size.
    [...]
    Yes it is, it speeds up the display that I don't regenerate the pixmap.
    But unfortunately these two make things worse.

    MD5 hashes have 128 bits, so a chance for a collision is quite low and they're of better quality than simple CRCs. The only problem is that they take more time to compute, but I don't think that it will be noticeable for the user if you compute them once per image.

Similar Threads

  1. Finding marks on scanned image for alignment
    By caduel in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2007, 02:10
  2. Explanation to Image Formats
    By sincnarf in forum Qt Programming
    Replies: 13
    Last Post: 6th July 2007, 17:02
  3. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  4. how i can add image in my toolbar
    By jyoti in forum Qt Tools
    Replies: 7
    Last Post: 19th December 2006, 14:39
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.