Mercurial > mplayer.hg
annotate TOOLS/mwallp/jpeg.c @ 11861:fcaf4c2ca9e1
sync
author | nicolas |
---|---|
date | Tue, 27 Jan 2004 17:10:30 +0000 |
parents | 3a6ae4199f67 |
children | 6bd869a18d2c |
rev | line source |
---|---|
6457
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
1 // based on vd_ijpg.c by Pontscho |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
2 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
3 #include <stdio.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
4 #include <stdlib.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
5 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
6 #include <jpeglib.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
7 #define UINT16 IJPG_UINT16 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
8 #define INT16 IJPG_INT16 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
9 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
10 #include <setjmp.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
11 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
12 #include <inttypes.h> |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
13 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
14 #include "img_format.h" |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
15 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
16 #include "swscale.h" |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
17 #include "rgb2rgb.h" |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
18 |
9500 | 19 static struct SwsContext *swsContext=NULL; |
6457
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
20 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
21 typedef struct |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
22 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
23 struct jpeg_source_mgr pub; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
24 unsigned char * inbuf; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
25 int bufsize; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
26 } my_source_mgr; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
27 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
28 typedef my_source_mgr * my_src_ptr; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
29 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
30 METHODDEF(void) init_source (j_decompress_ptr cinfo) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
31 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
32 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
33 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
34 METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
35 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
36 my_src_ptr src = (my_src_ptr) cinfo->src; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
37 size_t nbytes; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
38 src->pub.next_input_byte = src->inbuf; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
39 src->pub.bytes_in_buffer = src->bufsize; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
40 return TRUE; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
41 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
42 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
43 METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
44 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
45 my_src_ptr src = (my_src_ptr) cinfo->src; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
46 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
47 if (num_bytes > 0) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
48 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
49 while (num_bytes > (long) src->pub.bytes_in_buffer) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
50 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
51 num_bytes -= (long) src->pub.bytes_in_buffer; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
52 (void) fill_input_buffer(cinfo); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
53 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
54 src->pub.next_input_byte += (size_t) num_bytes; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
55 src->pub.bytes_in_buffer -= (size_t) num_bytes; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
56 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
57 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
58 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
59 METHODDEF(void) term_source (j_decompress_ptr cinfo) { } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
60 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
61 GLOBAL(void) jpeg_buf_src ( j_decompress_ptr cinfo, char * inbuf,int bufsize ) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
62 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
63 my_src_ptr src; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
64 if (cinfo->src == NULL) cinfo->src=malloc( sizeof( my_source_mgr ) ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
65 src = (my_src_ptr) cinfo->src; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
66 src->pub.init_source = init_source; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
67 src->pub.fill_input_buffer = fill_input_buffer; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
68 src->pub.skip_input_data = skip_input_data; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
69 src->pub.resync_to_restart = jpeg_resync_to_restart; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
70 src->pub.term_source = term_source; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
71 src->inbuf = inbuf; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
72 src->bufsize=bufsize; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
73 src->pub.bytes_in_buffer = 0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
74 src->pub.next_input_byte = NULL; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
75 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
76 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
77 struct my_error_mgr |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
78 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
79 struct jpeg_error_mgr pub; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
80 jmp_buf setjmp_buffer; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
81 }; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
82 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
83 typedef struct my_error_mgr * my_error_ptr; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
84 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
85 METHODDEF(void) my_error_exit (j_common_ptr cinfo) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
86 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
87 my_error_ptr myerr=(my_error_ptr) cinfo->err; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
88 (*cinfo->err->output_message) (cinfo); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
89 longjmp(myerr->setjmp_buffer, 1); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
90 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
91 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
92 static struct jpeg_decompress_struct cinfo; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
93 static struct my_error_mgr jerr; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
94 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
95 // decode a frame |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
96 int decode_jpeg(void* data,int len,char* dbuffer,int dwidth,int dheight, int dstride,int dbpp){ |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
97 int width,height,depth,i; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
98 int row_stride; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
99 unsigned char* img=NULL; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
100 int in_fmt=0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
101 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
102 if ( len <= 0 ) return 0; // skipped frame |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
103 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
104 cinfo.err=jpeg_std_error( &jerr.pub ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
105 jerr.pub.error_exit=my_error_exit; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
106 if( setjmp( jerr.setjmp_buffer ) ) |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
107 { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
108 return 0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
109 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
110 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
111 jpeg_create_decompress( &cinfo ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
112 jpeg_buf_src( &cinfo,data,len ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
113 jpeg_read_header( &cinfo,TRUE ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
114 width=cinfo.image_width; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
115 height=cinfo.image_height; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
116 jpeg_start_decompress( &cinfo ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
117 depth=cinfo.output_components * 8; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
118 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
119 switch( depth ) { |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
120 case 8: in_fmt=IMGFMT_Y8;break; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
121 case 24: in_fmt=IMGFMT_RGB|24;break; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
122 default: return 0; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
123 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
124 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
125 row_stride=cinfo.output_width * cinfo.output_components; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
126 img=malloc(row_stride * (height+1)); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
127 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
128 for ( i=0;i < height;i++ ){ |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
129 // char* row=dbuffer+i*dstride; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
130 char* row=img+row_stride*i; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
131 jpeg_read_scanlines( &cinfo,(JSAMPLE**)&row,1 ); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
132 } |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
133 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
134 jpeg_finish_decompress(&cinfo); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
135 jpeg_destroy_decompress(&cinfo); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
136 |
10001 | 137 swsContext= sws_getContext(width,height, in_fmt, |
138 dwidth,dheight, IMGFMT_BGR|dbpp, SWS_BICUBIC, NULL, NULL); | |
6457
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
139 |
9500 | 140 sws_scale(swsContext,&img,&row_stride,0,height,&dbuffer, &dstride); |
6457
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
141 |
9500 | 142 sws_freeContext(swsContext); |
6457
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
143 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
144 free(img); |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
145 |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
146 return 1; |
95918d5066b6
mwallp - simple wallpaper setting tool using MPlayer codebase
arpi
parents:
diff
changeset
|
147 } |