aboutsummaryrefslogtreecommitdiffstats
path: root/src/jpeg.c
blob: cdcae7b19e8052a3f55767a5d0bbc69c2eaed15c (plain) (blame)
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
35
36
37
/*
 * Copyright (c) 2020-2022, yzrh <yzrh@noema.org>
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <stdio.h>

#include <jpeglib.h>

int
strinfo_jpeg_dim(int *jpeg_width, int *jpeg_height, int *jpeg_components,
	const char * restrict data, int data_size)
{
	struct jpeg_decompress_struct cinfo;
	struct jpeg_error_mgr jerr;

	cinfo.err = jpeg_std_error(&jerr);

	jpeg_create_decompress(&cinfo);

	jpeg_mem_src(&cinfo, (unsigned char *) data, data_size);

	jpeg_read_header(&cinfo, TRUE);

	jpeg_calc_output_dimensions(&cinfo);

	*jpeg_width = cinfo.output_width;
	*jpeg_height = cinfo.output_height;
	*jpeg_components = cinfo.output_components;

	jpeg_destroy((struct jpeg_common_struct *) &cinfo);

	jpeg_destroy_decompress(&cinfo);

	return 0;
}