| 340 | |
| 341 | #ifndef SAVE_SPACE |
| 342 | uint8_t *g5Compress(uint16_t width, uint16_t height, uint8_t *buffer, uint16_t buffersize, uint16_t &outBufferSize) { |
| 343 | G5ENCIMAGE g5enc; |
| 344 | int rc; |
| 345 | uint8_t *outbuffer = (uint8_t *)ps_malloc(buffersize+16384); |
| 346 | if (outbuffer == NULL) { |
| 347 | Serial.println("Failed to allocate the output buffer for the G5 encoder"); |
| 348 | return nullptr; |
| 349 | } |
| 350 | |
| 351 | rc = g5_encode_init(&g5enc, width, height, outbuffer, buffersize); |
| 352 | for (int y = 0; y < height && rc == G5_SUCCESS; y++) { |
| 353 | rc = g5_encode_encodeLine(&g5enc, buffer); |
| 354 | buffer += (width / 8); |
| 355 | if (rc != G5_SUCCESS) break; |
| 356 | } |
| 357 | if (rc == G5_ENCODE_COMPLETE) { |
| 358 | outBufferSize = g5_encode_getOutSize(&g5enc); |
| 359 | } else { |
| 360 | printf("Encode failed! rc=%d\n", rc); |
| 361 | free(outbuffer); |
| 362 | return nullptr; |
| 363 | } |
| 364 | return outbuffer; |
| 365 | } |
| 366 | #endif |
| 367 | |
| 368 | // The "ts_option" is a bitmapped variable with a default value of 1 |