1 /*
2 * lossless JPEG encoder
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2003 Alex Beregszaszi
5 * Copyright (c) 2003-2004 Michael Niedermayer
6 *
7 * Support for external huffman table, various fixes (AVID workaround),
8 * aspecting, new decode_frame mechanism and apple mjpeg-b support
9 * by Alex Beregszaszi
10 *
11 * This file is part of FFmpeg.
12 *
13 * FFmpeg is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * FFmpeg is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with FFmpeg; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28 /**
29 * @file
30 * lossless JPEG encoder.
31 */
32
38
39
41 const AVFrame *pict,
int *got_packet)
42 {
52
54 max_pkt_size += width * height * 3 * 4;
55 else {
56 max_pkt_size += mb_width * mb_height * 3 * 4
58 }
59
64 }
65
68
70
73 if (ret < 0)
77
79
81
88 int left[3], top[3], topleft[3];
89
90 for(i=0; i<3; i++){
91 buffer[0][i]= 1 << (9 - 1);
92 }
93
94 for(y = 0; y <
height; y++) {
95 const int modified_predictor= y ? predictor : 1;
97
100 return -1;
101 }
102
103 for(i=0; i<3; i++){
104 top[i]= left[i]= topleft[i]=
buffer[0][i];
105 }
106 for(x = 0; x <
width; x++) {
108 buffer[x][1] = ptr[3*x+0] - ptr[3*x+1] + 0x100;
109 buffer[x][2] = ptr[3*x+2] - ptr[3*x+1] + 0x100;
110 buffer[x][0] = (ptr[3*x+0] + 2*ptr[3*x+1] + ptr[3*x+2])>>2;
111 }else{
112 buffer[x][1] = ptr[4*x+0] - ptr[4*x+1] + 0x100;
113 buffer[x][2] = ptr[4*x+2] - ptr[4*x+1] + 0x100;
114 buffer[x][0] = (ptr[4*x+0] + 2*ptr[4*x+1] + ptr[4*x+2])>>2;
115 }
116
117 for(i=0;i<3;i++) {
119
120 PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
121
122 topleft[i]= top[i];
124
126
127 diff= ((left[i] - pred + 0x100)&0x1FF) - 0x100;
128
129 if(i==0)
131 else
133 }
134 }
135 }
136 }else{
137 int mb_x, mb_y, i;
138
139 for(mb_y = 0; mb_y < mb_height; mb_y++) {
142 return -1;
143 }
144 for(mb_x = 0; mb_x < mb_width; mb_x++) {
145 if(mb_x==0 || mb_y==0){
146 for(i=0;i<3;i++) {
148 int x,
y, h,
v, linesize;
152
154 for(x=0; x<h; x++){
156
157 ptr = p->
data[i] + (linesize * (v * mb_y +
y)) + (h * mb_x + x);
//FIXME optimize this crap
158 if(y==0 && mb_y==0){
159 if(x==0 && mb_x==0){
160 pred= 128;
161 }else{
162 pred= ptr[-1];
163 }
164 }else{
165 if(x==0 && mb_x==0){
166 pred= ptr[-linesize];
167 }else{
168 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
169 }
170 }
171
172 if(i==0)
174 else
176 }
177 }
178 }
179 }else{
180 for(i=0;i<3;i++) {
182 int x,
y, h,
v, linesize;
186
188 for(x=0; x<h; x++){
190
191 ptr = p->
data[i] + (linesize * (v * mb_y +
y)) + (h * mb_x + x);
//FIXME optimize this crap
192 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
193
194 if(i==0)
196 else
198 }
199 }
200 }
201 }
202 }
203 }
204 }
205
211
215 *got_packet = 1;
216
217 return 0;
218 // return (put_bits_count(&f->pb)+7)/8;
219 }
220
221
236 };