Browse Source

increase Snapmatic Max Capacity to 512 KB, support for pre May 2015

Snapmatic added
Syping 5 months ago
parent
commit
4c6962ab23
3 changed files with 31 additions and 24 deletions
  1. 4
    0
      .gitignore
  2. 25
    22
      SnapmaticPicture.cpp
  3. 2
    2
      main.cpp

+ 4
- 0
.gitignore View File

@@ -29,3 +29,7 @@
29 29
 
30 30
 # Qt project user file
31 31
 *.pro.user
32
+
33
+# Gettext translation files
34
+*.po
35
+*.pot

+ 25
- 22
SnapmaticPicture.cpp View File

@@ -44,6 +44,7 @@
44 44
 #define snapmaticUsefulLength 260
45 45
 #define snapmaticFileMaxSize 528192
46 46
 #define jpegHeaderLineDifStr 2
47
+#define jpegHeaderLineDifLim 8
47 48
 #define jpegPreHeaderLength 14
48 49
 #define jpegPicStreamLength 524288
49 50
 #define jsonStreamLength 3076
@@ -57,6 +58,9 @@
57 58
 #define titlStreamEditorLength 256
58 59
 #define titlStreamCharacterMax 39
59 60
 
61
+// LIMIT ALLOCATIONS
62
+#define jpegStreamLimitBegin 288
63
+
60 64
 // IMAGES VALUES
61 65
 #define snapmaticResolutionW 960
62 66
 #define snapmaticResolutionH 536
@@ -305,6 +309,12 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_, bo
305 309
         return false;
306 310
     }
307 311
 
312
+    // Get JPEG Size Limit
313
+    jpegHeaderLine.remove(0, jpegHeaderLineDifLim);
314
+    QString jpegHeaderLineStr = QString::fromUtf8(jpegHeaderLine.toHex().remove(8 - 2, 2));
315
+    QString hexadecimalStr = jpegHeaderLineStr.mid(4, 2) % jpegHeaderLineStr.mid(2, 2) % jpegHeaderLineStr.mid(0, 2);
316
+    jpegRawContentSize = hexadecimalStr.toInt(0, 16);
317
+
308 318
     // Read JPEG Stream
309 319
     if (!picStream->isReadable())
310 320
     {
@@ -314,18 +324,6 @@ bool SnapmaticPicture::readingPicture(bool writeEnabled_, bool cacheEnabled_, bo
314 324
         return false;
315 325
     }
316 326
     QByteArray jpegRawContent = picStream->read(jpegPicStreamLength);
317
-    if (jpegRawContent.contains("\xFF\xD9"))
318
-    {
319
-        int jpegRawContentSizeT = jpegRawContent.indexOf("\xFF\xD9") + 2;
320
-        jpegRawContentSizeE = jpegRawContentSizeT;
321
-        jpegRawContentSize = jpegRawContentSizeT;
322
-        if (jpegRawContent.contains("\xFF\x45\x4F\x49"))
323
-        {
324
-            jpegRawContentSizeT = jpegRawContent.indexOf("\xFF\x45\x4F\x49");
325
-        }
326
-        jpegRawContent = jpegRawContent.left(jpegRawContentSize);
327
-        jpegRawContentSize = jpegRawContentSizeT;
328
-    }
329 327
     if (cacheEnabled) picOk = cachePicture.loadFromData(jpegRawContent, "JPEG");
330 328
     if (!cacheEnabled)
331 329
     {
@@ -507,7 +505,7 @@ bool SnapmaticPicture::setImage(const QImage &picture)
507 505
             picStreamT.close();
508 506
             if (saveSuccess)
509 507
             {
510
-                if (picByteArrayT.length() > jpegRawContentSize)
508
+                if (picByteArrayT.length() > jpegPicStreamLength)
511 509
                 {
512 510
                     comLvl--;
513 511
                     saveSuccess = false;
@@ -527,29 +525,34 @@ bool SnapmaticPicture::setPictureStream(const QByteArray &streamArray) // clean
527 525
 {
528 526
     if (writeEnabled)
529 527
     {
530
-        bool customEOI = false;
531 528
         QByteArray picByteArray = streamArray;
532 529
         if (lowRamMode) { rawPicContent = qUncompress(rawPicContent); }
533 530
         QBuffer snapmaticStream(&rawPicContent);
534 531
         snapmaticStream.open(QIODevice::ReadWrite);
535 532
         if (!snapmaticStream.seek(jpegStreamEditorBegin)) return false;
536 533
         if (picByteArray.length() > jpegPicStreamLength) return false;
537
-        if (picByteArray.length() < jpegRawContentSize && jpegRawContentSize + 4 < jpegPicStreamLength)
538
-        {
539
-            customEOI = true;
540
-        }
541 534
         while (picByteArray.length() != jpegPicStreamLength)
542 535
         {
543 536
             picByteArray += '\x00';
544 537
         }
545
-        if (customEOI)
538
+        int result = snapmaticStream.write(picByteArray);
539
+        QString hexadecimalStr;
540
+        hexadecimalStr.setNum(streamArray.length(), 16);
541
+        while (hexadecimalStr.length() != 6)
546 542
         {
547
-            picByteArray.replace(jpegRawContentSize, 4, "\xFF\x45\x4F\x49");
543
+            hexadecimalStr.prepend('0');
544
+        }
545
+        hexadecimalStr = hexadecimalStr.mid(4, 2) % hexadecimalStr.mid(2, 2) % hexadecimalStr.mid(0, 2);
546
+        bool updatedRawContentSize = false;
547
+        if (snapmaticStream.seek(jpegStreamLimitBegin))
548
+        {
549
+            snapmaticStream.write(QByteArray::fromHex(hexadecimalStr.toUtf8()));
550
+            updatedRawContentSize = true;
548 551
         }
549
-        int result = snapmaticStream.write(picByteArray);
550 552
         snapmaticStream.close();
551 553
         if (result != 0)
552 554
         {
555
+            if (updatedRawContentSize) { jpegRawContentSize = streamArray.length(); }
553 556
             if (cacheEnabled)
554 557
             {
555 558
                 QImage replacedPicture;
@@ -1031,7 +1034,7 @@ void SnapmaticPicture::parseJsonContent()
1031 1034
         if (jsonObject["rsedtr"].isBool()) { localProperties.isFromRSEditor = jsonObject["rsedtr"].toBool(); }
1032 1035
         else { jsonError = true; }
1033 1036
     }
1034
-    else { jsonIncomplete = true; }
1037
+    // else { jsonIncomplete = true; } // Game release Snapmatic pictures prior May 2015 left out rsedtr, so don't force exists on that one
1035 1038
 
1036 1039
     if (!jsonIncomplete && !jsonError)
1037 1040
     {

+ 2
- 2
main.cpp View File

@@ -70,6 +70,8 @@ int main(int argc, char *argv[])
70 70
     a.setApplicationVersion(GTA5SYNC_APPVER);
71 71
     a.setQuitOnLastWindowClosed(false);
72 72
 
73
+    QResource::registerResource(":/global/global.rcc");
74
+
73 75
     QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
74 76
     settings.beginGroup("Startup");
75 77
 
@@ -292,8 +294,6 @@ int main(int argc, char *argv[])
292 294
     QObject::connect(&threadDB, SIGNAL(finished()), &a, SLOT(quit()));
293 295
     threadDB.start();
294 296
 
295
-    QResource::registerResource(":/global/global.rcc");
296
-
297 297
     UserInterface uiWindow(&profileDB, &crewDB, &threadDB);
298 298
     uiWindow.setWindowIcon(IconLoader::loadingAppIcon());
299 299
     uiWindow.setupDirEnv();