1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 #include "mp4lib_int.h"
19 #include "mp4enc_lib.h"
21 //const static Int roundtab4[] = {0,1,1,1};
22 //const static Int roundtab8[] = {0,0,1,1,1,1,1,2};
23 //const static Int roundtab12[] = {0,0,0,1,1,1,1,1,1,1,2,2};
24 const static Int roundtab16[] = {0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
26 #define FORWARD_MODE 1
27 #define BACKWARD_MODE 2
28 #define BIDIRECTION_MODE 3
35 /*Function Prototype */
37 Int EncGetPredOutside(Int xpos, Int ypos, UChar *c_prev, UChar *rec,
38 Int width, Int height, Int rnd1);
40 void Copy_MB_from_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width);
41 void Copy_B_from_Vop(UChar *comp, Int cChan[], Int width);
42 void Copy_MB_into_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int width);
43 void Copy_B_into_Vop(UChar *comp, Int cChan[], Int width);
44 void get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v,
45 Short mb[6][64], Int lx, Int lx_uv);
48 UChar *c_prev, /* i */
49 UChar *pred_block, /* i */
55 UChar *c_prev, /* i */
56 UChar *pred_block, /* i */
62 UChar *c_prev, /* i */
63 UChar *pred_block, /* i */
69 UChar *c_prev, /* i */
70 UChar *pred_block, /* i */
75 static Int(*const GetPredAdvBTable[2][2])(UChar*, UChar*, Int, Int) =
77 {&GetPredAdvBy0x0, &GetPredAdvBy0x1},
78 {&GetPredAdvBy1x0, &GetPredAdvBy1x1}
87 /* ======================================================================== */
88 /* Function : getMotionCompensatedMB( ) */
89 /* Date : 4/17/2001 */
90 /* Purpose : Get the motion compensate block into video->predictionMB */
91 /* and generate video->predictionErrorMB */
92 /* modified from MBMotionComp() function in the decoder */
96 /* ======================================================================== */
98 void getMotionCompensatedMB(VideoEncData *video, Int ind_x, Int ind_y, Int offset)
100 Vop *prevVop = video->forwardRefVop; //reference frame
101 Vop *currVop = video->currVop;
102 Int mbnum = video->mbnum; //mb index
103 MOT *mot = video->mot[mbnum];
105 UChar *c_prev, *cu_prev, *cv_prev;
106 UChar *c_rec, *cu_rec, *cv_rec;
107 Int height, pitch, pitch_uv, height_uv;
108 Int mode = video->headerInfo.Mode[mbnum]; /* get mode */
114 OSCL_UNUSED_ARG(offset);
116 round1 = (Int)(1 - video->currVop->roundingType);
118 pitch = currVop->pitch;
119 height = currVop->height;
120 pitch_uv = pitch >> 1;
121 height_uv = height >> 1;
126 c_rec = video->predictedMB;
127 cu_rec = video->predictedMB + 256;
128 cv_rec = video->predictedMB + 264;
130 if (mode == MODE_INTER || mode == MODE_INTER_Q)
132 /* Motion vector in x direction */
136 c_prev = prevVop->yChan;
138 xpred = (xpos << 1) + dx ;
139 ypred = (ypos << 1) + dy ;
141 /* Call function that performs luminance prediction */
142 EncPrediction_INTER(xpred, ypred, c_prev, c_rec,
145 if ((dx & 3) == 0) dx = dx >> 1;
146 else dx = (dx >> 1) | 1;
148 if ((dy & 3) == 0) dy = dy >> 1;
149 else dy = (dy >> 1) | 1;
154 cu_prev = prevVop->uChan;
155 cv_prev = prevVop->vChan;
157 EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec,
158 pitch_uv, (currVop->width) >> 1, height_uv, round1);
161 else if (mode == MODE_INTER4V)
163 c_prev = prevVop->yChan;
164 cu_prev = prevVop->uChan;
165 cv_prev = prevVop->vChan;
167 EncPrediction_INTER4V(xpos, ypos, mot, c_prev, c_rec,
170 xsum = mot[1].x + mot[2].x + mot[3].x + mot[4].x;
171 ysum = mot[1].y + mot[2].y + mot[3].y + mot[4].y;
173 dx = PV_SIGN(xsum) * (roundtab16[(PV_ABS(xsum)) & 0xF] +
174 (((PV_ABS(xsum)) >> 4) << 1));
175 dy = PV_SIGN(ysum) * (roundtab16[(PV_ABS(ysum)) & 0xF] +
176 (((PV_ABS(ysum)) >> 4) << 1));
181 EncPrediction_Chrom(xpred, ypred, cu_prev, cv_prev, cu_rec, cv_rec,
182 pitch_uv, (currVop->width) >> 1, height_uv, round1);
187 ;//printf("Error, MODE_SKIPPED is not decided yet!\n");
193 /***************************************************************************
194 Function: EncPrediction_INTER
196 Purpose: Get predicted area for luminance and compensate with the residue.
197 Modified from luminance_pred_mode_inter() in decoder.
198 ***************************************************************************/
200 void EncPrediction_INTER(
203 UChar *c_prev, /* i */
204 UChar *c_rec, /* i */
209 c_prev += (xpred >> 1) + ((ypred >> 1) * lx);
211 GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
216 GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
218 c_prev += (lx << 3) - B_SIZE;
219 c_rec += (16 << 3) - B_SIZE; /* padding */
221 GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
226 GetPredAdvBTable[ypred&1][xpred&1](c_prev, c_rec, lx, round1);
232 /***************************************************************************
233 Function: EncPrediction_INTER4V
235 Purpose: Get predicted area for luminance and compensate with the residue.
236 Modified from luminance_pred_mode_inter4v() in decoder.
237 ***************************************************************************/
239 void EncPrediction_INTER4V(
243 UChar *c_prev, /* i */
244 UChar *c_rec, /* i */
251 xpred = (Int)((xpos << 1) + mot[1].x);
252 ypred = (Int)((ypos << 1) + mot[1].y);
254 GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
259 xpred = (Int)(((xpos + B_SIZE) << 1) + mot[2].x);
260 ypred = (Int)((ypos << 1) + mot[2].y);
262 GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
265 c_rec += (16 << 3) - B_SIZE; /* padding */
267 xpred = (Int)((xpos << 1) + mot[3].x);
268 ypred = (Int)(((ypos + B_SIZE) << 1) + mot[3].y);
270 GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
275 xpred = (Int)(((xpos + B_SIZE) << 1) + mot[4].x);
276 ypred = (Int)(((ypos + B_SIZE) << 1) + mot[4].y);
278 GetPredAdvBTable[ypred&1][xpred&1](c_prev + (xpred >> 1) + ((ypred >> 1)*lx),
283 #endif /* NO_INTER4V */
285 /***************************************************************************
286 Function: EncPrediction_Chrom
288 Purpose: Get predicted area for chrominance and compensate with the residue.
289 Modified from chrominance_pred() in decoder.
290 ***************************************************************************/
292 void EncPrediction_Chrom(
295 UChar *cu_prev, /* i */
296 UChar *cv_prev, /* i */
300 Int width_uv, /* i */
301 Int height_uv, /* i */
305 /* check whether the MV points outside the frame */
306 /* Compute prediction for Chrominance b block (block[4]) */
307 if (xpred >= 0 && xpred <= ((width_uv << 1) - (2*B_SIZE)) && ypred >= 0 &&
308 ypred <= ((height_uv << 1) - (2*B_SIZE)))
310 /*****************************/
311 /* (x,y) is inside the frame */
312 /*****************************/
314 /* Compute prediction for Chrominance b (block[4]) */
315 GetPredAdvBTable[ypred&1][xpred&1](cu_prev + (xpred >> 1) + ((ypred >> 1)*lx),
318 /* Compute prediction for Chrominance r (block[5]) */
319 GetPredAdvBTable[ypred&1][xpred&1](cv_prev + (xpred >> 1) + ((ypred >> 1)*lx),
324 /******************************/
325 /* (x,y) is outside the frame */
326 /******************************/
328 /* Compute prediction for Chrominance b (block[4]) */
329 EncGetPredOutside(xpred, ypred,
331 width_uv, height_uv, round1);
333 /* Compute prediction for Chrominance r (block[5]) */
334 EncGetPredOutside(xpred, ypred,
336 width_uv, height_uv, round1);
341 /***************************************************************************
342 Function: GetPredAdvancedB
344 Purpose: Get predicted area (block) and compensate with the residue.
345 - modified from GetPredAdvancedBAdd in decoder.
348 ***************************************************************************/
357 Int i; /* loop variable */
358 ULong pred_word, word1, word2;
361 OSCL_UNUSED_ARG(rnd);
363 /* initialize offset to adjust pixel counter */
364 /* the next row; full-pel resolution */
366 tmp = (ULong)prev & 0x3;
368 if (tmp == 0) /* word-aligned */
370 rec -= 16; /* preset */
373 for (i = 8; i > 0; i--)
375 *((ULong*)(rec += 16)) = *((ULong*)(prev += lx));
376 *((ULong*)(rec + 4)) = *((ULong*)(prev + 4));
380 else if (tmp == 1) /* first position */
382 prev--; /* word-aligned */
383 rec -= 16; /* preset */
386 for (i = 8; i > 0; i--)
388 word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
389 word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */
390 word1 >>= 8; /* 0 b4 b3 b2 */
391 pred_word = word1 | (word2 << 24); /* b5 b4 b3 b2 */
392 *((ULong*)(rec += 16)) = pred_word;
394 word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
395 word2 >>= 8; /* 0 b8 b7 b6 */
396 pred_word = word2 | (word1 << 24); /* b9 b8 b7 b6 */
397 *((ULong*)(rec + 4)) = pred_word;
402 else if (tmp == 2) /* second position */
404 prev -= 2; /* word1-aligned */
405 rec -= 16; /* preset */
408 for (i = 8; i > 0; i--)
410 word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
411 word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */
412 word1 >>= 16; /* 0 0 b4 b3 */
413 pred_word = word1 | (word2 << 16); /* b6 b5 b4 b3 */
414 *((ULong*)(rec += 16)) = pred_word;
416 word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
417 word2 >>= 16; /* 0 0 b8 b7 */
418 pred_word = word2 | (word1 << 16); /* b10 b9 b8 b7 */
419 *((ULong*)(rec + 4)) = pred_word;
424 else /* third position */
426 prev -= 3; /* word1-aligned */
427 rec -= 16; /* preset */
430 for (i = 8; i > 0; i--)
432 word1 = *((ULong*)(prev += lx)); /* read 4 bytes, b4 b3 b2 b1 */
433 word2 = *((ULong*)(prev + 4)); /* read 4 bytes, b8 b7 b6 b5 */
434 word1 >>= 24; /* 0 0 0 b4 */
435 pred_word = word1 | (word2 << 8); /* b7 b6 b5 b4 */
436 *((ULong*)(rec += 16)) = pred_word;
438 word1 = *((ULong*)(prev + 8)); /* b12 b11 b10 b9 */
439 word2 >>= 24; /* 0 0 0 b8 */
440 pred_word = word2 | (word1 << 8); /* b11 b10 b9 b8 */
441 *((ULong*)(rec + 4)) = pred_word;
448 /**************************************************************************/
456 Int i; /* loop variable */
458 ULong word1, word2, word3, word12;
462 /* initialize offset to adjust pixel counter */
463 /* the next row; full-pel resolution */
464 offset = lx - B_SIZE; /* offset for prev */
466 /* Branch based on pixel location (half-pel or full-pel) for x and y */
467 rec -= 12; /* preset */
469 tmp = (ULong)prev & 3;
472 mask |= (mask << 16); /* 0xFEFEFEFE */
474 if (tmp == 0) /* word-aligned */
478 for (i = B_SIZE; i > 0; i--)
480 word1 = *((ULong*)prev); /* b4 b3 b2 b1 */
481 word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */
482 word12 = (word1 >> 8); /* 0 b4 b3 b2 */
483 word12 |= (word2 << 24); /* b5 b4 b3 b2 */
484 word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
486 word3 &= (~mask); /* 0x1010101, check last bit */
489 word1 = word1 + (word12 >> 1);
491 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
493 word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */
494 word12 = (word2 >> 8); /* 0 b8 b7 b6 */
495 word12 |= (word1 << 24); /* b9 b8 b7 b6 */
496 word3 = word2 | word12;
498 word3 &= (~mask); /* 0x1010101, check last bit */
501 word2 = word2 + (word12 >> 1);
503 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
511 for (i = B_SIZE; i > 0; i--)
513 word1 = *((ULong*)prev); /* b4 b3 b2 b1 */
515 word2 = *((ULong*)(prev += 4)); /* b8 b7 b6 b5 */
516 word12 = (word1 >> 8); /* 0 b4 b3 b2 */
517 word12 |= (word2 << 24); /* b5 b4 b3 b2 */
518 word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
520 word3 &= (~mask); /* 0x1010101, check last bit */
523 word1 = word1 + (word12 >> 1);
525 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
527 word1 = *((ULong*)(prev += 4)); /* b12 b11 b10 b9 */
528 word12 = (word2 >> 8); /* 0 b8 b7 b6 */
529 word12 |= (word1 << 24); /* b9 b8 b7 b6 */
530 word3 = word2 & word12;
532 word3 &= (~mask); /* 0x1010101, check last bit */
535 word2 = word2 + (word12 >> 1);
537 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
546 prev--; /* word-aligned */
549 for (i = B_SIZE; i > 0; i--)
551 word1 = *((ULong*)prev); /* b3 b2 b1 b0 */
552 word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */
553 word12 = (word1 >> 8); /* 0 b3 b2 b1 */
554 word1 >>= 16; /* 0 0 b3 b2 */
555 word12 |= (word2 << 24); /* b4 b3 b2 b1 */
556 word1 |= (word2 << 16); /* b5 b4 b3 b2 */
557 word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
559 word3 &= (~mask); /* 0x1010101, check last bit */
562 word1 = word1 + (word12 >> 1);
564 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
566 word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */
567 word12 = (word2 >> 8); /* 0 b7 b6 b5 */
568 word2 >>= 16; /* 0 0 b7 b6 */
569 word12 |= (word1 << 24); /* b8 b7 b6 b5 */
570 word2 |= (word1 << 16); /* b9 b8 b7 b6 */
571 word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word2&word12
573 word3 &= (~mask); /* 0x1010101, check last bit */
576 word2 = word2 + (word12 >> 1);
578 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
586 for (i = B_SIZE; i > 0; i--)
588 word1 = *((ULong*)prev); /* b3 b2 b1 b0 */
590 word2 = *((ULong*)(prev += 4)); /* b7 b6 b5 b4 */
591 word12 = (word1 >> 8); /* 0 b3 b2 b1 */
592 word1 >>= 16; /* 0 0 b3 b2 */
593 word12 |= (word2 << 24); /* b4 b3 b2 b1 */
594 word1 |= (word2 << 16); /* b5 b4 b3 b2 */
595 word3 = word1 & word12;
597 word3 &= (~mask); /* 0x1010101, check last bit */
600 word1 = word1 + (word12 >> 1);
602 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
604 word1 = *((ULong*)(prev += 4)); /* b11 b10 b9 b8 */
605 word12 = (word2 >> 8); /* 0 b7 b6 b5 */
606 word2 >>= 16; /* 0 0 b7 b6 */
607 word12 |= (word1 << 24); /* b8 b7 b6 b5 */
608 word2 |= (word1 << 16); /* b9 b8 b7 b6 */
609 word3 = word2 & word12;
611 word3 &= (~mask); /* 0x1010101, check last bit */
614 word2 = word2 + (word12 >> 1);
616 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
625 prev -= 2; /* word-aligned */
628 for (i = B_SIZE; i > 0; i--)
630 word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */
631 word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */
632 word12 = (word1 >> 16); /* 0 0 b2 b1 */
633 word1 >>= 24; /* 0 0 0 b2 */
634 word12 |= (word2 << 16); /* b4 b3 b2 b1 */
635 word1 |= (word2 << 8); /* b5 b4 b3 b2 */
636 word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
638 word3 &= (~mask); /* 0x1010101, check last bit */
641 word1 = word1 + (word12 >> 1);
643 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
645 word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */
646 word12 = (word2 >> 16); /* 0 0 b6 b5 */
647 word2 >>= 24; /* 0 0 0 b6 */
648 word12 |= (word1 << 16); /* b8 b7 b6 b5 */
649 word2 |= (word1 << 8); /* b9 b8 b7 b6 */
650 word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
652 word3 &= (~mask); /* 0x1010101, check last bit */
655 word2 = word2 + (word12 >> 1);
657 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
664 for (i = B_SIZE; i > 0; i--)
666 word1 = *((ULong*)prev); /* b2 b1 b0 bN1 */
667 word2 = *((ULong*)(prev += 4)); /* b6 b5 b4 b3 */
668 word12 = (word1 >> 16); /* 0 0 b2 b1 */
669 word1 >>= 24; /* 0 0 0 b2 */
670 word12 |= (word2 << 16); /* b4 b3 b2 b1 */
671 word1 |= (word2 << 8); /* b5 b4 b3 b2 */
672 word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
674 word3 &= (~mask); /* 0x1010101, check last bit */
677 word1 = word1 + (word12 >> 1);
679 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
681 word1 = *((ULong*)(prev += 4)); /* b10 b9 b8 b7 */
682 word12 = (word2 >> 16); /* 0 0 b6 b5 */
683 word2 >>= 24; /* 0 0 0 b6 */
684 word12 |= (word1 << 16); /* b8 b7 b6 b5 */
685 word2 |= (word1 << 8); /* b9 b8 b7 b6 */
686 word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
688 word3 &= (~mask); /* 0x1010101, check last bit */
691 word2 = word2 + (word12 >> 1);
693 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
701 prev -= 3; /* word-aligned */
704 for (i = B_SIZE; i > 0; i--)
706 word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */
707 word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */
708 word12 = (word1 >> 24); /* 0 0 0 b1 */
709 word12 |= (word2 << 8); /* b4 b3 b2 b1 */
711 word3 = word1 | word12; // rnd1 = 1; otherwise word3 = word1&word12
713 word3 &= (~mask); /* 0x1010101, check last bit */
716 word1 = word1 + (word12 >> 1);
718 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
720 word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */
721 word12 = (word2 >> 24); /* 0 0 0 b5 */
722 word12 |= (word1 << 8); /* b8 b7 b6 b5 */
723 word2 = word1; /* b9 b8 b7 b6 */
724 word3 = word2 | word12; // rnd1 = 1; otherwise word3 = word1&word12
726 word3 &= (~mask); /* 0x1010101, check last bit */
729 word2 = word2 + (word12 >> 1);
731 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
738 for (i = B_SIZE; i > 0; i--)
740 word1 = *((ULong*)prev); /* b1 b0 bN1 bN2 */
741 word2 = *((ULong*)(prev += 4)); /* b5 b4 b3 b2 */
742 word12 = (word1 >> 24); /* 0 0 0 b1 */
743 word12 |= (word2 << 8); /* b4 b3 b2 b1 */
745 word3 = word1 & word12; // rnd1 = 1; otherwise word3 = word1&word12
747 word3 &= (~mask); /* 0x1010101, check last bit */
750 word1 = word1 + (word12 >> 1);
752 *((ULong*)(rec += 12)) = word1; /* write 4 pixels */
754 word1 = *((ULong*)(prev += 4)); /* b9 b8 b7 b6 */
755 word12 = (word2 >> 24); /* 0 0 0 b5 */
756 word12 |= (word1 << 8); /* b8 b7 b6 b5 */
757 word2 = word1; /* b9 b8 b7 b6 */
758 word3 = word2 & word12; // rnd1 = 1; otherwise word3 = word1&word12
760 word3 &= (~mask); /* 0x1010101, check last bit */
763 word2 = word2 + (word12 >> 1);
765 *((ULong*)(rec += 4)) = word2; /* write 4 pixels */
773 /**************************************************************************/
781 Int i; /* loop variable */
783 ULong word1, word2, word3, word12, word22;
787 /* initialize offset to adjust pixel counter */
788 /* the next row; full-pel resolution */
789 offset = lx - B_SIZE; /* offset for prev */
791 /* Branch based on pixel location (half-pel or full-pel) for x and y */
792 rec -= 12; /* preset */
794 tmp = (ULong)prev & 3;
797 mask |= (mask << 16); /* 0xFEFEFEFE */
799 if (tmp == 0) /* word-aligned */
804 for (i = B_SIZE; i > 0; i--)
806 word1 = *((ULong*)(prev += 4));
807 word2 = *((ULong*)(prev + lx));
808 word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
810 word3 &= (~mask); /* 0x1010101, check last bit */
813 word1 = word1 + (word2 >> 1);
815 *((ULong*)(rec += 12)) = word1;
816 word1 = *((ULong*)(prev += 4));
817 word2 = *((ULong*)(prev + lx));
818 word3 = word1 | word2; // rnd1 = 1; otherwise word3 = word1&word2
820 word3 &= (~mask); /* 0x1010101, check last bit */
823 word1 = word1 + (word2 >> 1);
825 *((ULong*)(rec += 4)) = word1;
833 for (i = B_SIZE; i > 0; i--)
835 word1 = *((ULong*)(prev += 4));
836 word2 = *((ULong*)(prev + lx));
837 word3 = word1 & word2; /* rnd1 = 0; */
839 word3 &= (~mask); /* 0x1010101, check last bit */
842 word1 = word1 + (word2 >> 1);
844 *((ULong*)(rec += 12)) = word1;
845 word1 = *((ULong*)(prev += 4));
846 word2 = *((ULong*)(prev + lx));
847 word3 = word1 & word2; /* rnd1 = 0; */
849 word3 &= (~mask); /* 0x1010101, check last bit */
852 word1 = word1 + (word2 >> 1);
854 *((ULong*)(rec += 4)) = word1;
863 prev--; /* word-aligned */
866 for (i = B_SIZE; i > 0; i--)
868 word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
869 word22 = *((ULong*)(prev + lx));
871 word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
872 word2 = *((ULong*)(prev + lx));
873 word12 >>= 8; /* 0 b4 b3 b2 */
875 word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
876 word22 = word22 | (word2 << 24);
877 word3 = word12 | word22;
880 word3 &= (~mask); /* 0x1010101, check last bit */
882 word12 = word12 + (word22 >> 1);
884 *((ULong*)(rec += 12)) = word12;
886 word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
887 word22 = *((ULong*)(prev + lx));
888 word1 >>= 8; /* 0 b8 b7 b6 */
890 word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
891 word2 = word2 | (word22 << 24);
892 word3 = word1 | word2;
895 word3 &= (~mask); /* 0x1010101, check last bit */
897 word1 = word1 + (word2 >> 1);
899 *((ULong*)(rec += 4)) = word1;
906 for (i = B_SIZE; i > 0; i--)
908 word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
909 word22 = *((ULong*)(prev + lx));
911 word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
912 word2 = *((ULong*)(prev + lx));
913 word12 >>= 8; /* 0 b4 b3 b2 */
915 word12 = word12 | (word1 << 24); /* b5 b4 b3 b2 */
916 word22 = word22 | (word2 << 24);
917 word3 = word12 & word22;
920 word3 &= (~mask); /* 0x1010101, check last bit */
922 word12 = word12 + (word22 >> 1);
924 *((ULong*)(rec += 12)) = word12;
926 word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
927 word22 = *((ULong*)(prev + lx));
928 word1 >>= 8; /* 0 b8 b7 b6 */
930 word1 = word1 | (word12 << 24); /* b9 b8 b7 b6 */
931 word2 = word2 | (word22 << 24);
932 word3 = word1 & word2;
935 word3 &= (~mask); /* 0x1010101, check last bit */
937 word1 = word1 + (word2 >> 1);
939 *((ULong*)(rec += 4)) = word1;
947 prev -= 2; /* word-aligned */
950 for (i = B_SIZE; i > 0; i--)
952 word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
953 word22 = *((ULong*)(prev + lx));
955 word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
956 word2 = *((ULong*)(prev + lx));
957 word12 >>= 16; /* 0 0 b4 b3 */
959 word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
960 word22 = word22 | (word2 << 16);
961 word3 = word12 | word22;
964 word3 &= (~mask); /* 0x1010101, check last bit */
966 word12 = word12 + (word22 >> 1);
968 *((ULong*)(rec += 12)) = word12;
970 word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
971 word22 = *((ULong*)(prev + lx));
972 word1 >>= 16; /* 0 0 b8 b7 */
974 word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
975 word2 = word2 | (word22 << 16);
976 word3 = word1 | word2;
979 word3 &= (~mask); /* 0x1010101, check last bit */
981 word1 = word1 + (word2 >> 1);
983 *((ULong*)(rec += 4)) = word1;
990 for (i = B_SIZE; i > 0; i--)
992 word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
993 word22 = *((ULong*)(prev + lx));
995 word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
996 word2 = *((ULong*)(prev + lx));
997 word12 >>= 16; /* 0 0 b4 b3 */
999 word12 = word12 | (word1 << 16); /* b6 b5 b4 b3 */
1000 word22 = word22 | (word2 << 16);
1001 word3 = word12 & word22;
1004 word3 &= (~mask); /* 0x1010101, check last bit */
1006 word12 = word12 + (word22 >> 1);
1008 *((ULong*)(rec += 12)) = word12;
1010 word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
1011 word22 = *((ULong*)(prev + lx));
1012 word1 >>= 16; /* 0 0 b8 b7 */
1014 word1 = word1 | (word12 << 16); /* b10 b9 b8 b7 */
1015 word2 = word2 | (word22 << 16);
1016 word3 = word1 & word2;
1019 word3 &= (~mask); /* 0x1010101, check last bit */
1021 word1 = word1 + (word2 >> 1);
1023 *((ULong*)(rec += 4)) = word1;
1032 prev -= 3; /* word-aligned */
1035 for (i = B_SIZE; i > 0; i--)
1037 word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
1038 word22 = *((ULong*)(prev + lx));
1040 word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
1041 word2 = *((ULong*)(prev + lx));
1042 word12 >>= 24; /* 0 0 0 b4 */
1044 word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
1045 word22 = word22 | (word2 << 8);
1046 word3 = word12 | word22;
1049 word3 &= (~mask); /* 0x1010101, check last bit */
1051 word12 = word12 + (word22 >> 1);
1053 *((ULong*)(rec += 12)) = word12;
1055 word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
1056 word22 = *((ULong*)(prev + lx));
1057 word1 >>= 24; /* 0 0 0 b8 */
1059 word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
1060 word2 = word2 | (word22 << 8);
1061 word3 = word1 | word2;
1064 word3 &= (~mask); /* 0x1010101, check last bit */
1066 word1 = word1 + (word2 >> 1);
1068 *((ULong*)(rec += 4)) = word1;
1075 for (i = B_SIZE; i > 0; i--)
1077 word12 = *((ULong*)prev); /* read b4 b3 b2 b1 */
1078 word22 = *((ULong*)(prev + lx));
1080 word1 = *((ULong*)(prev += 4)); /* read b8 b7 b6 b5 */
1081 word2 = *((ULong*)(prev + lx));
1082 word12 >>= 24; /* 0 0 0 b4 */
1084 word12 = word12 | (word1 << 8); /* b7 b6 b5 b4 */
1085 word22 = word22 | (word2 << 8);
1086 word3 = word12 & word22;
1089 word3 &= (~mask); /* 0x1010101, check last bit */
1091 word12 = word12 + (word22 >> 1);
1093 *((ULong*)(rec += 12)) = word12;
1095 word12 = *((ULong*)(prev += 4)); /* read b12 b11 b10 b9 */
1096 word22 = *((ULong*)(prev + lx));
1097 word1 >>= 24; /* 0 0 0 b8 */
1099 word1 = word1 | (word12 << 8); /* b11 b10 b9 b8 */
1100 word2 = word2 | (word22 << 8);
1101 word3 = word1 & word2;
1104 word3 &= (~mask); /* 0x1010101, check last bit */
1106 word1 = word1 + (word2 >> 1);
1108 *((ULong*)(rec += 4)) = word1;
1116 /**********************************************************************************/
1117 Int GetPredAdvBy1x1(
1118 UChar *prev, /* i */
1124 Int i; /* loop variable */
1126 ULong x1, x2, x1m, x2m, y1, y2, y1m, y2m; /* new way */
1131 /* initialize offset to adjust pixel counter */
1132 /* the next row; full-pel resolution */
1133 offset = lx - B_SIZE; /* offset for prev */
1136 rnd2 |= (rnd2 << 8);
1137 rnd2 |= (rnd2 << 16);
1140 mask |= (mask << 8);
1141 mask |= (mask << 16); /* 0x3f3f3f3f */
1143 tmp = (ULong)prev & 3;
1145 rec -= 4; /* preset */
1147 if (tmp == 0) /* word-aligned */
1149 for (i = B_SIZE; i > 0; i--)
1151 x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
1152 x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
1153 y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
1154 y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
1156 x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
1157 x2m = (x2 >> 2) & mask;
1158 x1 = x1 ^(x1m << 2);
1159 x2 = x2 ^(x2m << 2);
1164 y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
1165 y2m = (y2 >> 2) & mask;
1166 y1 = y1 ^(y1m << 2);
1167 y2 = y2 ^(y2m << 2);
1173 x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
1174 y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
1175 x2m = (x2 >> 2) & mask;
1176 y2m = (y2 >> 2) & mask;
1177 x2 = x2 ^(x2m << 2);
1178 y2 = y2 ^(y2m << 2);
1183 /* now operate on x1m, x1, y1m, y1, x2m, x2 */
1184 /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
1185 /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
1186 /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
1191 y2m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */
1193 x1m += y2m; /* a3+b3+a4+b4, ....., a0+b0+a1+b1 */
1198 *((ULong*)(rec += 4)) = x1m; /* save x1m */
1202 y2m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */
1204 y1m += y2m; /* a7+b7+a8+b8, ....., a4+b4+a5+b5 */
1209 *((ULong*)(rec += 4)) = y1m; /* save y1m */
1219 prev--; /* to word-aligned */
1220 for (i = B_SIZE; i > 0; i--)
1222 x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
1223 x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
1224 y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
1225 y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
1227 x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
1228 x2m = (x2 >> 2) & mask;
1229 x1 = x1 ^(x1m << 2);
1230 x2 = x2 ^(x2m << 2);
1235 y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
1236 y2m = (y2 >> 2) & mask;
1237 y1 = y1 ^(y1m << 2);
1238 y2 = y2 ^(y2m << 2);
1244 x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
1245 y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
1246 x2m = (x2 >> 2) & mask;
1247 y2m = (y2 >> 2) & mask;
1248 x2 = x2 ^(x2m << 2);
1249 y2 = y2 ^(y2m << 2);
1254 /* now operate on x1m, x1, y1m, y1, x2m, x2 */
1255 /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
1256 /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
1257 /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
1262 x1m |= (y1m << 24); /* a4+b4, a3+b3, a2+b2, a1+b1 */
1266 y2m |= (x1m >> 8); /* a5+b5, a4+b4, a3+b3, a2+b2 */
1269 x1m += y2m; /* a4+b4+a5+b5, ....., a1+b1+a2+b2 */
1273 *((ULong*)(rec += 4)) = x1m; /* save x1m */
1277 y1m |= (x2m << 24); /* a8+b8, a7+b7, a6+b6, a5+b5 */
1281 y2m |= (y1m >> 8); /* a9+b9, a8+b8, a7+b7, a6+b6,*/
1284 y1m += y2m; /* a8+b8+a9+b9, ....., a5+b5+a6+b6 */
1288 *((ULong*)(rec += 4)) = y1m; /* save y1m */
1297 prev -= 2; /* to word-aligned */
1298 for (i = B_SIZE; i > 0; i--)
1300 x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
1301 x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
1302 y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
1303 y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
1305 x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
1306 x2m = (x2 >> 2) & mask;
1307 x1 = x1 ^(x1m << 2);
1308 x2 = x2 ^(x2m << 2);
1313 y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
1314 y2m = (y2 >> 2) & mask;
1315 y1 = y1 ^(y1m << 2);
1316 y2 = y2 ^(y2m << 2);
1322 x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
1323 y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
1324 x2m = (x2 >> 2) & mask;
1325 y2m = (y2 >> 2) & mask;
1326 x2 = x2 ^(x2m << 2);
1327 y2 = y2 ^(y2m << 2);
1332 /* now operate on x1m, x1, y1m, y1, x2m, x2 */
1333 /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
1334 /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
1335 /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
1340 x1m |= (y1m << 16); /* a5+b5, a4+b4, a3+b3, a2+b2 */
1344 y2m |= (x1m >> 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */
1347 x1m += y2m; /* a5+b5+a6+b6, ....., a2+b2+a3+b3 */
1351 *((ULong*)(rec += 4)) = x1m; /* save x1m */
1355 y1m |= (x2m << 16); /* a9+b9, a8+b8, a7+b7, a6+b6 */
1359 y2m |= (y1m >> 8); /* a10+b10, a9+b9, a8+b8, a7+b7,*/
1362 y1m += y2m; /* a9+b9+a10+b10, ....., a6+b6+a7+b7 */
1366 *((ULong*)(rec += 4)) = y1m; /* save y1m */
1375 prev -= 3; /* to word-aligned */
1376 for (i = B_SIZE; i > 0; i--)
1378 x1 = *((ULong*)prev); /* load a3 a2 a1 a0 */
1379 x2 = *((ULong*)(prev + lx)); /* load b3 b2 b1 b0, another line */
1380 y1 = *((ULong*)(prev += 4)); /* a7 a6 a5 a4 */
1381 y2 = *((ULong*)(prev + lx)); /* b7 b6 b5 b4 */
1383 x1m = (x1 >> 2) & mask; /* zero out last 2 bits */
1384 x2m = (x2 >> 2) & mask;
1385 x1 = x1 ^(x1m << 2);
1386 x2 = x2 ^(x2m << 2);
1391 y1m = (y1 >> 2) & mask; /* zero out last 2 bits */
1392 y2m = (y2 >> 2) & mask;
1393 y1 = y1 ^(y1m << 2);
1394 y2 = y2 ^(y2m << 2);
1400 x2 = *((ULong*)(prev += 4)); /* a11 a10 a9 a8 */
1401 y2 = *((ULong*)(prev + lx)); /* b11 b10 b9 b8 */
1402 x2m = (x2 >> 2) & mask;
1403 y2m = (y2 >> 2) & mask;
1404 x2 = x2 ^(x2m << 2);
1405 y2 = y2 ^(y2m << 2);
1410 /* now operate on x1m, x1, y1m, y1, x2m, x2 */
1411 /* x1m = a3+b3, a2+b2, a1+b1, a0+b0 */
1412 /* y1m = a7+b7, a6+b6, a5+b5, a4+b4 */
1413 /* x2m = a11+b11, a10+b10, a9+b9, a8+b8 */
1418 x1m |= (y1m << 8); /* a6+b6, a5+b5, a4+b4, a3+b3 */
1421 x1m += y1m; /* a6+b6+a7+b7, ....., a3+b3+a4+b4 */
1426 *((ULong*)(rec += 4)) = x1m; /* save x1m */
1430 y1m |= (x2m << 8); /* a10+b10, a9+b9, a8+b8, a7+b7 */
1432 y1m += x2m; /* a10+b10+a11+b11, ....., a7+b7+a8+b8 */
1437 *((ULong*)(rec += 4)) = y1m; /* save y1m */
1447 /*=============================================================================
1448 Function: EncGetPredOutside
1450 Purpose: - modified from GetPredOutside in the decoder.
1452 use the existing non-initialized padded region
1453 =============================================================================*/
1454 // not really needed since padding is included
1455 #define PAD_CORNER { temp = *src; \
1456 temp |= (temp<<8); \
1457 temp |= (temp<<16); \
1458 *((ULong*)dst) = temp; \
1459 *((ULong*)(dst+4)) = temp; \
1460 *((ULong*)(dst+=lx)) = temp; \
1461 *((ULong*)(dst+4)) = temp; \
1462 *((ULong*)(dst+=lx)) = temp; \
1463 *((ULong*)(dst+4)) = temp; \
1464 *((ULong*)(dst+=lx)) = temp; \
1465 *((ULong*)(dst+4)) = temp; \
1466 *((ULong*)(dst+=lx)) = temp; \
1467 *((ULong*)(dst+4)) = temp; \
1468 *((ULong*)(dst+=lx)) = temp; \
1469 *((ULong*)(dst+4)) = temp; \
1470 *((ULong*)(dst+=lx)) = temp; \
1471 *((ULong*)(dst+4)) = temp; \
1472 *((ULong*)(dst+=lx)) = temp; \
1473 *((ULong*)(dst+4)) = temp; }
1475 #define PAD_ROW { temp = *((ULong*)src); \
1476 temp2 = *((ULong*)(src+4)); \
1477 *((ULong*)dst) = temp; \
1478 *((ULong*)(dst+4)) = temp2; \
1479 *((ULong*)(dst+=lx)) = temp; \
1480 *((ULong*)(dst+4)) = temp2; \
1481 *((ULong*)(dst+=lx)) = temp; \
1482 *((ULong*)(dst+4)) = temp2; \
1483 *((ULong*)(dst+=lx)) = temp; \
1484 *((ULong*)(dst+4)) = temp2; \
1485 *((ULong*)(dst+=lx)) = temp; \
1486 *((ULong*)(dst+4)) = temp2; \
1487 *((ULong*)(dst+=lx)) = temp; \
1488 *((ULong*)(dst+4)) = temp2; \
1489 *((ULong*)(dst+=lx)) = temp; \
1490 *((ULong*)(dst+4)) = temp2; \
1491 *((ULong*)(dst+=lx)) = temp; \
1492 *((ULong*)(dst+4)) = temp2; }
1494 #define PAD_COL { temp = *src; temp |= (temp<<8); temp |= (temp<<16); \
1495 *((ULong*)dst) = temp; \
1496 *((ULong*)(dst+4)) = temp; \
1497 temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
1498 *((ULong*)(dst+=lx)) = temp; \
1499 *((ULong*)(dst+4)) = temp; \
1500 temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
1501 *((ULong*)(dst+=lx)) = temp; \
1502 *((ULong*)(dst+4)) = temp; \
1503 temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
1504 *((ULong*)(dst+=lx)) = temp; \
1505 *((ULong*)(dst+4)) = temp; \
1506 temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
1507 *((ULong*)(dst+=lx)) = temp; \
1508 *((ULong*)(dst+4)) = temp; \
1509 temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
1510 *((ULong*)(dst+=lx)) = temp; \
1511 *((ULong*)(dst+4)) = temp; \
1512 temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
1513 *((ULong*)(dst+=lx)) = temp; \
1514 *((ULong*)(dst+4)) = temp; \
1515 temp = *(src+=lx); temp |= (temp<<8); temp |= (temp<<16); \
1516 *((ULong*)(dst+=lx)) = temp; \
1517 *((ULong*)(dst+4)) = temp; }
1520 Int EncGetPredOutside(Int xpos, Int ypos, UChar *c_prev, UChar *rec,
1521 Int width, Int height, Int rnd1)
1528 lx = width + 16; /* only works for chroma */
1532 if (ypos < 0) /* pad top-left */
1536 dst = c_prev - (lx << 3) - 8;
1540 dst = c_prev - (lx << 3);
1547 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1552 else if ((ypos >> 1) < (height - 8)) /* pad left of frame */
1555 src = c_prev + (ypos >> 1) * lx;
1559 temp = *(src += lx);
1560 temp |= (temp << 8);
1561 temp |= (temp << 16);
1562 *((ULong*)(dst += lx)) = temp;
1563 *((ULong*)(dst + 4)) = temp;
1565 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1570 else /* pad bottom-left */
1573 src = c_prev + (height - 1) * lx;
1587 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1593 else if ((xpos >> 1) < (width - 8))
1595 if (ypos < 0) /* pad top of frame */
1597 xoffset = (xpos >> 1) & 0x3;
1598 src = c_prev + (xpos >> 1) - xoffset;
1599 dst = src - (lx << 3);
1601 if (xoffset || (xpos&1))
1603 temp = *((ULong*)(src + 8));
1604 dst = src - (lx << 3) + 8;
1605 *((ULong*)dst) = temp;
1606 *((ULong*)(dst += lx)) = temp;
1607 *((ULong*)(dst += lx)) = temp;
1608 *((ULong*)(dst += lx)) = temp;
1609 *((ULong*)(dst += lx)) = temp;
1610 *((ULong*)(dst += lx)) = temp;
1611 *((ULong*)(dst += lx)) = temp;
1612 *((ULong*)(dst += lx)) = temp;
1615 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1620 else /* pad bottom of frame */
1622 xoffset = (xpos >> 1) & 0x3;
1623 src = c_prev + (xpos >> 1) - xoffset + (height - 1) * lx;
1626 if (xoffset || (xpos&1))
1628 temp = *((ULong*)(src + 8));
1630 *((ULong*)dst) = temp;
1631 *((ULong*)(dst += lx)) = temp;
1632 *((ULong*)(dst += lx)) = temp;
1633 *((ULong*)(dst += lx)) = temp;
1634 *((ULong*)(dst += lx)) = temp;
1635 *((ULong*)(dst += lx)) = temp;
1636 *((ULong*)(dst += lx)) = temp;
1637 *((ULong*)(dst += lx)) = temp;
1640 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1648 if (ypos < 0) /* pad top-right */
1651 src = c_prev + width - 1;
1652 dst = src - (lx << 3) + 1;
1657 dst = src - (lx << 3);
1665 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1670 else if ((ypos >> 1) < (height - B_SIZE)) /* pad right of frame */
1673 src = c_prev + (ypos >> 1) * lx + width - 1;
1677 temp = *(src += lx);
1678 temp |= (temp << 8);
1679 temp |= (temp << 16);
1680 *((ULong*)(dst += lx)) = temp;
1681 *((ULong*)(dst + 4)) = temp;
1683 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1688 else /* pad bottom-right */
1691 src = c_prev + (height - 8) * lx + width - 1;
1704 GetPredAdvBTable[ypos&1][xpos&1](c_prev + (xpos >> 1) + ((ypos >> 1)*lx),
1712 /* ====================================================================== /
1713 Function : Copy_MB_from_Vop()
1715 ====================================================================== */
1717 void Copy_MB_from_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int pitch)
1721 Int offset = pitch - MB_SIZE;
1724 for (i = 0; i < 4; i += 2)
1735 temp = *((ULong*)comp);
1736 *src1++ = (Int)(temp & 0xFF);
1737 *src1++ = (Int)((temp >> 8) & 0xFF);
1738 *src1++ = (Int)((temp >> 16) & 0xFF);
1739 *src1++ = (Int)((temp >> 24) & 0xFF);
1746 temp = *((ULong*)comp);
1747 *src2++ = (Int)(temp & 0xFF);
1748 *src2++ = (Int)((temp >> 8) & 0xFF);
1749 *src2++ = (Int)((temp >> 16) & 0xFF);
1750 *src2++ = (Int)((temp >> 24) & 0xFF);
1760 /* ====================================================================== /
1761 Function : Copy_B_from_Vop()
1763 / ====================================================================== */
1765 void Copy_B_from_Vop(UChar *comp, Int cChan[], Int pitch)
1768 Int offset = pitch - B_SIZE;
1777 temp = *((ULong*)comp);
1778 *cChan++ = (Int)(temp & 0xFF);
1779 *cChan++ = (Int)((temp >> 8) & 0xFF);
1780 *cChan++ = (Int)((temp >> 16) & 0xFF);
1781 *cChan++ = (Int)((temp >> 24) & 0xFF);
1789 /* ====================================================================== /
1790 Function : Copy_MB_into_Vop()
1792 History : From decoder
1793 / ====================================================================== */
1795 void Copy_MB_into_Vop(UChar *comp, Int yChan[][NCOEFF_BLOCK], Int pitch)
1799 Int offset = pitch - MB_SIZE;
1804 for (i = 0; i < 4; i += 2)
1816 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1819 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1820 temp |= (tmp << 16);
1822 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1825 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1827 *((ULong*)comp) = temp;
1835 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1838 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1839 temp |= (tmp << 16);
1841 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1844 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1846 *((ULong*)comp) = temp;
1857 /* ====================================================================== /
1858 Function : Copy_B_into_Vop()
1860 History : From decoder
1861 / ====================================================================== */
1863 void Copy_B_into_Vop(UChar *comp, Int cChan[], Int pitch)
1866 Int offset = pitch - B_SIZE;
1878 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1881 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1882 temp |= (tmp << 16);
1884 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1887 if ((UInt)tmp > mask) tmp = mask & (~(tmp >> 31));
1889 *((ULong*)comp) = temp;
1897 /* ======================================================================== */
1898 /* Function : get_MB( ) */
1899 /* Date : 10/03/2000 */
1900 /* Purpose : Copy 4 Y to reference frame */
1904 /* ======================================================================== */
1905 void get_MB(UChar *c_prev, UChar *c_prev_u , UChar *c_prev_v,
1906 Short mb[6][64], Int lx, Int lx_uv)
1909 Int i, j, count = 0, count1 = 0;
1910 Int k1 = lx - MB_SIZE, k2 = lx_uv - B_SIZE;
1912 for (i = 0; i < B_SIZE; i++)
1914 for (j = 0; j < B_SIZE; j++)
1916 mb[0][count] = (Int)(*c_prev++);
1917 mb[4][count] = (Int)(*c_prev_u++);
1918 mb[5][count++] = (Int)(*c_prev_v++);
1921 for (j = 0; j < B_SIZE; j++)
1922 mb[1][count1++] = (Int)(*c_prev++);
1932 for (i = 0; i < B_SIZE; i++)
1934 for (j = 0; j < B_SIZE; j++)
1935 mb[2][count++] = (Int)(*c_prev++);
1937 for (j = 0; j < B_SIZE; j++)
1938 mb[3][count1++] = (Int)(*c_prev++);
1944 void PutSkippedBlock(UChar *rec, UChar *prev, Int lx)
1947 Int offset = (lx - 8) >> 2;
1953 end = prev + (lx << 3);
1962 while ((UInt)src < (UInt)end);