Revision: | 22 |

Committed: | Mon Jul 7 22:16:37 2008 UTC (11 years, 3 months ago) by wdelano |

File size: | 29297 byte(s) |

Log Message: | initial checkin of mpeg_encode source |

Line | File contents |
---|---|

1 | /*===========================================================================* |

2 | * subsample.c * |

3 | * * |

4 | * Procedures concerned with subsampling * |

5 | * * |

6 | * EXPORTED PROCEDURES: * |

7 | * LumMotionErrorA * |

8 | * LumMotionErrorB * |

9 | * LumMotionErrorC * |

10 | * LumMotionErrorD * |

11 | * * |

12 | *===========================================================================*/ |

13 | |

14 | /* |

15 | * Copyright (c) 1995 The Regents of the University of California. |

16 | * All rights reserved. |

17 | * |

18 | * Permission to use, copy, modify, and distribute this software and its |

19 | * documentation for any purpose, without fee, and without written agreement is |

20 | * hereby granted, provided that the above copyright notice and the following |

21 | * two paragraphs appear in all copies of this software. |

22 | * |

23 | * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR |

24 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |

25 | * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF |

26 | * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |

27 | * |

28 | * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, |

29 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |

30 | * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |

31 | * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO |

32 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |

33 | */ |

34 | |

35 | /* |

36 | * $Header: /n/charlie-brown/project/mm/mpeg/mpeg_dist/mpeg_encode/RCS/subsample.c,v 1.6 1995/01/19 23:09:28 eyhung Exp $ |

37 | * $Log: subsample.c,v $ |

38 | * Revision 1.6 1995/01/19 23:09:28 eyhung |

39 | * Changed copyrights |

40 | * |

41 | * Revision 1.5 1994/11/12 02:12:01 keving |

42 | * nothing |

43 | * |

44 | * Revision 1.4 1993/12/22 19:19:01 keving |

45 | * nothing |

46 | * |

47 | * Revision 1.4 1993/12/22 19:19:01 keving |

48 | * nothing |

49 | * |

50 | * Revision 1.3 1993/07/22 22:23:43 keving |

51 | * nothing |

52 | * |

53 | * Revision 1.2 1993/06/30 20:06:09 keving |

54 | * nothing |

55 | * |

56 | * Revision 1.1 1993/06/22 21:56:05 keving |

57 | * nothing |

58 | * |

59 | */ |

60 | |

61 | |

62 | /*==============* |

63 | * HEADER FILES * |

64 | *==============*/ |

65 | |

66 | #include "all.h" |

67 | #include "mtypes.h" |

68 | #include "frames.h" |

69 | #include "bitio.h" |

70 | #include "prototypes.h" |

71 | |

72 | #undef ABS |

73 | #define ABS(x) ((x < 0) ? (-x) : x) |

74 | |

75 | |

76 | /*=====================* |

77 | * EXPORTED PROCEDURES * |

78 | *=====================*/ |

79 | |

80 | |

81 | /*===========================================================================* |

82 | * |

83 | * LumMotionErrorA |

84 | * |

85 | * compute the motion error for the A subsampling pattern |

86 | * |

87 | * RETURNS: the error, or some number greater if it is worse |

88 | * |

89 | * SIDE EFFECTS: none |

90 | * |

91 | *===========================================================================*/ |

92 | int32 |

93 | LumMotionErrorA(currentBlock, prevFrame, by, bx, my, mx, bestSoFar) |

94 | LumBlock currentBlock; |

95 | MpegFrame *prevFrame; |

96 | int by; |

97 | int bx; |

98 | int my; |

99 | int mx; |

100 | int32 bestSoFar; |

101 | { |

102 | register int32 diff = 0; /* max value of diff is 255*256 = 65280 */ |

103 | register int32 localDiff; |

104 | register uint8 *macross; |

105 | register uint8 **prev; |

106 | register int fy, fx; |

107 | boolean xHalf, yHalf; |

108 | |

109 | xHalf = (ABS(mx) % 2 == 1); |

110 | yHalf = (ABS(my) % 2 == 1); |

111 | |

112 | MOTION_TO_FRAME_COORD(by, bx, my/2, mx/2, fy, fx); |

113 | |

114 | if ( xHalf ) { |

115 | if ( mx < 0 ) { |

116 | fx--; |

117 | } |

118 | |

119 | if ( yHalf ) { |

120 | if ( my < 0 ) { |

121 | fy--; |

122 | } |

123 | |

124 | prev = prevFrame->halfBoth; |

125 | } else { |

126 | prev = prevFrame->halfX; |

127 | } |

128 | } else if ( yHalf ) { |

129 | if ( my < 0 ) { |

130 | fy--; |

131 | } |

132 | |

133 | prev = prevFrame->halfY; |

134 | } else { |

135 | prev = prevFrame->ref_y; |

136 | } |

137 | |

138 | macross = &(prev[fy][fx]); |

139 | |

140 | localDiff = macross[0]-currentBlock[0][0]; diff += ABS(localDiff); |

141 | localDiff = macross[2]-currentBlock[0][2]; diff += ABS(localDiff); |

142 | localDiff = macross[4]-currentBlock[0][4]; diff += ABS(localDiff); |

143 | localDiff = macross[6]-currentBlock[0][6]; diff += ABS(localDiff); |

144 | localDiff = macross[8]-currentBlock[0][8]; diff += ABS(localDiff); |

145 | localDiff = macross[10]-currentBlock[0][10]; diff += ABS(localDiff); |

146 | localDiff = macross[12]-currentBlock[0][12]; diff += ABS(localDiff); |

147 | localDiff = macross[14]-currentBlock[0][14]; diff += ABS(localDiff); |

148 | |

149 | if ( diff > bestSoFar ) { |

150 | return diff; |

151 | } |

152 | |

153 | macross = &(prev[fy+2][fx]); |

154 | |

155 | localDiff = macross[0]-currentBlock[2][0]; diff += ABS(localDiff); |

156 | localDiff = macross[2]-currentBlock[2][2]; diff += ABS(localDiff); |

157 | localDiff = macross[4]-currentBlock[2][4]; diff += ABS(localDiff); |

158 | localDiff = macross[6]-currentBlock[2][6]; diff += ABS(localDiff); |

159 | localDiff = macross[8]-currentBlock[2][8]; diff += ABS(localDiff); |

160 | localDiff = macross[10]-currentBlock[2][10]; diff += ABS(localDiff); |

161 | localDiff = macross[12]-currentBlock[2][12]; diff += ABS(localDiff); |

162 | localDiff = macross[14]-currentBlock[2][14]; diff += ABS(localDiff); |

163 | |

164 | if ( diff > bestSoFar ) { |

165 | return diff; |

166 | } |

167 | |

168 | macross = &(prev[fy+4][fx]); |

169 | |

170 | localDiff = macross[0]-currentBlock[4][0]; diff += ABS(localDiff); |

171 | localDiff = macross[2]-currentBlock[4][2]; diff += ABS(localDiff); |

172 | localDiff = macross[4]-currentBlock[4][4]; diff += ABS(localDiff); |

173 | localDiff = macross[6]-currentBlock[4][6]; diff += ABS(localDiff); |

174 | localDiff = macross[8]-currentBlock[4][8]; diff += ABS(localDiff); |

175 | localDiff = macross[10]-currentBlock[4][10]; diff += ABS(localDiff); |

176 | localDiff = macross[12]-currentBlock[4][12]; diff += ABS(localDiff); |

177 | localDiff = macross[14]-currentBlock[4][14]; diff += ABS(localDiff); |

178 | |

179 | if ( diff > bestSoFar ) { |

180 | return diff; |

181 | } |

182 | |

183 | macross = &(prev[fy+6][fx]); |

184 | |

185 | localDiff = macross[0]-currentBlock[6][0]; diff += ABS(localDiff); |

186 | localDiff = macross[2]-currentBlock[6][2]; diff += ABS(localDiff); |

187 | localDiff = macross[4]-currentBlock[6][4]; diff += ABS(localDiff); |

188 | localDiff = macross[6]-currentBlock[6][6]; diff += ABS(localDiff); |

189 | localDiff = macross[8]-currentBlock[6][8]; diff += ABS(localDiff); |

190 | localDiff = macross[10]-currentBlock[6][10]; diff += ABS(localDiff); |

191 | localDiff = macross[12]-currentBlock[6][12]; diff += ABS(localDiff); |

192 | localDiff = macross[14]-currentBlock[6][14]; diff += ABS(localDiff); |

193 | |

194 | if ( diff > bestSoFar ) { |

195 | return diff; |

196 | } |

197 | |

198 | macross = &(prev[fy+8][fx]); |

199 | |

200 | localDiff = macross[0]-currentBlock[8][0]; diff += ABS(localDiff); |

201 | localDiff = macross[2]-currentBlock[8][2]; diff += ABS(localDiff); |

202 | localDiff = macross[4]-currentBlock[8][4]; diff += ABS(localDiff); |

203 | localDiff = macross[6]-currentBlock[8][6]; diff += ABS(localDiff); |

204 | localDiff = macross[8]-currentBlock[8][8]; diff += ABS(localDiff); |

205 | localDiff = macross[10]-currentBlock[8][10]; diff += ABS(localDiff); |

206 | localDiff = macross[12]-currentBlock[8][12]; diff += ABS(localDiff); |

207 | localDiff = macross[14]-currentBlock[8][14]; diff += ABS(localDiff); |

208 | |

209 | if ( diff > bestSoFar ) { |

210 | return diff; |

211 | } |

212 | |

213 | macross = &(prev[fy+10][fx]); |

214 | |

215 | localDiff = macross[0]-currentBlock[10][0]; diff += ABS(localDiff); |

216 | localDiff = macross[2]-currentBlock[10][2]; diff += ABS(localDiff); |

217 | localDiff = macross[4]-currentBlock[10][4]; diff += ABS(localDiff); |

218 | localDiff = macross[6]-currentBlock[10][6]; diff += ABS(localDiff); |

219 | localDiff = macross[8]-currentBlock[10][8]; diff += ABS(localDiff); |

220 | localDiff = macross[10]-currentBlock[10][10]; diff += ABS(localDiff); |

221 | localDiff = macross[12]-currentBlock[10][12]; diff += ABS(localDiff); |

222 | localDiff = macross[14]-currentBlock[10][14]; diff += ABS(localDiff); |

223 | |

224 | if ( diff > bestSoFar ) { |

225 | return diff; |

226 | } |

227 | |

228 | macross = &(prev[fy+12][fx]); |

229 | |

230 | localDiff = macross[0]-currentBlock[12][0]; diff += ABS(localDiff); |

231 | localDiff = macross[2]-currentBlock[12][2]; diff += ABS(localDiff); |

232 | localDiff = macross[4]-currentBlock[12][4]; diff += ABS(localDiff); |

233 | localDiff = macross[6]-currentBlock[12][6]; diff += ABS(localDiff); |

234 | localDiff = macross[8]-currentBlock[12][8]; diff += ABS(localDiff); |

235 | localDiff = macross[10]-currentBlock[12][10]; diff += ABS(localDiff); |

236 | localDiff = macross[12]-currentBlock[12][12]; diff += ABS(localDiff); |

237 | localDiff = macross[14]-currentBlock[12][14]; diff += ABS(localDiff); |

238 | |

239 | if ( diff > bestSoFar ) { |

240 | return diff; |

241 | } |

242 | |

243 | macross = &(prev[fy+14][fx]); |

244 | |

245 | localDiff = macross[0]-currentBlock[14][0]; diff += ABS(localDiff); |

246 | localDiff = macross[2]-currentBlock[14][2]; diff += ABS(localDiff); |

247 | localDiff = macross[4]-currentBlock[14][4]; diff += ABS(localDiff); |

248 | localDiff = macross[6]-currentBlock[14][6]; diff += ABS(localDiff); |

249 | localDiff = macross[8]-currentBlock[14][8]; diff += ABS(localDiff); |

250 | localDiff = macross[10]-currentBlock[14][10]; diff += ABS(localDiff); |

251 | localDiff = macross[12]-currentBlock[14][12]; diff += ABS(localDiff); |

252 | localDiff = macross[14]-currentBlock[14][14]; diff += ABS(localDiff); |

253 | |

254 | return diff; |

255 | } |

256 | |

257 | |

258 | /*===========================================================================* |

259 | * |

260 | * LumMotionErrorB |

261 | * |

262 | * compute the motion error for the B subsampling pattern |

263 | * |

264 | * RETURNS: the error, or some number greater if it is worse |

265 | * |

266 | * SIDE EFFECTS: none |

267 | * |

268 | *===========================================================================*/ |

269 | int32 |

270 | LumMotionErrorB(currentBlock, prevFrame, by, bx, my, mx, bestSoFar) |

271 | LumBlock currentBlock; |

272 | MpegFrame *prevFrame; |

273 | int by; |

274 | int bx; |

275 | int my; |

276 | int mx; |

277 | int32 bestSoFar; |

278 | { |

279 | register int32 diff = 0; /* max value of diff is 255*256 = 65280 */ |

280 | register int32 localDiff; |

281 | register uint8 *macross; |

282 | register uint8 **prev; |

283 | register int fy, fx; |

284 | boolean xHalf, yHalf; |

285 | |

286 | xHalf = (ABS(mx) % 2 == 1); |

287 | yHalf = (ABS(my) % 2 == 1); |

288 | |

289 | MOTION_TO_FRAME_COORD(by, bx, my/2, mx/2, fy, fx); |

290 | |

291 | if ( xHalf ) { |

292 | if ( mx < 0 ) { |

293 | fx--; |

294 | } |

295 | |

296 | if ( yHalf ) { |

297 | if ( my < 0 ) { |

298 | fy--; |

299 | } |

300 | |

301 | prev = prevFrame->halfBoth; |

302 | } else { |

303 | prev = prevFrame->halfX; |

304 | } |

305 | } else if ( yHalf ) { |

306 | if ( my < 0 ) { |

307 | fy--; |

308 | } |

309 | |

310 | prev = prevFrame->halfY; |

311 | } else { |

312 | prev = prevFrame->ref_y; |

313 | } |

314 | |

315 | macross = &(prev[fy+0][fx]); |

316 | |

317 | localDiff = macross[1]-currentBlock[0][1]; diff += ABS(localDiff); |

318 | localDiff = macross[3]-currentBlock[0][3]; diff += ABS(localDiff); |

319 | localDiff = macross[5]-currentBlock[0][5]; diff += ABS(localDiff); |

320 | localDiff = macross[7]-currentBlock[0][7]; diff += ABS(localDiff); |

321 | localDiff = macross[9]-currentBlock[0][9]; diff += ABS(localDiff); |

322 | localDiff = macross[11]-currentBlock[0][11]; diff += ABS(localDiff); |

323 | localDiff = macross[13]-currentBlock[0][13]; diff += ABS(localDiff); |

324 | localDiff = macross[15]-currentBlock[0][15]; diff += ABS(localDiff); |

325 | |

326 | if ( diff > bestSoFar ) { |

327 | return diff; |

328 | } |

329 | |

330 | macross = &(prev[fy+2][fx]); |

331 | |

332 | localDiff = macross[1]-currentBlock[2][1]; diff += ABS(localDiff); |

333 | localDiff = macross[3]-currentBlock[2][3]; diff += ABS(localDiff); |

334 | localDiff = macross[5]-currentBlock[2][5]; diff += ABS(localDiff); |

335 | localDiff = macross[7]-currentBlock[2][7]; diff += ABS(localDiff); |

336 | localDiff = macross[9]-currentBlock[2][9]; diff += ABS(localDiff); |

337 | localDiff = macross[11]-currentBlock[2][11]; diff += ABS(localDiff); |

338 | localDiff = macross[13]-currentBlock[2][13]; diff += ABS(localDiff); |

339 | localDiff = macross[15]-currentBlock[2][15]; diff += ABS(localDiff); |

340 | |

341 | if ( diff > bestSoFar ) { |

342 | return diff; |

343 | } |

344 | |

345 | macross = &(prev[fy+4][fx]); |

346 | |

347 | localDiff = macross[1]-currentBlock[4][1]; diff += ABS(localDiff); |

348 | localDiff = macross[3]-currentBlock[4][3]; diff += ABS(localDiff); |

349 | localDiff = macross[5]-currentBlock[4][5]; diff += ABS(localDiff); |

350 | localDiff = macross[7]-currentBlock[4][7]; diff += ABS(localDiff); |

351 | localDiff = macross[9]-currentBlock[4][9]; diff += ABS(localDiff); |

352 | localDiff = macross[11]-currentBlock[4][11]; diff += ABS(localDiff); |

353 | localDiff = macross[13]-currentBlock[4][13]; diff += ABS(localDiff); |

354 | localDiff = macross[15]-currentBlock[4][15]; diff += ABS(localDiff); |

355 | |

356 | if ( diff > bestSoFar ) { |

357 | return diff; |

358 | } |

359 | |

360 | macross = &(prev[fy+6][fx]); |

361 | |

362 | localDiff = macross[1]-currentBlock[6][1]; diff += ABS(localDiff); |

363 | localDiff = macross[3]-currentBlock[6][3]; diff += ABS(localDiff); |

364 | localDiff = macross[5]-currentBlock[6][5]; diff += ABS(localDiff); |

365 | localDiff = macross[7]-currentBlock[6][7]; diff += ABS(localDiff); |

366 | localDiff = macross[9]-currentBlock[6][9]; diff += ABS(localDiff); |

367 | localDiff = macross[11]-currentBlock[6][11]; diff += ABS(localDiff); |

368 | localDiff = macross[13]-currentBlock[6][13]; diff += ABS(localDiff); |

369 | localDiff = macross[15]-currentBlock[6][15]; diff += ABS(localDiff); |

370 | |

371 | if ( diff > bestSoFar ) { |

372 | return diff; |

373 | } |

374 | |

375 | macross = &(prev[fy+8][fx]); |

376 | |

377 | localDiff = macross[1]-currentBlock[8][1]; diff += ABS(localDiff); |

378 | localDiff = macross[3]-currentBlock[8][3]; diff += ABS(localDiff); |

379 | localDiff = macross[5]-currentBlock[8][5]; diff += ABS(localDiff); |

380 | localDiff = macross[7]-currentBlock[8][7]; diff += ABS(localDiff); |

381 | localDiff = macross[9]-currentBlock[8][9]; diff += ABS(localDiff); |

382 | localDiff = macross[11]-currentBlock[8][11]; diff += ABS(localDiff); |

383 | localDiff = macross[13]-currentBlock[8][13]; diff += ABS(localDiff); |

384 | localDiff = macross[15]-currentBlock[8][15]; diff += ABS(localDiff); |

385 | |

386 | if ( diff > bestSoFar ) { |

387 | return diff; |

388 | } |

389 | |

390 | macross = &(prev[fy+10][fx]); |

391 | |

392 | localDiff = macross[1]-currentBlock[10][1]; diff += ABS(localDiff); |

393 | localDiff = macross[3]-currentBlock[10][3]; diff += ABS(localDiff); |

394 | localDiff = macross[5]-currentBlock[10][5]; diff += ABS(localDiff); |

395 | localDiff = macross[7]-currentBlock[10][7]; diff += ABS(localDiff); |

396 | localDiff = macross[9]-currentBlock[10][9]; diff += ABS(localDiff); |

397 | localDiff = macross[11]-currentBlock[10][11]; diff += ABS(localDiff); |

398 | localDiff = macross[13]-currentBlock[10][13]; diff += ABS(localDiff); |

399 | localDiff = macross[15]-currentBlock[10][15]; diff += ABS(localDiff); |

400 | |

401 | if ( diff > bestSoFar ) { |

402 | return diff; |

403 | } |

404 | |

405 | macross = &(prev[fy+12][fx]); |

406 | |

407 | localDiff = macross[1]-currentBlock[12][1]; diff += ABS(localDiff); |

408 | localDiff = macross[3]-currentBlock[12][3]; diff += ABS(localDiff); |

409 | localDiff = macross[5]-currentBlock[12][5]; diff += ABS(localDiff); |

410 | localDiff = macross[7]-currentBlock[12][7]; diff += ABS(localDiff); |

411 | localDiff = macross[9]-currentBlock[12][9]; diff += ABS(localDiff); |

412 | localDiff = macross[11]-currentBlock[12][11]; diff += ABS(localDiff); |

413 | localDiff = macross[13]-currentBlock[12][13]; diff += ABS(localDiff); |

414 | localDiff = macross[15]-currentBlock[12][15]; diff += ABS(localDiff); |

415 | |

416 | if ( diff > bestSoFar ) { |

417 | return diff; |

418 | } |

419 | |

420 | macross = &(prev[fy+14][fx]); |

421 | |

422 | localDiff = macross[1]-currentBlock[14][1]; diff += ABS(localDiff); |

423 | localDiff = macross[3]-currentBlock[14][3]; diff += ABS(localDiff); |

424 | localDiff = macross[5]-currentBlock[14][5]; diff += ABS(localDiff); |

425 | localDiff = macross[7]-currentBlock[14][7]; diff += ABS(localDiff); |

426 | localDiff = macross[9]-currentBlock[14][9]; diff += ABS(localDiff); |

427 | localDiff = macross[11]-currentBlock[14][11]; diff += ABS(localDiff); |

428 | localDiff = macross[13]-currentBlock[14][13]; diff += ABS(localDiff); |

429 | localDiff = macross[15]-currentBlock[14][15]; diff += ABS(localDiff); |

430 | |

431 | return diff; |

432 | } |

433 | |

434 | |

435 | /*===========================================================================* |

436 | * |

437 | * LumMotionErrorC |

438 | * |

439 | * compute the motion error for the C subsampling pattern |

440 | * |

441 | * RETURNS: the error, or some number greater if it is worse |

442 | * |

443 | * SIDE EFFECTS: none |

444 | * |

445 | *===========================================================================*/ |

446 | int32 |

447 | LumMotionErrorC(currentBlock, prevFrame, by, bx, my, mx, bestSoFar) |

448 | LumBlock currentBlock; |

449 | MpegFrame *prevFrame; |

450 | int by; |

451 | int bx; |

452 | int my; |

453 | int mx; |

454 | int32 bestSoFar; |

455 | { |

456 | register int32 diff = 0; /* max value of diff is 255*256 = 65280 */ |

457 | register int32 localDiff; |

458 | register uint8 *macross; |

459 | register uint8 **prev; |

460 | register int fy, fx; |

461 | boolean xHalf, yHalf; |

462 | |

463 | xHalf = (ABS(mx) % 2 == 1); |

464 | yHalf = (ABS(my) % 2 == 1); |

465 | |

466 | MOTION_TO_FRAME_COORD(by, bx, my/2, mx/2, fy, fx); |

467 | |

468 | if ( xHalf ) { |

469 | if ( mx < 0 ) { |

470 | fx--; |

471 | } |

472 | |

473 | if ( yHalf ) { |

474 | if ( my < 0 ) { |

475 | fy--; |

476 | } |

477 | |

478 | prev = prevFrame->halfBoth; |

479 | } else { |

480 | prev = prevFrame->halfX; |

481 | } |

482 | } else if ( yHalf ) { |

483 | if ( my < 0 ) { |

484 | fy--; |

485 | } |

486 | |

487 | prev = prevFrame->halfY; |

488 | } else { |

489 | prev = prevFrame->ref_y; |

490 | } |

491 | |

492 | macross = &(prev[fy+1][fx]); |

493 | |

494 | localDiff = macross[0]-currentBlock[1][0]; diff += ABS(localDiff); |

495 | localDiff = macross[2]-currentBlock[1][2]; diff += ABS(localDiff); |

496 | localDiff = macross[4]-currentBlock[1][4]; diff += ABS(localDiff); |

497 | localDiff = macross[6]-currentBlock[1][6]; diff += ABS(localDiff); |

498 | localDiff = macross[8]-currentBlock[1][8]; diff += ABS(localDiff); |

499 | localDiff = macross[10]-currentBlock[1][10]; diff += ABS(localDiff); |

500 | localDiff = macross[12]-currentBlock[1][12]; diff += ABS(localDiff); |

501 | localDiff = macross[14]-currentBlock[1][14]; diff += ABS(localDiff); |

502 | |

503 | if ( diff > bestSoFar ) { |

504 | return diff; |

505 | } |

506 | |

507 | macross = &(prev[fy+3][fx]); |

508 | |

509 | localDiff = macross[0]-currentBlock[3][0]; diff += ABS(localDiff); |

510 | localDiff = macross[2]-currentBlock[3][2]; diff += ABS(localDiff); |

511 | localDiff = macross[4]-currentBlock[3][4]; diff += ABS(localDiff); |

512 | localDiff = macross[6]-currentBlock[3][6]; diff += ABS(localDiff); |

513 | localDiff = macross[8]-currentBlock[3][8]; diff += ABS(localDiff); |

514 | localDiff = macross[10]-currentBlock[3][10]; diff += ABS(localDiff); |

515 | localDiff = macross[12]-currentBlock[3][12]; diff += ABS(localDiff); |

516 | localDiff = macross[14]-currentBlock[3][14]; diff += ABS(localDiff); |

517 | |

518 | if ( diff > bestSoFar ) { |

519 | return diff; |

520 | } |

521 | |

522 | macross = &(prev[fy+5][fx]); |

523 | |

524 | localDiff = macross[0]-currentBlock[5][0]; diff += ABS(localDiff); |

525 | localDiff = macross[2]-currentBlock[5][2]; diff += ABS(localDiff); |

526 | localDiff = macross[4]-currentBlock[5][4]; diff += ABS(localDiff); |

527 | localDiff = macross[6]-currentBlock[5][6]; diff += ABS(localDiff); |

528 | localDiff = macross[8]-currentBlock[5][8]; diff += ABS(localDiff); |

529 | localDiff = macross[10]-currentBlock[5][10]; diff += ABS(localDiff); |

530 | localDiff = macross[12]-currentBlock[5][12]; diff += ABS(localDiff); |

531 | localDiff = macross[14]-currentBlock[5][14]; diff += ABS(localDiff); |

532 | |

533 | if ( diff > bestSoFar ) { |

534 | return diff; |

535 | } |

536 | |

537 | macross = &(prev[fy+7][fx]); |

538 | |

539 | localDiff = macross[0]-currentBlock[7][0]; diff += ABS(localDiff); |

540 | localDiff = macross[2]-currentBlock[7][2]; diff += ABS(localDiff); |

541 | localDiff = macross[4]-currentBlock[7][4]; diff += ABS(localDiff); |

542 | localDiff = macross[6]-currentBlock[7][6]; diff += ABS(localDiff); |

543 | localDiff = macross[8]-currentBlock[7][8]; diff += ABS(localDiff); |

544 | localDiff = macross[10]-currentBlock[7][10]; diff += ABS(localDiff); |

545 | localDiff = macross[12]-currentBlock[7][12]; diff += ABS(localDiff); |

546 | localDiff = macross[14]-currentBlock[7][14]; diff += ABS(localDiff); |

547 | |

548 | if ( diff > bestSoFar ) { |

549 | return diff; |

550 | } |

551 | |

552 | macross = &(prev[fy+9][fx]); |

553 | |

554 | localDiff = macross[0]-currentBlock[9][0]; diff += ABS(localDiff); |

555 | localDiff = macross[2]-currentBlock[9][2]; diff += ABS(localDiff); |

556 | localDiff = macross[4]-currentBlock[9][4]; diff += ABS(localDiff); |

557 | localDiff = macross[6]-currentBlock[9][6]; diff += ABS(localDiff); |

558 | localDiff = macross[8]-currentBlock[9][8]; diff += ABS(localDiff); |

559 | localDiff = macross[10]-currentBlock[9][10]; diff += ABS(localDiff); |

560 | localDiff = macross[12]-currentBlock[9][12]; diff += ABS(localDiff); |

561 | localDiff = macross[14]-currentBlock[9][14]; diff += ABS(localDiff); |

562 | |

563 | if ( diff > bestSoFar ) { |

564 | return diff; |

565 | } |

566 | |

567 | macross = &(prev[fy+11][fx]); |

568 | |

569 | localDiff = macross[0]-currentBlock[11][0]; diff += ABS(localDiff); |

570 | localDiff = macross[2]-currentBlock[11][2]; diff += ABS(localDiff); |

571 | localDiff = macross[4]-currentBlock[11][4]; diff += ABS(localDiff); |

572 | localDiff = macross[6]-currentBlock[11][6]; diff += ABS(localDiff); |

573 | localDiff = macross[8]-currentBlock[11][8]; diff += ABS(localDiff); |

574 | localDiff = macross[10]-currentBlock[11][10]; diff += ABS(localDiff); |

575 | localDiff = macross[12]-currentBlock[11][12]; diff += ABS(localDiff); |

576 | localDiff = macross[14]-currentBlock[11][14]; diff += ABS(localDiff); |

577 | |

578 | if ( diff > bestSoFar ) { |

579 | return diff; |

580 | } |

581 | |

582 | macross = &(prev[fy+13][fx]); |

583 | |

584 | localDiff = macross[0]-currentBlock[13][0]; diff += ABS(localDiff); |

585 | localDiff = macross[2]-currentBlock[13][2]; diff += ABS(localDiff); |

586 | localDiff = macross[4]-currentBlock[13][4]; diff += ABS(localDiff); |

587 | localDiff = macross[6]-currentBlock[13][6]; diff += ABS(localDiff); |

588 | localDiff = macross[8]-currentBlock[13][8]; diff += ABS(localDiff); |

589 | localDiff = macross[10]-currentBlock[13][10]; diff += ABS(localDiff); |

590 | localDiff = macross[12]-currentBlock[13][12]; diff += ABS(localDiff); |

591 | localDiff = macross[14]-currentBlock[13][14]; diff += ABS(localDiff); |

592 | |

593 | if ( diff > bestSoFar ) { |

594 | return diff; |

595 | } |

596 | |

597 | macross = &(prev[fy+15][fx]); |

598 | |

599 | localDiff = macross[0]-currentBlock[15][0]; diff += ABS(localDiff); |

600 | localDiff = macross[2]-currentBlock[15][2]; diff += ABS(localDiff); |

601 | localDiff = macross[4]-currentBlock[15][4]; diff += ABS(localDiff); |

602 | localDiff = macross[6]-currentBlock[15][6]; diff += ABS(localDiff); |

603 | localDiff = macross[8]-currentBlock[15][8]; diff += ABS(localDiff); |

604 | localDiff = macross[10]-currentBlock[15][10]; diff += ABS(localDiff); |

605 | localDiff = macross[12]-currentBlock[15][12]; diff += ABS(localDiff); |

606 | localDiff = macross[14]-currentBlock[15][14]; diff += ABS(localDiff); |

607 | |

608 | return diff; |

609 | } |

610 | |

611 | |

612 | /*===========================================================================* |

613 | * |

614 | * LumMotionErrorD |

615 | * |

616 | * compute the motion error for the D subsampling pattern |

617 | * |

618 | * RETURNS: the error, or some number greater if it is worse |

619 | * |

620 | * SIDE EFFECTS: none |

621 | * |

622 | *===========================================================================*/ |

623 | int32 |

624 | LumMotionErrorD(currentBlock, prevFrame, by, bx, my, mx, bestSoFar) |

625 | LumBlock currentBlock; |

626 | MpegFrame *prevFrame; |

627 | int by; |

628 | int bx; |

629 | int my; |

630 | int mx; |

631 | int32 bestSoFar; |

632 | { |

633 | register int32 diff = 0; /* max value of diff is 255*256 = 65280 */ |

634 | register int32 localDiff; |

635 | register uint8 *macross; |

636 | register uint8 **prev; |

637 | register int fy, fx; |

638 | boolean xHalf, yHalf; |

639 | |

640 | xHalf = (ABS(mx) % 2 == 1); |

641 | yHalf = (ABS(my) % 2 == 1); |

642 | |

643 | MOTION_TO_FRAME_COORD(by, bx, my/2, mx/2, fy, fx); |

644 | |

645 | if ( xHalf ) { |

646 | if ( mx < 0 ) { |

647 | fx--; |

648 | } |

649 | |

650 | if ( yHalf ) { |

651 | if ( my < 0 ) { |

652 | fy--; |

653 | } |

654 | prev = prevFrame->halfBoth; |

655 | } else { |

656 | prev = prevFrame->halfX; |

657 | } |

658 | } else if ( yHalf ) { |

659 | if ( my < 0 ) { |

660 | fy--; |

661 | } |

662 | prev = prevFrame->halfY; |

663 | } else { |

664 | prev = prevFrame->ref_y; |

665 | } |

666 | |

667 | macross = &(prev[fy+1][fx]); |

668 | |

669 | localDiff = macross[1]-currentBlock[1][1]; diff += ABS(localDiff); |

670 | localDiff = macross[3]-currentBlock[1][3]; diff += ABS(localDiff); |

671 | localDiff = macross[5]-currentBlock[1][5]; diff += ABS(localDiff); |

672 | localDiff = macross[7]-currentBlock[1][7]; diff += ABS(localDiff); |

673 | localDiff = macross[9]-currentBlock[1][9]; diff += ABS(localDiff); |

674 | localDiff = macross[11]-currentBlock[1][11]; diff += ABS(localDiff); |

675 | localDiff = macross[13]-currentBlock[1][13]; diff += ABS(localDiff); |

676 | localDiff = macross[15]-currentBlock[1][15]; diff += ABS(localDiff); |

677 | |

678 | if ( diff > bestSoFar ) { |

679 | return diff; |

680 | } |

681 | |

682 | macross = &(prev[fy+3][fx]); |

683 | |

684 | localDiff = macross[1]-currentBlock[3][1]; diff += ABS(localDiff); |

685 | localDiff = macross[3]-currentBlock[3][3]; diff += ABS(localDiff); |

686 | localDiff = macross[5]-currentBlock[3][5]; diff += ABS(localDiff); |

687 | localDiff = macross[7]-currentBlock[3][7]; diff += ABS(localDiff); |

688 | localDiff = macross[9]-currentBlock[3][9]; diff += ABS(localDiff); |

689 | localDiff = macross[11]-currentBlock[3][11]; diff += ABS(localDiff); |

690 | localDiff = macross[13]-currentBlock[3][13]; diff += ABS(localDiff); |

691 | localDiff = macross[15]-currentBlock[3][15]; diff += ABS(localDiff); |

692 | |

693 | if ( diff > bestSoFar ) { |

694 | return diff; |

695 | } |

696 | |

697 | macross = &(prev[fy+5][fx]); |

698 | |

699 | localDiff = macross[1]-currentBlock[5][1]; diff += ABS(localDiff); |

700 | localDiff = macross[3]-currentBlock[5][3]; diff += ABS(localDiff); |

701 | localDiff = macross[5]-currentBlock[5][5]; diff += ABS(localDiff); |

702 | localDiff = macross[7]-currentBlock[5][7]; diff += ABS(localDiff); |

703 | localDiff = macross[9]-currentBlock[5][9]; diff += ABS(localDiff); |

704 | localDiff = macross[11]-currentBlock[5][11]; diff += ABS(localDiff); |

705 | localDiff = macross[13]-currentBlock[5][13]; diff += ABS(localDiff); |

706 | localDiff = macross[15]-currentBlock[5][15]; diff += ABS(localDiff); |

707 | |

708 | if ( diff > bestSoFar ) { |

709 | return diff; |

710 | } |

711 | |

712 | macross = &(prev[fy+7][fx]); |

713 | |

714 | localDiff = macross[1]-currentBlock[7][1]; diff += ABS(localDiff); |

715 | localDiff = macross[3]-currentBlock[7][3]; diff += ABS(localDiff); |

716 | localDiff = macross[5]-currentBlock[7][5]; diff += ABS(localDiff); |

717 | localDiff = macross[7]-currentBlock[7][7]; diff += ABS(localDiff); |

718 | localDiff = macross[9]-currentBlock[7][9]; diff += ABS(localDiff); |

719 | localDiff = macross[11]-currentBlock[7][11]; diff += ABS(localDiff); |

720 | localDiff = macross[13]-currentBlock[7][13]; diff += ABS(localDiff); |

721 | localDiff = macross[15]-currentBlock[7][15]; diff += ABS(localDiff); |

722 | |

723 | if ( diff > bestSoFar ) { |

724 | return diff; |

725 | } |

726 | |

727 | macross = &(prev[fy+9][fx]); |

728 | |

729 | localDiff = macross[1]-currentBlock[9][1]; diff += ABS(localDiff); |

730 | localDiff = macross[3]-currentBlock[9][3]; diff += ABS(localDiff); |

731 | localDiff = macross[5]-currentBlock[9][5]; diff += ABS(localDiff); |

732 | localDiff = macross[7]-currentBlock[9][7]; diff += ABS(localDiff); |

733 | localDiff = macross[9]-currentBlock[9][9]; diff += ABS(localDiff); |

734 | localDiff = macross[11]-currentBlock[9][11]; diff += ABS(localDiff); |

735 | localDiff = macross[13]-currentBlock[9][13]; diff += ABS(localDiff); |

736 | localDiff = macross[15]-currentBlock[9][15]; diff += ABS(localDiff); |

737 | |

738 | if ( diff > bestSoFar ) { |

739 | return diff; |

740 | } |

741 | |

742 | macross = &(prev[fy+11][fx]); |

743 | |

744 | localDiff = macross[1]-currentBlock[11][1]; diff += ABS(localDiff); |

745 | localDiff = macross[3]-currentBlock[11][3]; diff += ABS(localDiff); |

746 | localDiff = macross[5]-currentBlock[11][5]; diff += ABS(localDiff); |

747 | localDiff = macross[7]-currentBlock[11][7]; diff += ABS(localDiff); |

748 | localDiff = macross[9]-currentBlock[11][9]; diff += ABS(localDiff); |

749 | localDiff = macross[11]-currentBlock[11][11]; diff += ABS(localDiff); |

750 | localDiff = macross[13]-currentBlock[11][13]; diff += ABS(localDiff); |

751 | localDiff = macross[15]-currentBlock[11][15]; diff += ABS(localDiff); |

752 | |

753 | if ( diff > bestSoFar ) { |

754 | return diff; |

755 | } |

756 | |

757 | macross = &(prev[fy+13][fx]); |

758 | |

759 | localDiff = macross[1]-currentBlock[13][1]; diff += ABS(localDiff); |

760 | localDiff = macross[3]-currentBlock[13][3]; diff += ABS(localDiff); |

761 | localDiff = macross[5]-currentBlock[13][5]; diff += ABS(localDiff); |

762 | localDiff = macross[7]-currentBlock[13][7]; diff += ABS(localDiff); |

763 | localDiff = macross[9]-currentBlock[13][9]; diff += ABS(localDiff); |

764 | localDiff = macross[11]-currentBlock[13][11]; diff += ABS(localDiff); |

765 | localDiff = macross[13]-currentBlock[13][13]; diff += ABS(localDiff); |

766 | localDiff = macross[15]-currentBlock[13][15]; diff += ABS(localDiff); |

767 | |

768 | if ( diff > bestSoFar ) { |

769 | return diff; |

770 | } |

771 | |

772 | macross = &(prev[fy+15][fx]); |

773 | |

774 | localDiff = macross[1]-currentBlock[15][1]; diff += ABS(localDiff); |

775 | localDiff = macross[3]-currentBlock[15][3]; diff += ABS(localDiff); |

776 | localDiff = macross[5]-currentBlock[15][5]; diff += ABS(localDiff); |

777 | localDiff = macross[7]-currentBlock[15][7]; diff += ABS(localDiff); |

778 | localDiff = macross[9]-currentBlock[15][9]; diff += ABS(localDiff); |

779 | localDiff = macross[11]-currentBlock[15][11]; diff += ABS(localDiff); |

780 | localDiff = macross[13]-currentBlock[15][13]; diff += ABS(localDiff); |

781 | localDiff = macross[15]-currentBlock[15][15]; diff += ABS(localDiff); |

782 | |

783 | return diff; |

784 | } |