Dana
2025-11-30 efda44a3808207db37921cf9237a8b7656352486
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// Created by YY on 2021/12/2.
//
 
#include <stdint.h>
#include <stdio.h>
#include <setjmp.h>
#include "jpeg.h"
#include "jpeglib.h"
#include "turbojpeg.h"
 
static tjhandle handle = NULL;
 
void init_JPEG_turbo(void)
{
    handle = tjInitDecompress();
}
 
void uninit_JPEG_turbo(void) {
    if (handle) {
        tjDestroy(handle);
        handle = NULL;
    }
}
 
void read_JPEG_turbo(const uint8_t *jpg, int length, uint8_t *rgba)
{
    int width, height, subsample, colorspace;
 
    tjDecompressHeader3(handle, jpg, length, &width, &height, &subsample, &colorspace);
 
    tjDecompress2(handle, jpg,    length, rgba,    width, 0, height, TJPF_RGBA,
                  TJFLAG_FASTDCT| TJFLAG_FASTUPSAMPLE);
}