-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathencode_minimal.c
36 lines (34 loc) · 1.14 KB
/
encode_minimal.c
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
// Minimal encoding sample.
#include <assert.h>
#include <libgpujpeg/gpujpeg_encoder.h>
#include <stdio.h>
#include <stdlib.h>
#define OUT_FNAME "out.jpg"
int
main()
{
struct gpujpeg_encoder *encoder = gpujpeg_encoder_create(0);
assert(encoder != NULL);
struct gpujpeg_parameters param;
gpujpeg_set_default_parameters(¶m);
struct gpujpeg_image_parameters param_image;
gpujpeg_image_set_default_parameters(¶m_image);
param_image.width = 640;
param_image.height = 480;
param_image.color_space = GPUJPEG_YCBCR_JPEG;
param_image.pixel_format = GPUJPEG_U8;
struct gpujpeg_encoder_input encoder_input;
uint8_t *blank_buffer =
calloc(1, gpujpeg_image_calculate_size(¶m_image));
gpujpeg_encoder_input_set_image(&encoder_input, blank_buffer);
uint8_t *out = NULL;
size_t len = 0;
gpujpeg_encoder_encode(encoder, ¶m, ¶m_image, &encoder_input, &out,
&len);
FILE *outf = fopen(OUT_FNAME, "wb");
fwrite(out, len, 1, outf);
printf("Ouput " OUT_FNAME " was written.\n");
fclose(outf);
free(blank_buffer);
gpujpeg_encoder_destroy(encoder);
}