| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#include <stdio.h> |
|---|
| 20 |
#include <stdlib.h> |
|---|
| 21 |
|
|---|
| 22 |
#include "cc3.h" |
|---|
| 23 |
#include "cc3_jpg.h" |
|---|
| 24 |
#include <jpeglib.h> |
|---|
| 25 |
|
|---|
| 26 |
typedef struct { |
|---|
| 27 |
struct jpeg_compress_struct cinfo; |
|---|
| 28 |
struct jpeg_error_mgr jerr; |
|---|
| 29 |
} cc3_jpeg_t; |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
static void destroy_jpeg(cc3_jpeg_t *cj); |
|---|
| 33 |
static cc3_jpeg_t *init_jpeg (void); |
|---|
| 34 |
static void capture_current_jpeg(cc3_jpeg_t *cj, FILE *f); |
|---|
| 35 |
|
|---|
| 36 |
void cc3_jpeg_send_simple(void) { |
|---|
| 37 |
|
|---|
| 38 |
cc3_pixbuf_load(); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
cc3_jpeg_t *cj = init_jpeg(); |
|---|
| 42 |
|
|---|
| 43 |
capture_current_jpeg(cj, stdout); |
|---|
| 44 |
|
|---|
| 45 |
destroy_jpeg(cj); |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
static cc3_jpeg_t *init_jpeg(void) { |
|---|
| 51 |
cc3_jpeg_t *cj = malloc(sizeof(cc3_jpeg_t)); |
|---|
| 52 |
if (cj == NULL) { |
|---|
| 53 |
return NULL; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
cj->cinfo.err = jpeg_std_error(&cj->jerr); |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
jpeg_create_compress(&cj->cinfo); |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
cj->cinfo.image_width = cc3_g_pixbuf_frame.width; |
|---|
| 64 |
cj->cinfo.image_height = cc3_g_pixbuf_frame.height; |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
cj->cinfo.input_components = 3; |
|---|
| 68 |
|
|---|
| 69 |
cj->cinfo.in_color_space = JCS_RGB; |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
jpeg_set_defaults(&cj->cinfo); |
|---|
| 73 |
jpeg_set_quality(&cj->cinfo, 85, true); |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
return cj; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
static void capture_current_jpeg(cc3_jpeg_t *cj, FILE *f) { |
|---|
| 80 |
JSAMPROW row_pointer[1]; |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
row_pointer[0] = cc3_malloc_rows(1); |
|---|
| 84 |
if (row_pointer[0] == NULL) { |
|---|
| 85 |
return; |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
jpeg_stdio_dest(&cj->cinfo, f); |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
jpeg_start_compress(&cj->cinfo, TRUE); |
|---|
| 93 |
while (cj->cinfo.next_scanline < cj->cinfo.image_height) { |
|---|
| 94 |
cc3_pixbuf_read_rows(row_pointer[0], 1); |
|---|
| 95 |
jpeg_write_scanlines(&cj->cinfo, row_pointer, 1); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
jpeg_finish_compress(&cj->cinfo); |
|---|
| 100 |
|
|---|
| 101 |
free(row_pointer[0]); |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
static void destroy_jpeg(cc3_jpeg_t *cj) { |
|---|
| 106 |
jpeg_destroy_compress(&cj->cinfo); |
|---|
| 107 |
free(cj); |
|---|
| 108 |
} |
|---|