MCPcopy Create free account
hub / github.com/Blueforcer/awtrix3 / jd_input

Method jd_input

lib/TJpg_Decoder/src/TJpg_Decoder.cpp:82–149  ·  view source on GitHub ↗

** Function name: jd_input (declared static) ** Description: Called by tjpgd.c to get more data ***************************************************************************************/

Source from the content-addressed store, hash-verified

80** Description: Called by tjpgd.c to get more data
81***************************************************************************************/
82unsigned int TJpg_Decoder::jd_input(JDEC *jdec, uint8_t *buf, unsigned int len)
83{
84 TJpg_Decoder *thisPtr = TJpgDec.thisPtr;
85 jdec = jdec; // Supress warning
86
87 // Handle an array input
88 if (thisPtr->jpg_source == TJPG_ARRAY)
89 {
90 // Avoid running off end of array
91 if (thisPtr->array_index + len > thisPtr->array_size)
92 {
93 len = thisPtr->array_size - thisPtr->array_index;
94 }
95
96 // If buf is valid then copy len bytes to buffer
97 if (buf)
98 memcpy_P(buf, (const uint8_t *)(thisPtr->array_data + thisPtr->array_index), len);
99
100 // Move pointer
101 thisPtr->array_index += len;
102 }
103
104#ifdef TJPGD_LOAD_FFS
105 // Handle SPIFFS input
106 else if (thisPtr->jpg_source == TJPG_FS_FILE)
107 {
108 // Check how many bytes are available
109 uint32_t bytesLeft = thisPtr->jpgFile.available();
110 if (bytesLeft < len)
111 len = bytesLeft;
112
113 if (buf)
114 {
115 // Read into buffer, pointer moved as well
116 thisPtr->jpgFile.read(buf, len);
117 }
118 else
119 {
120 // Buffer is null, so skip data by moving pointer
121 thisPtr->jpgFile.seek(thisPtr->jpgFile.position() + len);
122 }
123 }
124#endif
125
126#if defined(TJPGD_LOAD_SD_LIBRARY)
127 // Handle SD library input
128 else if (thisPtr->jpg_source == TJPG_SD_FILE)
129 {
130 // Check how many bytes are available
131 uint32_t bytesLeft = thisPtr->jpgSdFile.available();
132 if (bytesLeft < len)
133 len = bytesLeft;
134
135 if (buf)
136 {
137 // Read into buffer, pointer moved as well
138 thisPtr->jpgSdFile.read(buf, len);
139 }

Callers

nothing calls this directly

Calls 1

readMethod · 0.80

Tested by

no test coverage detected