| 118 | } |
| 119 | |
| 120 | void _IMAGE_SHARED_API encodeJpeg(std::vector<uint8_t>& buffer, Image<ColorRgb>& inputImage, bool scaleDown) |
| 121 | { |
| 122 | const int aspect = (scaleDown) ? 2 : 1; |
| 123 | const int width = inputImage.width(); |
| 124 | const int height = inputImage.height() / aspect; |
| 125 | int pitch = width * sizeof(ColorRgb) * aspect; |
| 126 | int subSample = (scaleDown) ? TJSAMP_422 : TJSAMP_444; |
| 127 | int quality = 75; |
| 128 | |
| 129 | unsigned long compressedImageSize = 0; |
| 130 | unsigned char* compressedImage = NULL; |
| 131 | |
| 132 | tjhandle _jpegCompressor = tjInitCompress(); |
| 133 | |
| 134 | tjCompress2(_jpegCompressor, inputImage.rawMem(), width, pitch, height, TJPF_RGB, |
| 135 | &compressedImage, &compressedImageSize, subSample, quality, TJFLAG_FASTDCT); |
| 136 | |
| 137 | buffer.resize(compressedImageSize); |
| 138 | memcpy(buffer.data(), compressedImage, compressedImageSize); |
| 139 | |
| 140 | tjDestroy(_jpegCompressor); |
| 141 | tjFree(compressedImage); |
| 142 | } |
| 143 | |
| 144 | bool _IMAGE_SHARED_API savePng(const std::string& filename, const Image<ColorRgb>& image) |
| 145 | { |