@@ -1004,14 +1004,15 @@ static bool GetBool(const char s[], bool &rslt)
10041004static void StartReceivedMessage ();
10051005static void EndReceivedMessage ();
10061006static void ProcessReceivedValue (StringRef id, const char data[], const size_t indices[]);
1007+ static void ProcessArrayElementEnd (const char id[], const size_t index);
10071008static void ProcessArrayEnd (const char id[], const size_t indices[]);
10081009static void ParserErrorEncountered (int currentState, const char *, int errors);
10091010
10101011static struct SerialIo ::SerialIoCbs serial_cbs = {
10111012 .StartReceivedMessage = StartReceivedMessage,
10121013 .EndReceivedMessage = EndReceivedMessage,
10131014 .ProcessReceivedValue = ProcessReceivedValue,
1014- .ProcessArrayElementEnd = nullptr ,
1015+ .ProcessArrayElementEnd = ProcessArrayElementEnd ,
10151016 .ProcessArrayEnd = ProcessArrayEnd,
10161017 .ParserErrorEncountered = ParserErrorEncountered
10171018};
@@ -1023,10 +1024,10 @@ static void StartReceivedMessage()
10231024 FileManager::BeginNewMessage ();
10241025 currentAlert.Reset ();
10251026
1027+ thumbnailNew.Init ();
10261028 if (thumbnailCurrent.state == ThumbnailState::Init)
10271029 {
10281030 thumbnailCurrent.Init ();
1029- ThumbnailInit (thumbnailCurrent.thumbnail );
10301031 memset (&thumbnailData, 0 , sizeof (thumbnailData));
10311032 }
10321033}
@@ -1069,12 +1070,12 @@ static void EndReceivedMessage()
10691070 thumbnailCurrent.err );
10701071 thumbnailCurrent.state = ThumbnailState::Init;
10711072 }
1072- #if 0 // && DEBUG
1073+ #if DEBUG
10731074 if (thumbnailCurrent.thumbnail .imageFormat != Thumbnail::ImageFormat::Invalid)
10741075 {
10751076 dbg (" filename %s offset %d size %d format %d width %d height %d\n " ,
1076- thumbnailContext .filename.c_str(),
1077- thumbnailContext .offset, thumbnailContext .size,
1077+ thumbnailCurrent .filename .c_str (),
1078+ thumbnailCurrent .offset , thumbnailCurrent .size ,
10781079 thumbnailCurrent.thumbnail .imageFormat ,
10791080 thumbnailCurrent.thumbnail .width , thumbnailCurrent.thumbnail .height );
10801081 }
@@ -1977,7 +1978,7 @@ static void ProcessReceivedValue(StringRef id, const char data[], const size_t i
19771978 }
19781979 break ;
19791980 case rcvM36Filename:
1980- thumbnailCurrent .filename .copy (data);
1981+ thumbnailNew .filename .copy (data);
19811982 break ;
19821983
19831984 case rcvM36GeneratedBy:
@@ -2030,41 +2031,41 @@ static void ProcessReceivedValue(StringRef id, const char data[], const size_t i
20302031 break ;
20312032
20322033 case rcvM36ThumbnailsFormat:
2033- thumbnailCurrent .thumbnail .imageFormat = Thumbnail::ImageFormat::Invalid;
2034+ thumbnailNew .thumbnail .imageFormat = Thumbnail::ImageFormat::Invalid;
20342035 if (strcmp (data, " qoi" ) == 0 )
20352036 {
2036- thumbnailCurrent .thumbnail .imageFormat = Thumbnail::ImageFormat::Qoi;
2037+ thumbnailNew .thumbnail .imageFormat = Thumbnail::ImageFormat::Qoi;
20372038
2038- thumbnailCurrent .state = ThumbnailState::Header;
2039+ thumbnailNew .state = ThumbnailState::Header;
20392040 }
20402041 break ;
20412042 case rcvM36ThumbnailsHeight:
20422043 uint32_t height;
20432044 if (GetUnsignedInteger (data, height))
20442045 {
2045- thumbnailCurrent .thumbnail .height = height;
2046+ thumbnailNew .thumbnail .height = height;
20462047 }
20472048 break ;
20482049 case rcvM36ThumbnailsOffset:
20492050 uint32_t offset;
20502051 if (GetUnsignedInteger (data, offset))
20512052 {
2052- thumbnailCurrent .next = offset;
2053+ thumbnailNew .next = offset;
20532054 dbg (" receive initial offset %d.\n " , offset);
20542055 }
20552056 break ;
20562057 case rcvM36ThumbnailsSize:
20572058 uint32_t size;
20582059 if (GetUnsignedInteger (data, size))
20592060 {
2060- thumbnailCurrent .size = size;
2061+ thumbnailNew .size = size;
20612062 }
20622063 break ;
20632064 case rcvM36ThumbnailsWidth:
20642065 uint32_t width;
20652066 if (GetUnsignedInteger (data, width))
20662067 {
2067- thumbnailCurrent .thumbnail .width = width;
2068+ thumbnailNew .thumbnail .width = width;
20682069 }
20692070 break ;
20702071
@@ -2094,7 +2095,7 @@ static void ProcessReceivedValue(StringRef id, const char data[], const size_t i
20942095 dbg (" receive next offset %d.\n " , thumbnailCurrent.next );
20952096 break ;
20962097 case rcvM361ThumbnailOffset:
2097- if (!GetUnsignedInteger (data, thumbnailCurrent .offset ))
2098+ if (!GetUnsignedInteger (data, thumbnailNew .offset ))
20982099 {
20992100 thumbnailCurrent.parseErr = -4 ;
21002101 break ;
@@ -2133,6 +2134,26 @@ static void ProcessReceivedValue(StringRef id, const char data[], const size_t i
21332134 }
21342135}
21352136
2137+ static void ProcessArrayElementEnd (const char id[], const size_t index)
2138+ {
2139+ // dbg("id %s index %lu\r\n", id, index);
2140+
2141+ // check if new thumbnail fits better
2142+ if (strcmp (id, " thumbnails^" ) == 0 &&
2143+ ThumbnailIsValid (thumbnailNew.thumbnail ) &&
2144+ thumbnailCurrent.thumbnail .height < thumbnailNew.thumbnail .height &&
2145+ thumbnailNew.thumbnail .height <= fpThumbnail->GetHeight () &&
2146+ thumbnailCurrent.thumbnail .width < thumbnailNew.thumbnail .width &&
2147+ thumbnailNew.thumbnail .width <= fpThumbnail->GetWidth ())
2148+ {
2149+ dbg (" setting new thumbnail %d/%d\r\n " , fpThumbnail->GetWidth (), fpThumbnail->GetWidth ());
2150+ thumbnailCurrent = thumbnailNew;
2151+ thumbnailNew.Init ();
2152+ }
2153+
2154+ return ;
2155+ }
2156+
21362157// Public function called when the serial I/O module finishes receiving an array of values
21372158static void ProcessArrayEnd (const char id[], const size_t indices[])
21382159{
0 commit comments