1 /* -*-C-*-
2 ******************************************************************************
3 *
4 * File: mcu2rast.c
5 * RCS: $Header: /ImageMagick/delegates/fpx/jpeg/mcu2rast.c,v 1.2 2000/12/23 22:37:48 bfriesen Exp $
6 * Description: Converts the MCU data into raster order pixels.
7 * Author: Gregory S. Yovanof
8 * Created: Thu Jul 13 11:04:22 1996
9 * Initial Source Release: Mon Jan 22 1996
10 * Language: C
11 * Package: Hewlett-Packard JPEG Encoder/Decoder
12 *
13 * Copyright (c) 1999 Digital Imaging Group, Inc.
14 * For conditions of distribution and use, see copyright notice
15 * in Flashpix.h
16 *
17 ******************************************************************************
18 */
19
20 #ifdef _WINDOWS
21 #define WINDLL
22 #endif
23
24 #include <stdio.h>
25 #include "jpegconf.h"
26 #include "decoder.h"
27 #include "dbuffer.h"
28 #include "dectile.h"
29 #include "djpeg.h"
30
Write_Scan_MCUs_Mono(unsigned char * outbuf,int * MCUbuf,int width,int height)31 void Write_Scan_MCUs_Mono(
32 unsigned char *outbuf, /* image out */
33 int *MCUbuf, /* sequence of MCUs */
34 int width, /* image width */
35 int height /* image height */
36 )
37 {
38 int i,j, skip, nvblocks,nhblocks;
39 int k,t;
40 int *inptr;
41 unsigned char *ptr;
42
43 inptr = MCUbuf;
44
45 skip = width-8;
46 nvblocks = height/8;
47 nhblocks = width/8;
48 for (i=0; i < nvblocks; i++) {
49 for(j=0; j < nhblocks; j++) {
50 ptr = outbuf + i*8*width + j*8;
51 for(k = 8; k > 0; k--) {
52 for(t = 8; t > 0; t--) {
53 *ptr++ = (unsigned char) *inptr++ ;
54 }
55 ptr = ptr + skip;
56 }
57 }
58 }
59 }
60
Write_Scan_MCUs_211(unsigned char * outbuf,int * MCUbuf,int width,int height,int interleave)61 void Write_Scan_MCUs_211(
62 unsigned char *outbuf, /* image out */
63 int *MCUbuf, /* sequence of MCUs */
64 int width, /* image width */
65 int height, /* image height */
66 int interleave /* Interleave flag */
67 )
68 {
69 /*
70 * Routine to generate raster scan data from MCUs.
71 * Case: subsampled data in 4:1:1
72 * or 4:2:0 format.
73 *
74 * <MCUbuf>: a pointer to the data
75 * if interleaved=1, output data is interleaved (c1c1c1c1 c2 c3,
76 c1c1c1c1 c2 c3)
77 * else it is not( data is in scan-line by scan -line format).
78 *
79 * width and heigh are already in multiples of 16; i.e. data
80 * is already padded and subsampled as necessary.
81 *
82 */
83 unsigned char *buf_ptr, *c2_ptr, *c3_ptr;
84 int *p1, *p2, *p3, *p4, i, j, k, l, t, skip, skip2,skip_row_data;
85 int *p1_2, *p2_2;
86 int *mcupos;
87 int nvMCU, nhMCU; /* number of FULL MCU vert. and hor. */
88
89 nvMCU = height/16;
90 nhMCU = width/16;
91
92 /* Interleaved Data */
93 if (interleave == 1) {
94 /* if interleaved, a line has (width/2 * 6) pixels
95 */
96 skip = width*3 - 48; /* 48 = 16 x 3 */
97 skip_row_data = 24*width; /* One 16x16 block-row bytes */
98 /* 24 = 16*3bytes*6/12 */
99 for (i = 0; i < nvMCU; i++) {
100 for (j=0; j < nhMCU; j++) {
101 mcupos = MCUbuf+(i*nhMCU+j)*384;
102 p3 = mcupos+4*64; /* chroma blocks */
103 p4 = mcupos+5*64;
104 buf_ptr = outbuf + i*skip_row_data + j*48;
105 for (l=0; l<2; l++) {
106 if(l == 0) {
107 p1 = mcupos; /* left-right blocks */
108 }
109 else {
110 p1 = mcupos+128;
111 }
112 p2 = p1+64;
113 p1_2 = p1 +8;
114 p2_2 = p2+8;
115 for(k=4; k > 0; k--) {
116 for(t=4; t > 0; t--) {
117 *buf_ptr++ = (unsigned char) *p1++;
118 *buf_ptr++ = (unsigned char) *p1++;
119 *buf_ptr++ = (unsigned char) *p1_2++ ;
120 *buf_ptr++ = (unsigned char) *p1_2++ ;
121 *buf_ptr++ = (unsigned char) *p3++ ;
122 *buf_ptr++ = (unsigned char) *p4++ ;
123 } /* t-loop */
124 for(t=4; t > 0; t--) {
125 *buf_ptr++ = (unsigned char) *p2++ ;
126 *buf_ptr++ = (unsigned char) *p2++ ;
127 *buf_ptr++ = (unsigned char) *p2_2++;
128 *buf_ptr++ = (unsigned char) *p2_2++;
129 *buf_ptr++ = (unsigned char) *p3++ ;
130 *buf_ptr++ = (unsigned char) *p4++ ;
131 } /* t-loop */
132 p1 = p1 + 8;
133 p2 = p2 +8;
134 p1_2 = p1_2 + 8;
135 p2_2 = p2_2 +8;
136 buf_ptr = buf_ptr + skip;
137 } /* k-loop */
138 } /* end on l */
139 } /* end on j */
140 } /* end on i */
141 } /* end of interleaved */
142 /************************/
143 /* Non-Interleaved Data */
144 /************************/
145 else {
146 /* if interleaved, a line has "width" pixels */
147 skip = width - 16;
148 skip2 = (width/2) - 8;
149 skip_row_data = 16*width; /* One row of MCUs */
150
151 for (i = 0; i < nvMCU; i++) {
152 for (j=0; j < nhMCU; j++) {
153 mcupos = MCUbuf+(i*nhMCU+j)*384;
154 p3 = mcupos+4*64; /* chroma blocks */
155 p4 = mcupos+5*64;
156 /* Where the luma and chroma will be stored */
157 buf_ptr = outbuf + i*skip_row_data + j*16;
158 c2_ptr = outbuf+width*height+j*8+i*width*4;
159 c3_ptr = c2_ptr + (width*height/4);
160
161 for (l=0; l<2; l++) {
162 if(l == 0) {
163 p1 = mcupos; /* left-right blocks */
164 }
165 else {
166 p1 = mcupos+128;
167 }
168 p2 = p1+64;
169 for(k=8; k > 0; k--) {
170 for(t=8; t > 0; t--) {
171 *buf_ptr++ = (unsigned char) *p1++;
172 } /* t-loop */
173 for(t=8; t > 0; t--) {
174 *buf_ptr++ = (unsigned char) *p2++;
175 } /* t-loop */
176 buf_ptr = buf_ptr + skip;
177 } /* k-loop */
178 } /* end on l */
179 /* fill the chroma now */
180 for(k =8; k>0; k--) {
181 for(t=8; t>0; t--) {
182 *c2_ptr++ = (unsigned char) *p3++;
183 *c3_ptr++ = (unsigned char) *p4++;
184 }
185 c2_ptr = c2_ptr +skip2;
186 c3_ptr = c3_ptr +skip2;
187 } /* end on k */
188 } /* end on j */
189 } /* end on i */
190 } /* end of non-interleaved */
191 }
192
Write_Scan_MCUs_422(unsigned char * outbuf,int * MCUbuf,int width,int height,int interleave)193 void Write_Scan_MCUs_422(
194 unsigned char *outbuf, /* image out */
195 int *MCUbuf, /* sequence of MCUs */
196 int width, /* image width */
197 int height, /* image height */
198 int interleave /* Interleave flag */
199 )
200 {
201 /*
202 * Routine to generate raster scan data from MCUs.
203 * Case: subsampled data in 4:2:2
204 *
205 * <MCUbuf>: a pointer to the data
206 * if interleaved=1, output data is interleaved (c1c1 c2 c3,
207 c1c1 c2 c3)
208 * else it is not( data is in scan-line by scan-line format).
209 *
210 * width and height are already in multiples of 8 or 16; i.e. data
211 * is already padded and subsampled as necessary.
212 *
213 */
214 unsigned char *buf_ptr, *c2_ptr, *c3_ptr;
215 int *p1, *p2, *p3, *p4, i, j, k, t;
216 int skip, skip2, skip_row_data;
217 int *mcupos;
218 int nvMCU, nhMCU; /* number of FULL MCU vert. and hor. */
219
220 nvMCU = height/8;
221 nhMCU = width/16;
222
223 /* Interleaved Data */
224 if (interleave == 1) {
225 /* if interleaved, a line has (width/2 * 4) pixels
226 */
227 skip = width*2 - 32; /* 32 = 8 subsampled symbols x 4bytes/ss-symbol */
228 skip_row_data = width * 16; /* One 8x16 block-row bytes */
229 /* 16 = 8*4*width/2 */
230 for (i = 0; i < nvMCU; i++) {
231 for (j=0; j < nhMCU; j++) {
232 mcupos = MCUbuf+(i*nhMCU+j)*256; /* 4 blocks/MCU */
233 buf_ptr = outbuf + i*skip_row_data + j*32;
234
235 p1 = mcupos; /* left-right blocks */
236 p2 = p1+64;
237 p3 = mcupos+2*64; /* chroma blocks */
238 p4 = p3 + 64;
239 for(k=8; k > 0; k--) { /* lines in MCU */
240 for(t=4; t > 0; t--) {
241 *buf_ptr++ = (unsigned char) *p1++;
242 *buf_ptr++ = (unsigned char) *p1++;
243 *buf_ptr++ = (unsigned char) *p3++ ;
244 *buf_ptr++ = (unsigned char) *p4++ ;
245 } /* t-loop */
246 for(t=4; t > 0; t--) {
247 *buf_ptr++ = (unsigned char) *p2++ ;
248 *buf_ptr++ = (unsigned char) *p2++ ;
249 *buf_ptr++ = (unsigned char) *p3++ ;
250 *buf_ptr++ = (unsigned char) *p4++ ;
251 } /* t-loop */
252 /* p1 = p1 + 8; p2 = p2 +8; GSY 5/6/96 */
253 buf_ptr = buf_ptr + skip;
254 } /* k-loop */
255
256 } /* end on j */
257 } /* end on i */
258 } /* end of interleaved */
259 /************************/
260 /* Non-Interleaved Data */
261 /************************/
262 else {
263 /* if interleaved, a line has "width" pixels */
264 skip = width - 16;
265 skip2 = (width/2) - 8;
266 skip_row_data = 8*width; /* One row of MCUs */
267
268 for (i = 0; i < nvMCU; i++) {
269 for (j=0; j < nhMCU; j++) {
270 mcupos = MCUbuf+(i*nhMCU+j)*256;
271 p3 = mcupos+4*64; /* chroma blocks */
272 p4 = p3 + 64;
273 /* Where the luma and chroma will be stored */
274 buf_ptr = outbuf + i*skip_row_data + j*16;
275 c2_ptr = outbuf+width*height+j*8+i*width*4;
276 c3_ptr = c2_ptr + (width*height/4);
277
278 p1 = mcupos; /* left-right blocks */
279 p2 = p1+64;
280 for(k=8; k > 0; k--) {
281 for(t=8; t > 0; t--) {
282 *buf_ptr++ = (unsigned char) *p1++;
283 } /* t-loop */
284 for(t=8; t > 0; t--) {
285 *buf_ptr++ = (unsigned char) *p2++;
286 } /* t-loop */
287 buf_ptr = buf_ptr + skip;
288 } /* k-loop */
289
290 /* fill the chroma now */
291 for(k =8; k>0; k--) {
292 for(t=8; t>0; t--) {
293 *c2_ptr++ = (unsigned char) *p3++;
294 *c3_ptr++ = (unsigned char) *p4++;
295 }
296 c2_ptr = c2_ptr +skip2;
297 c3_ptr = c3_ptr +skip2;
298 } /* end on k */
299 } /* end on j */
300 } /* end on i */
301 } /* end of non-interleaved */
302 }
303
Write_Scan_MCUs_4224(unsigned char * outbuf,int * MCUbuf,int width,int height,int interleave)304 void Write_Scan_MCUs_4224(
305 unsigned char *outbuf, /* image out */
306 int *MCUbuf, /* sequence of MCUs */
307 int width, /* image width */
308 int height, /* image height */
309 int interleave /* Interleave flag */
310 )
311 {
312 /*
313 * Routine to generate raster scan data from MCUs.
314 * Case: subsampled data in 4:2:2:4 format
315 *
316 * <MCUbuf>: a pointer to the data
317 * if interleaved=1, output data is interleaved (c1c1 c2 c3 c4c4,
318 c1c1 c2 c3 c4c4)
319 * else it is not( data is in scan-line by scan-line format).
320 *
321 * width and height are already in multiples of 8 or 16; i.e. data
322 * is already padded and subsampled as necessary.
323 *
324 */
325 unsigned char *buf_ptr, *c1_ptr, *c2_ptr, *c3_ptr, *c4_ptr;
326 int *p1, *p2, *p3, *p4, *p5, *p6, i, j, k, t;
327 int skip, skip2, skip_row_data;
328 int *mcupos;
329 int nvMCU, nhMCU; /* number of FULL MCU vert. and hor. */
330
331 nvMCU = height/8;
332 nhMCU = width/16;
333
334 /* Interleaved Data */
335 if (interleave == 1) {
336 /* if interleaved, a line has (width/2 * 6) pixels (1byte/pixel) */
337 /* A subsampled symbol has 6 bytes. */
338 skip = width*3 - 48; /* 48 = 8 subsampled symbols x 6bytes/ss-symbol */
339 skip_row_data = width * 24; /* One 8x16 block-row bytes */
340 /* 8 lines * (6*width/2)bytes/line */
341 for (i = 0; i < nvMCU; i++) {
342 for (j=0; j < nhMCU; j++) {
343 mcupos = MCUbuf+(i*nhMCU+j)*384; /* 6 blocks/MCU */
344 buf_ptr = outbuf + i*skip_row_data + j*48;
345
346 p1 = mcupos; /* left-right blocks */
347 p2 = p1+64;
348 p3 = p2+64; /* chroma blocks */
349 p4 = p3+64;
350 p5 = p4+64;
351 p6 = p5+64;
352 for(k=8; k > 0; k--) { /* lines in MCU */
353 for(t=4; t > 0; t--) {
354 *buf_ptr++ = (unsigned char) *p1++;
355 *buf_ptr++ = (unsigned char) *p1++;
356 *buf_ptr++ = (unsigned char) *p3++ ;
357 *buf_ptr++ = (unsigned char) *p4++ ;
358 *buf_ptr++ = (unsigned char) *p5++;
359 *buf_ptr++ = (unsigned char) *p5++;
360 } /* t-loop */
361 for(t=4; t > 0; t--) {
362 *buf_ptr++ = (unsigned char) *p2++ ;
363 *buf_ptr++ = (unsigned char) *p2++ ;
364 *buf_ptr++ = (unsigned char) *p3++ ;
365 *buf_ptr++ = (unsigned char) *p4++ ;
366 *buf_ptr++ = (unsigned char) *p6++ ;
367 *buf_ptr++ = (unsigned char) *p6++ ;
368 } /* t-loop */
369 buf_ptr = buf_ptr + skip;
370 } /* k-loop */
371
372 } /* end on j */
373 } /* end on i */
374 } /* end of interleaved */
375 /************************/
376 /* Non-Interleaved Data */
377 /************************/
378 else {
379 /* if interleaved, a line has "width" pixels */
380 skip = width - 16;
381 skip2 = (width/2) - 8;
382 skip_row_data = 8*width; /* One row of MCUs */
383
384 for (i = 0; i < nvMCU; i++) {
385 for (j=0; j < nhMCU; j++) {
386 mcupos = MCUbuf+(i*nhMCU+j)*384;
387 p1 = mcupos; /* left-right blocks */
388 p2 = p1+64;
389 p3 = mcupos+4*64; /* chroma blocks */
390 p4 = p3 + 64;
391 p5 = p4 + 64;
392 p6 = p5 + 64;
393 /* Where the luma, chroma and alpha will be stored */
394 c1_ptr = outbuf + i*skip_row_data + j*16;
395 c2_ptr = outbuf+width*height+j*8+i*width*4;
396 c3_ptr = c2_ptr + (width*height/4);
397 c4_ptr = outbuf + 3*width*height/2 + i*skip_row_data + j*16;
398
399 for(k=8; k > 0; k--) {
400 for(t=8; t > 0; t--) {
401 *c1_ptr++ = (unsigned char) *p1++;
402 *c4_ptr++ = (unsigned char) *p5++;
403 } /* t-loop */
404 for(t=8; t > 0; t--) {
405 *c1_ptr++ = (unsigned char) *p2++;
406 *c4_ptr++ = (unsigned char) *p6++;
407 } /* t-loop */
408 c1_ptr = c1_ptr + skip;
409 } /* k-loop */
410
411 /* fill the chroma now */
412 for(k =8; k>0; k--) {
413 for(t=8; t>0; t--) {
414 *c2_ptr++ = (unsigned char) *p3++;
415 *c3_ptr++ = (unsigned char) *p4++;
416 }
417 c2_ptr = c2_ptr +skip2;
418 c3_ptr = c3_ptr +skip2;
419 } /* end on k */
420 } /* end on j */
421 } /* end on i */
422 } /* end of non-interleaved */
423 }
424
Write_Scan_MCUs_111(unsigned char * outbuf,int * MCUbuf,int width,int height,int interleave)425 void Write_Scan_MCUs_111(
426 unsigned char *outbuf, /* image out */
427 int *MCUbuf, /* sequence of MCUs */
428 int width, /* image width */
429 int height, /* image height */
430 int interleave /* Interleave flag */
431 )
432 /*
433 * Routine to generate raster scan data from macroblocks
434 for NON-subsampled data (1:1:1)
435 * MCUbuf: a pointer to the MCUs
436 * if interleaved=1, data output is interleaved (RGB RGB ..)
437 * else it is not.
438 *
439 */
440 {
441 unsigned char *buf_ptr;
442 int *p1, *p2, *p3, i, j, k, t, skip, block_row_skip;
443 int nvMCU, nhMCU; /* number of FULL MCU vert. and hori. */
444 unsigned char *c1, *c2, *c3;
445 int *mcupos;
446
447 nvMCU = (height)/8;
448 nhMCU = (width)/8;
449
450 if(interleave == 1) {
451 skip = (3*width) - 24;
452 block_row_skip = 3*width*8;
453 for (i = 0; i < nvMCU; i++) {
454 for (j = 0; j < nhMCU; j++) {
455 mcupos = MCUbuf + (i*nhMCU+j)*192;
456
457 p1 = mcupos;
458 p2 = mcupos+64;
459 p3 = p2 + 64;
460 buf_ptr = outbuf + i*block_row_skip + j*24;
461 for (k = 8; k > 0; k--) {
462 for (t = 8; t > 0; t--) {
463 *buf_ptr++ = (unsigned char) *p1++ ;
464 *buf_ptr++ = (unsigned char) *p2++ ;
465 *buf_ptr++ = (unsigned char) *p3++ ;
466 }
467 buf_ptr = buf_ptr + skip;
468 }
469 } /* end of j */
470 } /* end of i */
471 } /* end of interleaved data case */
472 else {
473 /************************/
474 /* Non interleaved data */
475 /************************/
476 skip = width - 8;
477 block_row_skip = width*8;
478 for (i = 0; i < nvMCU; i++) {
479 for (j = 0; j < nhMCU; j++) {
480 mcupos = MCUbuf + (i*nhMCU+j)*192;
481
482 p1 = mcupos;
483 p2 = mcupos+64;
484 p3 = p2 + 64;
485
486 c1 = outbuf + i*block_row_skip + j*8;
487 c2 = c1 + width * height;
488 c3 = c2 + width * height;
489 for (k = 8; k > 0; k--) {
490 for (t = 8; t > 0; t--) {
491 *c1++ = (unsigned char) *p1++ ;
492 *c2++ = (unsigned char) *p2++ ;
493 *c3++ = (unsigned char) *p3++ ;
494 }
495 c1 = c1 + skip;
496 c2 = c2 + skip;
497 c3 = c3 + skip;
498 }
499 } /* end of j */
500 } /* end of i */
501 } /* end of else loop */
502 }
503
Write_Scan_MCUs_4114(unsigned char * outbuf,int * MCUbuf,int width,int height,int interleave)504 void Write_Scan_MCUs_4114(
505 unsigned char *outbuf, /* image out */
506 int *MCUbuf, /* sequence of MCUs */
507 int width, /* image width */
508 int height, /* image height */
509 int interleave /* Interleave flag */
510 )
511 {
512 /*
513 * Routine to generate raster scan data from MCUs.
514 * Case: subsampled data in 4:1:1:4
515 * i.e., 4 channel data with the middle 2 channels
516 * being subsampled by 2x in both dimensions.
517 *
518 * <MCUbuf>: a pointer to the data
519 * if interleaved=1, output data is interleaved (c1c1c1c1 c2 c3,
520 c1c1c1c1 c2 c3)
521 * else it is not( data is in scan-line by scan-line format).
522 *
523 * width and heigh are already in multiples of 16; i.e. data
524 * is already padded and subsampled as necessary.
525 *
526 */
527 unsigned char *buf_ptr, *c1_ptr, *c2_ptr, *c3_ptr;
528 int *p1, *p2, *p3, *p4, i, j, k, l, t, skip, skip2,skip_row_data;
529 int *p1_2, *p2_2;
530 int *mcupos;
531 int nvMCU, nhMCU; /* number of FULL MCU vert. and hor. */
532 int *p5,*p6,*p5_2,*p6_2;
533 unsigned char *c4_ptr;
534
535 nvMCU = height/16;
536 nhMCU = width/16;
537
538 /* Interleaved Data */
539 if (interleave == 1) {
540 /* if interleaved, a line has (width/2 * 10) pixels */
541 skip = width*5 - 80; /* 80 = 8 subsampled blocks * 10 bytes/block */
542 skip_row_data = 40*width; /* One 16x16 block-row bytes */
543 /* 40 = 16rows * 4 bytes * 10/16 (MCU reduction) */
544 for (i = 0; i < nvMCU; i++) {
545 for (j=0; j < nhMCU; j++) {
546 mcupos = MCUbuf+(i*nhMCU+j)*640;
547 /* 640 = 10 blocks/MCU * 64 bytes */
548 p3 = mcupos+4*64; /* chroma blocks */
549 p4 = mcupos+5*64;
550 buf_ptr = outbuf + i*skip_row_data + j*80;
551 for (l=0; l<2; l++) {
552 if(l == 0) {
553 p1 = mcupos; /* left-right blocks */
554 }
555 else {
556 p1 = mcupos+128;
557 }
558 p2 = p1+64;
559 p1_2 = p1+8;
560 p2_2 = p2+8;
561 p5 = p1+6*64;
562 p6 = p5+64;
563 p5_2 = p5+8;
564 p6_2 = p6+8;
565 for(k=4; k > 0; k--) {
566 for(t=4; t > 0; t--) {
567 *buf_ptr++ = (unsigned char) *p1++;
568 *buf_ptr++ = (unsigned char) *p1++;
569 *buf_ptr++ = (unsigned char) *p1_2++ ;
570 *buf_ptr++ = (unsigned char) *p1_2++ ;
571 *buf_ptr++ = (unsigned char) *p3++ ;
572 *buf_ptr++ = (unsigned char) *p4++ ;
573 *buf_ptr++ = (unsigned char) *p5++;
574 *buf_ptr++ = (unsigned char) *p5++;
575 *buf_ptr++ = (unsigned char) *p5_2++ ;
576 *buf_ptr++ = (unsigned char) *p5_2++ ;
577 } /* t-loop */
578 for(t=4; t > 0; t--) {
579 *buf_ptr++ = (unsigned char) *p2++ ;
580 *buf_ptr++ = (unsigned char) *p2++ ;
581 *buf_ptr++ = (unsigned char) *p2_2++;
582 *buf_ptr++ = (unsigned char) *p2_2++;
583 *buf_ptr++ = (unsigned char) *p3++ ;
584 *buf_ptr++ = (unsigned char) *p4++ ;
585 *buf_ptr++ = (unsigned char) *p6++ ;
586 *buf_ptr++ = (unsigned char) *p6++ ;
587 *buf_ptr++ = (unsigned char) *p6_2++;
588 *buf_ptr++ = (unsigned char) *p6_2++;
589 } /* t-loop */
590 p1 = p1 + 8;
591 p2 = p2 +8;
592 p1_2 = p1_2 + 8;
593 p2_2 = p2_2 +8;
594 p5 += 8;
595 p6 += 8;
596 p5_2 += 8;
597 p6_2 += 8;
598 buf_ptr = buf_ptr + skip;
599 } /* k-loop */
600 } /* end on l */
601 } /* end on j */
602 } /* end on i */
603 } /* end of interleaved */
604 /************************/
605 /* Non-Interleaved Data */
606 /************************/
607 else {
608 /* if non-interleaved, a line has "width" pixels */
609 skip = width - 16;
610 skip2 = (width/2) - 8;
611 skip_row_data = 16*width; /* One row of MCUs */
612
613 for (i = 0; i < nvMCU; i++) {
614 for (j=0; j < nhMCU; j++) {
615 mcupos = MCUbuf+(i*nhMCU+j)*640;
616 p3 = mcupos+4*64; /* chroma blocks */
617 p4 = mcupos+5*64;
618 /* Where the luma and chroma will be stored */
619 c1_ptr = outbuf + i*skip_row_data + j*16;
620 c2_ptr = outbuf+width*height+j*8+i*width*4;
621 c3_ptr = c2_ptr + (width*height/4);
622 c4_ptr = c1_ptr + (width*height/2);
623
624 for (l=0; l<2; l++) { /* output luma & alpha-channel */
625 if(l == 0) {
626 p1 = mcupos; /* left-right blocks */
627 }
628 else {
629 p1 = mcupos+128;
630 }
631 p2 = p1+64;
632 p5 = p1+6*64;
633 p6 = p5+64;
634 for(k=8; k > 0; k--) {
635 for(t=8; t > 0; t--) {
636 *c1_ptr++ = (unsigned char) *p1++;
637 *c4_ptr++ = (unsigned char) *p5++;
638 } /* t-loop */
639 for(t=8; t > 0; t--) {
640 *c1_ptr++ = (unsigned char) *p2++;
641 *c4_ptr++ = (unsigned char) *p6++;
642 } /* t-loop */
643 c1_ptr = c1_ptr + skip;
644 c4_ptr = c4_ptr + skip;
645 } /* k-loop */
646 } /* end on l */
647 /* fill the chroma now */
648 for(k =8; k>0; k--) {
649 for(t=8; t>0; t--) {
650 *c2_ptr++ = (unsigned char) *p3++;
651 *c3_ptr++ = (unsigned char) *p4++;
652 }
653 c2_ptr = c2_ptr +skip2;
654 c3_ptr = c3_ptr +skip2;
655 } /* end on k */
656 } /* end on j */
657 } /* end on i */
658 } /* end of non-interleaved */
659 }
660
Write_Scan_MCUs_1111(unsigned char * outbuf,int * MCUbuf,int width,int height,int interleave)661 void Write_Scan_MCUs_1111(
662 unsigned char *outbuf, /* image out */
663 int *MCUbuf, /* sequence of MCUs */
664 int width, /* image width */
665 int height, /* image height */
666 int interleave /* Interleave flag */
667 )
668 /*
669 * Routine to generate raster scan data from macroblocks
670 for NON-subsampled data with four components (1:1:1:1)
671 * MCUbuf: a pointer to the MCUs
672 * if interleaved=1, data output is interleaved (eg. MCYK, MCYK,...)
673 * else it is not.
674 *
675 */
676 {
677 unsigned char *buf_ptr;
678 int *p1, *p2, *p3, *p4, i, j, k, t, skip, block_row_skip;
679 int nvMCU, nhMCU; /* number of FULL MCU vert. and hori. */
680 unsigned char *c1, *c2, *c3, *c4;
681 int *mcupos;
682
683 nvMCU = (height)/8;
684 nhMCU = (width)/8;
685
686 if(interleave == 1) {
687 skip = (4*width) - 32;
688 block_row_skip = 4*width*8;
689 for (i = 0; i < nvMCU; i++) {
690 for (j = 0; j < nhMCU; j++) {
691 mcupos = MCUbuf + (i*nhMCU+j)*256;
692
693 p1 = mcupos;
694 p2 = mcupos+64;
695 p3 = p2 + 64;
696 p4 = p3 + 64;
697 buf_ptr = outbuf + i*block_row_skip + j*32;
698 for (k = 8; k > 0; k--) {
699 for (t = 8; t > 0; t--) {
700 *buf_ptr++ = (unsigned char) *p1++ ;
701 *buf_ptr++ = (unsigned char) *p2++ ;
702 *buf_ptr++ = (unsigned char) *p3++ ;
703 *buf_ptr++ = (unsigned char) *p4++ ;
704 }
705 buf_ptr = buf_ptr + skip;
706 }
707 } /* end of j */
708 } /* end of i */
709 } /* end of interleaved data case */
710 else {
711 /************************/
712 /* Non interleaved data */
713 /************************/
714 skip = width - 8;
715 block_row_skip = width*8;
716 for (i = 0; i < nvMCU; i++) {
717 for (j = 0; j < nhMCU; j++) {
718 mcupos = MCUbuf + (i*nhMCU+j)*256;
719
720 p1 = mcupos;
721 p2 = mcupos+64;
722 p3 = p2 + 64;
723 p4 = p3 + 64;
724
725 c1 = outbuf + i*block_row_skip + j*8;
726 c2 = c1 + width * height;
727 c3 = c2 + width * height;
728 c4 = c3 + width * height;
729 for (k = 8; k > 0; k--) {
730 for (t = 8; t > 0; t--) {
731 *c1++ = (unsigned char) *p1++ ;
732 *c2++ = (unsigned char) *p2++ ;
733 *c3++ = (unsigned char) *p3++ ;
734 *c4++ = (unsigned char) *p4++ ;
735 }
736 c1 = c1 + skip;
737 c2 = c2 + skip;
738 c3 = c3 + skip;
739 c4 = c4 + skip;
740 }
741 } /* end of j */
742 } /* end of i */
743 } /* end of else loop */
744 }
745
Write_Scan_MCUs_11(unsigned char * outbuf,int * MCUbuf,int width,int height,int interleave)746 void Write_Scan_MCUs_11(
747 unsigned char *outbuf, /* image out */
748 int *MCUbuf, /* sequence of MCUs */
749 int width, /* image width */
750 int height, /* image height */
751 int interleave /* Interleave flag */
752 )
753 /*
754 * Routine to generate raster scan data from macroblocks
755 for NON-subsampled data with two components (1:1)
756 Not very practical, but included any how!!
757 * MCUbuf: a pointer to the MCUs
758 * if interleaved=1, data output is interleaved (eg. MCYK, MCYK,...)
759 * else it is not.
760 *
761 */
762 {
763 unsigned char *buf_ptr;
764 int *p1, *p2, i, j, k, t, skip, block_row_skip;
765 int nvMCU, nhMCU; /* number of FULL MCU vert. and hori. */
766 unsigned char *c1, *c2;
767 int *mcupos;
768
769 nvMCU = (height)/8;
770 nhMCU = (width)/8;
771
772 if(interleave == 1) {
773 skip = (2*width) - 16;
774 block_row_skip = 2*width*8;
775 for (i = 0; i < nvMCU; i++) {
776 for (j = 0; j < nhMCU; j++) {
777 mcupos = MCUbuf + (i*nhMCU+j)*128;
778
779 p1 = mcupos;
780 p2 = mcupos+64;
781
782 buf_ptr = outbuf + i*block_row_skip + j*16;
783 for (k = 8; k > 0; k--) {
784 for (t = 8; t > 0; t--) {
785 *buf_ptr++ = (unsigned char) *p1++ ;
786 *buf_ptr++ = (unsigned char) *p2++ ;
787 }
788 buf_ptr = buf_ptr + skip;
789 }
790 } /* end of j */
791 } /* end of i */
792 } /* end of interleaved data case */
793 else {
794 /************************/
795 /* Non interleaved data */
796 /************************/
797 skip = width - 8;
798 block_row_skip = width*8;
799 for (i = 0; i < nvMCU; i++) {
800 for (j = 0; j < nhMCU; j++) {
801 mcupos = MCUbuf + (i*nhMCU+j)*128;
802
803 p1 = mcupos;
804 p2 = mcupos+64;
805
806 c1 = outbuf + i*block_row_skip + j*8;
807 c2 = c1 + width * height;
808 for (k = 8; k > 0; k--) {
809 for (t = 8; t > 0; t--) {
810 *c1++ = (unsigned char) *p1++ ;
811 *c2++ = (unsigned char) *p2++ ;
812 }
813 c1 = c1 + skip;
814 c2 = c2 + skip;
815 }
816 } /* end of j */
817 } /* end of i */
818 } /* end of else loop */
819 }
820