| 1 |
/*****************************************************************************/ |
| 2 |
// Copyright 2008-2019 Adobe Systems Incorporated |
| 3 |
// All Rights Reserved. |
| 4 |
// |
| 5 |
// NOTICE: Adobe permits you to use, modify, and distribute this file in |
| 6 |
// accordance with the terms of the Adobe license agreement accompanying it. |
| 7 |
/*****************************************************************************/ |
| 8 |
|
| 9 |
#include "dng_bad_pixels.h" |
| 10 |
|
| 11 |
#include "dng_filter_task.h" |
| 12 |
#include "dng_globals.h" |
| 13 |
#include "dng_host.h" |
| 14 |
#include "dng_image.h" |
| 15 |
#include "dng_negative.h" |
| 16 |
#include "dng_safe_arithmetic.h" |
| 17 |
|
| 18 |
#include <algorithm> |
| 19 |
|
| 20 |
/*****************************************************************************/ |
| 21 |
|
| 22 |
dng_opcode_FixBadPixelsConstant::dng_opcode_FixBadPixelsConstant |
| 23 |
(uint32 constant, |
| 24 |
uint32 bayerPhase) |
| 25 |
|
| 26 |
: dng_filter_opcode (dngOpcode_FixBadPixelsConstant, |
| 27 |
dngVersion_1_3_0_0, |
| 28 |
0) |
| 29 |
|
| 30 |
, fConstant (constant) |
| 31 |
, fBayerPhase (bayerPhase) |
| 32 |
|
| 33 |
{ |
| 34 |
|
| 35 |
} |
| 36 |
|
| 37 |
/*****************************************************************************/ |
| 38 |
|
| 39 |
dng_opcode_FixBadPixelsConstant::dng_opcode_FixBadPixelsConstant |
| 40 |
(dng_stream &stream) |
| 41 |
|
| 42 |
: dng_filter_opcode (dngOpcode_FixBadPixelsConstant, |
| 43 |
stream, |
| 44 |
"FixBadPixelsConstant") |
| 45 |
|
| 46 |
, fConstant (0) |
| 47 |
, fBayerPhase (0) |
| 48 |
|
| 49 |
{ |
| 50 |
|
| 51 |
if (stream.Get_uint32 () != 8) |
| 52 |
{ |
| 53 |
ThrowBadFormat (); |
| 54 |
} |
| 55 |
|
| 56 |
fConstant = stream.Get_uint32 (); |
| 57 |
fBayerPhase = stream.Get_uint32 (); |
| 58 |
|
| 59 |
#if qDNGValidate |
| 60 |
|
| 61 |
if (gVerbose) |
| 62 |
{ |
| 63 |
|
| 64 |
printf ("Constant: %u\n", (unsigned) fConstant); |
| 65 |
|
| 66 |
printf ("Bayer Phase: %u\n", (unsigned) fBayerPhase); |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
#endif |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
/*****************************************************************************/ |
| 75 |
|
| 76 |
void dng_opcode_FixBadPixelsConstant::PutData (dng_stream &stream) const |
| 77 |
{ |
| 78 |
|
| 79 |
stream.Put_uint32 (8); |
| 80 |
|
| 81 |
stream.Put_uint32 (fConstant ); |
| 82 |
stream.Put_uint32 (fBayerPhase); |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
/*****************************************************************************/ |
| 87 |
|
| 88 |
dng_point dng_opcode_FixBadPixelsConstant::SrcRepeat () |
| 89 |
{ |
| 90 |
|
| 91 |
return dng_point (2, 2); |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
/*****************************************************************************/ |
| 96 |
|
| 97 |
dng_rect dng_opcode_FixBadPixelsConstant::SrcArea (const dng_rect &dstArea, |
| 98 |
const dng_rect & /* imageBounds */) |
| 99 |
{ |
| 100 |
|
| 101 |
dng_rect srcArea = dstArea; |
| 102 |
|
| 103 |
srcArea.t -= 2; |
| 104 |
srcArea.l -= 2; |
| 105 |
|
| 106 |
srcArea.b += 2; |
| 107 |
srcArea.r += 2; |
| 108 |
|
| 109 |
return srcArea; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
/*****************************************************************************/ |
| 114 |
|
| 115 |
void dng_opcode_FixBadPixelsConstant::Prepare (dng_negative & /* negative */, |
| 116 |
uint32 /* threadCount */, |
| 117 |
const dng_point & /* tileSize */, |
| 118 |
const dng_rect & /* imageBounds */, |
| 119 |
uint32 imagePlanes, |
| 120 |
uint32 bufferPixelType, |
| 121 |
dng_memory_allocator & /* allocator */) |
| 122 |
{ |
| 123 |
|
| 124 |
// This opcode is restricted to single channel images. |
| 125 |
|
| 126 |
if (imagePlanes != 1) |
| 127 |
{ |
| 128 |
|
| 129 |
ThrowBadFormat (); |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
// This opcode is restricted to 16-bit images. |
| 134 |
|
| 135 |
if (bufferPixelType != ttShort) |
| 136 |
{ |
| 137 |
|
| 138 |
ThrowBadFormat (); |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
/*****************************************************************************/ |
| 145 |
|
| 146 |
void dng_opcode_FixBadPixelsConstant::ProcessArea (dng_negative & /* negative */, |
| 147 |
uint32 /* threadIndex */, |
| 148 |
dng_pixel_buffer &srcBuffer, |
| 149 |
dng_pixel_buffer &dstBuffer, |
| 150 |
const dng_rect &dstArea, |
| 151 |
const dng_rect & /* imageBounds */) |
| 152 |
{ |
| 153 |
|
| 154 |
dstBuffer.CopyArea (srcBuffer, |
| 155 |
dstArea, |
| 156 |
0, |
| 157 |
dstBuffer.fPlanes); |
| 158 |
|
| 159 |
uint16 badPixel = (uint16) fConstant; |
| 160 |
|
| 161 |
for (int32 dstRow = dstArea.t; dstRow < dstArea.b; dstRow++) |
| 162 |
{ |
| 163 |
|
| 164 |
const uint16 *sPtr = srcBuffer.ConstPixel_uint16 (dstRow, dstArea.l, 0); |
| 165 |
uint16 *dPtr = dstBuffer.DirtyPixel_uint16 (dstRow, dstArea.l, 0); |
| 166 |
|
| 167 |
for (int32 dstCol = dstArea.l; dstCol < dstArea.r; dstCol++) |
| 168 |
{ |
| 169 |
|
| 170 |
if (*sPtr == badPixel) |
| 171 |
{ |
| 172 |
|
| 173 |
uint32 count = 0; |
| 174 |
uint32 total = 0; |
| 175 |
|
| 176 |
uint16 value; |
| 177 |
|
| 178 |
if (IsGreen (dstRow, dstCol)) // Green pixel |
| 179 |
{ |
| 180 |
|
| 181 |
value = sPtr [-srcBuffer.fRowStep - 1]; |
| 182 |
|
| 183 |
if (value != badPixel) |
| 184 |
{ |
| 185 |
count += 1; |
| 186 |
total += value; |
| 187 |
} |
| 188 |
|
| 189 |
value = sPtr [-srcBuffer.fRowStep + 1]; |
| 190 |
|
| 191 |
if (value != badPixel) |
| 192 |
{ |
| 193 |
count += 1; |
| 194 |
total += value; |
| 195 |
} |
| 196 |
|
| 197 |
value = sPtr [srcBuffer.fRowStep - 1]; |
| 198 |
|
| 199 |
if (value != badPixel) |
| 200 |
{ |
| 201 |
count += 1; |
| 202 |
total += value; |
| 203 |
} |
| 204 |
|
| 205 |
value = sPtr [srcBuffer.fRowStep + 1]; |
| 206 |
|
| 207 |
if (value != badPixel) |
| 208 |
{ |
| 209 |
count += 1; |
| 210 |
total += value; |
| 211 |
} |
| 212 |
|
| 213 |
} |
| 214 |
|
| 215 |
else // Red/blue pixel. |
| 216 |
{ |
| 217 |
|
| 218 |
value = sPtr [-srcBuffer.fRowStep * 2]; |
| 219 |
|
| 220 |
if (value != badPixel) |
| 221 |
{ |
| 222 |
count += 1; |
| 223 |
total += value; |
| 224 |
} |
| 225 |
|
| 226 |
value = sPtr [srcBuffer.fRowStep * 2]; |
| 227 |
|
| 228 |
if (value != badPixel) |
| 229 |
{ |
| 230 |
count += 1; |
| 231 |
total += value; |
| 232 |
} |
| 233 |
|
| 234 |
value = sPtr [-2]; |
| 235 |
|
| 236 |
if (value != badPixel) |
| 237 |
{ |
| 238 |
count += 1; |
| 239 |
total += value; |
| 240 |
} |
| 241 |
|
| 242 |
value = sPtr [2]; |
| 243 |
|
| 244 |
if (value != badPixel) |
| 245 |
{ |
| 246 |
count += 1; |
| 247 |
total += value; |
| 248 |
} |
| 249 |
|
| 250 |
} |
| 251 |
|
| 252 |
if (count == 4) // Most common case. |
| 253 |
{ |
| 254 |
|
| 255 |
*dPtr = (uint16) ((total + 2) >> 2); |
| 256 |
|
| 257 |
} |
| 258 |
|
| 259 |
else if (count > 0) |
| 260 |
{ |
| 261 |
|
| 262 |
*dPtr = (uint16) ((total + (count >> 1)) / count); |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
} |
| 267 |
|
| 268 |
sPtr++; |
| 269 |
dPtr++; |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
} |
| 274 |
|
| 275 |
} |
| 276 |
|
| 277 |
/*****************************************************************************/ |
| 278 |
|
| 279 |
dng_bad_pixel_list::dng_bad_pixel_list () |
| 280 |
|
| 281 |
: fBadPoints () |
| 282 |
, fBadRects () |
| 283 |
|
| 284 |
{ |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
/*****************************************************************************/ |
| 289 |
|
| 290 |
void dng_bad_pixel_list::AddPoint (const dng_point &pt) |
| 291 |
{ |
| 292 |
|
| 293 |
fBadPoints.push_back (pt); |
| 294 |
|
| 295 |
} |
| 296 |
|
| 297 |
/*****************************************************************************/ |
| 298 |
|
| 299 |
void dng_bad_pixel_list::AddRect (const dng_rect &r) |
| 300 |
{ |
| 301 |
|
| 302 |
fBadRects.push_back (r); |
| 303 |
|
| 304 |
} |
| 305 |
|
| 306 |
/*****************************************************************************/ |
| 307 |
|
| 308 |
static bool SortBadPoints (const dng_point &a, |
| 309 |
const dng_point &b) |
| 310 |
{ |
| 311 |
|
| 312 |
if (a.v < b.v) |
| 313 |
return true; |
| 314 |
|
| 315 |
if (a.v > b.v) |
| 316 |
return false; |
| 317 |
|
| 318 |
return a.h < b.h; |
| 319 |
|
| 320 |
} |
| 321 |
|
| 322 |
/*****************************************************************************/ |
| 323 |
|
| 324 |
static bool SortBadRects (const dng_rect &a, |
| 325 |
const dng_rect &b) |
| 326 |
{ |
| 327 |
|
| 328 |
if (a.t < b.t) |
| 329 |
return true; |
| 330 |
|
| 331 |
if (a.t > b.t) |
| 332 |
return false; |
| 333 |
|
| 334 |
if (a.l < b.l) |
| 335 |
return true; |
| 336 |
|
| 337 |
if (a.l > b.l) |
| 338 |
return false; |
| 339 |
|
| 340 |
if (a.b < b.b) |
| 341 |
return true; |
| 342 |
|
| 343 |
if (a.b > b.b) |
| 344 |
return false; |
| 345 |
|
| 346 |
return a.r < b.r; |
| 347 |
|
| 348 |
} |
| 349 |
|
| 350 |
/*****************************************************************************/ |
| 351 |
|
| 352 |
void dng_bad_pixel_list::Sort () |
| 353 |
{ |
| 354 |
|
| 355 |
if (PointCount () > 1) |
| 356 |
{ |
| 357 |
|
| 358 |
std::sort (fBadPoints.begin (), |
| 359 |
fBadPoints.end (), |
| 360 |
SortBadPoints); |
| 361 |
|
| 362 |
} |
| 363 |
|
| 364 |
if (RectCount () > 1) |
| 365 |
{ |
| 366 |
|
| 367 |
std::sort (fBadRects.begin (), |
| 368 |
fBadRects.end (), |
| 369 |
SortBadRects); |
| 370 |
|
| 371 |
} |
| 372 |
|
| 373 |
} |
| 374 |
|
| 375 |
/*****************************************************************************/ |
| 376 |
|
| 377 |
bool dng_bad_pixel_list::IsPointIsolated (uint32 index, |
| 378 |
uint32 radius) const |
| 379 |
{ |
| 380 |
|
| 381 |
dng_point pt = Point (index); |
| 382 |
|
| 383 |
// Search backward through bad point list. |
| 384 |
|
| 385 |
for (int32 j = index - 1; j >= 0; j--) |
| 386 |
{ |
| 387 |
|
| 388 |
const dng_point &pt2 = Point (j); |
| 389 |
|
| 390 |
if (pt2.v < pt.v - (int32) radius) |
| 391 |
{ |
| 392 |
break; |
| 393 |
} |
| 394 |
|
| 395 |
if (Abs_int32 (pt2.h - pt.h) <= radius) |
| 396 |
{ |
| 397 |
return false; |
| 398 |
} |
| 399 |
|
| 400 |
} |
| 401 |
|
| 402 |
// Search forward through bad point list. |
| 403 |
|
| 404 |
for (uint32 k = index + 1; k < PointCount (); k++) |
| 405 |
{ |
| 406 |
|
| 407 |
const dng_point &pt2 = Point (k); |
| 408 |
|
| 409 |
if (pt2.v > pt.v + (int32) radius) |
| 410 |
{ |
| 411 |
break; |
| 412 |
} |
| 413 |
|
| 414 |
if (Abs_int32 (pt2.h - pt.h) <= radius) |
| 415 |
{ |
| 416 |
return false; |
| 417 |
} |
| 418 |
|
| 419 |
} |
| 420 |
|
| 421 |
// Search through bad rectangle list. |
| 422 |
|
| 423 |
dng_rect testRect (pt.v - radius, |
| 424 |
pt.h - radius, |
| 425 |
pt.v + radius + 1, |
| 426 |
pt.h + radius + 1); |
| 427 |
|
| 428 |
for (uint32 n = 0; n < RectCount (); n++) |
| 429 |
{ |
| 430 |
|
| 431 |
if ((testRect & Rect (n)).NotEmpty ()) |
| 432 |
{ |
| 433 |
return false; |
| 434 |
} |
| 435 |
|
| 436 |
} |
| 437 |
|
| 438 |
// Did not find point anywhere, so bad pixel is isolated. |
| 439 |
|
| 440 |
return true; |
| 441 |
|
| 442 |
} |
| 443 |
|
| 444 |
/*****************************************************************************/ |
| 445 |
|
| 446 |
bool dng_bad_pixel_list::IsRectIsolated (uint32 index, |
| 447 |
uint32 radius) const |
| 448 |
{ |
| 449 |
|
| 450 |
dng_rect testRect = Rect (index); |
| 451 |
|
| 452 |
testRect.t -= radius; |
| 453 |
testRect.l -= radius; |
| 454 |
testRect.b += radius; |
| 455 |
testRect.r += radius; |
| 456 |
|
| 457 |
for (uint32 n = 0; n < RectCount (); n++) |
| 458 |
{ |
| 459 |
|
| 460 |
if (n != index) |
| 461 |
{ |
| 462 |
|
| 463 |
if ((testRect & Rect (n)).NotEmpty ()) |
| 464 |
{ |
| 465 |
return false; |
| 466 |
} |
| 467 |
|
| 468 |
} |
| 469 |
|
| 470 |
} |
| 471 |
|
| 472 |
return true; |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
/*****************************************************************************/ |
| 477 |
|
| 478 |
bool dng_bad_pixel_list::IsPointValid (const dng_point &pt, |
| 479 |
const dng_rect &imageBounds, |
| 480 |
uint32 index) const |
| 481 |
{ |
| 482 |
|
| 483 |
// The point must be in the image bounds to be valid. |
| 484 |
|
| 485 |
if (pt.v < imageBounds.t || |
| 486 |
pt.h < imageBounds.l || |
| 487 |
pt.v >= imageBounds.b || |
| 488 |
pt.h >= imageBounds.r) |
| 489 |
{ |
| 490 |
return false; |
| 491 |
} |
| 492 |
|
| 493 |
// Only search the bad point list if we have a starting search index. |
| 494 |
|
| 495 |
if (index != kNoIndex) |
| 496 |
{ |
| 497 |
|
| 498 |
// Search backward through bad point list. |
| 499 |
|
| 500 |
for (int32 j = index - 1; j >= 0; j--) |
| 501 |
{ |
| 502 |
|
| 503 |
const dng_point &pt2 = Point (j); |
| 504 |
|
| 505 |
if (pt2.v < pt.v) |
| 506 |
{ |
| 507 |
break; |
| 508 |
} |
| 509 |
|
| 510 |
if (pt2 == pt) |
| 511 |
{ |
| 512 |
return false; |
| 513 |
} |
| 514 |
|
| 515 |
} |
| 516 |
|
| 517 |
// Search forward through bad point list. |
| 518 |
|
| 519 |
for (uint32 k = index + 1; k < PointCount (); k++) |
| 520 |
{ |
| 521 |
|
| 522 |
const dng_point &pt2 = Point (k); |
| 523 |
|
| 524 |
if (pt2.v > pt.v) |
| 525 |
{ |
| 526 |
break; |
| 527 |
} |
| 528 |
|
| 529 |
if (pt2 == pt) |
| 530 |
{ |
| 531 |
return false; |
| 532 |
} |
| 533 |
|
| 534 |
} |
| 535 |
|
| 536 |
} |
| 537 |
|
| 538 |
// Search through bad rectangle list. |
| 539 |
|
| 540 |
for (uint32 n = 0; n < RectCount (); n++) |
| 541 |
{ |
| 542 |
|
| 543 |
const dng_rect &r = Rect (n); |
| 544 |
|
| 545 |
if (pt.v >= r.t && |
| 546 |
pt.h >= r.l && |
| 547 |
pt.v < r.b && |
| 548 |
pt.h < r.r) |
| 549 |
{ |
| 550 |
return false; |
| 551 |
} |
| 552 |
|
| 553 |
} |
| 554 |
|
| 555 |
// Did not find point anywhere, so pixel is valid. |
| 556 |
|
| 557 |
return true; |
| 558 |
|
| 559 |
} |
| 560 |
|
| 561 |
/*****************************************************************************/ |
| 562 |
|
| 563 |
dng_opcode_FixBadPixelsList::dng_opcode_FixBadPixelsList |
| 564 |
(AutoPtr<dng_bad_pixel_list> &list, |
| 565 |
uint32 bayerPhase) |
| 566 |
|
| 567 |
|
| 568 |
: dng_filter_opcode (dngOpcode_FixBadPixelsList, |
| 569 |
dngVersion_1_3_0_0, |
| 570 |
0) |
| 571 |
|
| 572 |
, fList () |
| 573 |
|
| 574 |
, fBayerPhase (bayerPhase) |
| 575 |
|
| 576 |
{ |
| 577 |
|
| 578 |
fList.Reset (list.Release ()); |
| 579 |
|
| 580 |
fList->Sort (); |
| 581 |
|
| 582 |
} |
| 583 |
|
| 584 |
/*****************************************************************************/ |
| 585 |
|
| 586 |
dng_opcode_FixBadPixelsList::dng_opcode_FixBadPixelsList (dng_stream &stream) |
| 587 |
|
| 588 |
: dng_filter_opcode (dngOpcode_FixBadPixelsList, |
| 589 |
stream, |
| 590 |
"FixBadPixelsList") |
| 591 |
|
| 592 |
, fList () |
| 593 |
|
| 594 |
, fBayerPhase (0) |
| 595 |
|
| 596 |
{ |
| 597 |
|
| 598 |
uint32 size = stream.Get_uint32 (); |
| 599 |
|
| 600 |
fBayerPhase = stream.Get_uint32 (); |
| 601 |
|
| 602 |
uint32 pCount = stream.Get_uint32 (); |
| 603 |
uint32 rCount = stream.Get_uint32 (); |
| 604 |
|
| 605 |
uint32 expectedSize = |
| 606 |
SafeUint32Add (12, |
| 607 |
SafeUint32Add (SafeUint32Mult (pCount, 8), |
| 608 |
SafeUint32Mult (rCount, 16))); |
| 609 |
|
| 610 |
if (size != expectedSize) |
| 611 |
{ |
| 612 |
ThrowBadFormat (); |
| 613 |
} |
| 614 |
|
| 615 |
fList.Reset (new dng_bad_pixel_list); |
| 616 |
|
| 617 |
uint32 index; |
| 618 |
|
| 619 |
for (index = 0; index < pCount; index++) |
| 620 |
{ |
| 621 |
|
| 622 |
dng_point pt; |
| 623 |
|
| 624 |
pt.v = stream.Get_int32 (); |
| 625 |
pt.h = stream.Get_int32 (); |
| 626 |
|
| 627 |
fList->AddPoint (pt); |
| 628 |
|
| 629 |
} |
| 630 |
|
| 631 |
for (index = 0; index < rCount; index++) |
| 632 |
{ |
| 633 |
|
| 634 |
dng_rect r; |
| 635 |
|
| 636 |
r.t = stream.Get_int32 (); |
| 637 |
r.l = stream.Get_int32 (); |
| 638 |
r.b = stream.Get_int32 (); |
| 639 |
r.r = stream.Get_int32 (); |
| 640 |
|
| 641 |
fList->AddRect (r); |
| 642 |
|
| 643 |
} |
| 644 |
|
| 645 |
fList->Sort (); |
| 646 |
|
| 647 |
#if qDNGValidate |
| 648 |
|
| 649 |
if (gVerbose) |
| 650 |
{ |
| 651 |
|
| 652 |
printf ("Bayer Phase: %u\n", (unsigned) fBayerPhase); |
| 653 |
|
| 654 |
printf ("Bad Pixels: %u\n", (unsigned) pCount); |
| 655 |
|
| 656 |
for (index = 0; index < pCount && index < gDumpLineLimit; index++) |
| 657 |
{ |
| 658 |
printf ("\tPixel [%u]: v=%d, h=%d\n", |
| 659 |
(unsigned) index, |
| 660 |
(int) fList->Point (index).v, |
| 661 |
(int) fList->Point (index).h); |
| 662 |
} |
| 663 |
|
| 664 |
if (pCount > gDumpLineLimit) |
| 665 |
{ |
| 666 |
printf ("\t ... %u bad pixels skipped\n", (unsigned) (pCount - gDumpLineLimit)); |
| 667 |
} |
| 668 |
|
| 669 |
printf ("Bad Rects: %u\n", (unsigned) rCount); |
| 670 |
|
| 671 |
for (index = 0; index < rCount && index < gDumpLineLimit; index++) |
| 672 |
{ |
| 673 |
printf ("\tRect [%u]: t=%d, l=%d, b=%d, r=%d\n", |
| 674 |
(unsigned) index, |
| 675 |
(int) fList->Rect (index).t, |
| 676 |
(int) fList->Rect (index).l, |
| 677 |
(int) fList->Rect (index).b, |
| 678 |
(int) fList->Rect (index).r); |
| 679 |
} |
| 680 |
|
| 681 |
if (rCount > gDumpLineLimit) |
| 682 |
{ |
| 683 |
printf ("\t ... %u bad rects skipped\n", (unsigned) (rCount - gDumpLineLimit)); |
| 684 |
} |
| 685 |
|
| 686 |
} |
| 687 |
|
| 688 |
#endif |
| 689 |
|
| 690 |
} |
| 691 |
|
| 692 |
/*****************************************************************************/ |
| 693 |
|
| 694 |
void dng_opcode_FixBadPixelsList::PutData (dng_stream &stream) const |
| 695 |
{ |
| 696 |
|
| 697 |
uint32 pCount = fList->PointCount (); |
| 698 |
uint32 rCount = fList->RectCount (); |
| 699 |
|
| 700 |
stream.Put_uint32 (12 + pCount * 8 + rCount * 16); |
| 701 |
|
| 702 |
stream.Put_uint32 (fBayerPhase); |
| 703 |
|
| 704 |
stream.Put_uint32 (pCount); |
| 705 |
stream.Put_uint32 (rCount); |
| 706 |
|
| 707 |
uint32 index; |
| 708 |
|
| 709 |
for (index = 0; index < pCount; index++) |
| 710 |
{ |
| 711 |
|
| 712 |
const dng_point &pt (fList->Point (index)); |
| 713 |
|
| 714 |
stream.Put_int32 (pt.v); |
| 715 |
stream.Put_int32 (pt.h); |
| 716 |
|
| 717 |
} |
| 718 |
|
| 719 |
for (index = 0; index < rCount; index++) |
| 720 |
{ |
| 721 |
|
| 722 |
const dng_rect &r (fList->Rect (index)); |
| 723 |
|
| 724 |
stream.Put_int32 (r.t); |
| 725 |
stream.Put_int32 (r.l); |
| 726 |
stream.Put_int32 (r.b); |
| 727 |
stream.Put_int32 (r.r); |
| 728 |
|
| 729 |
} |
| 730 |
|
| 731 |
} |
| 732 |
|
| 733 |
/*****************************************************************************/ |
| 734 |
|
| 735 |
dng_rect dng_opcode_FixBadPixelsList::SrcArea (const dng_rect &dstArea, |
| 736 |
const dng_rect & /* imageBounds */) |
| 737 |
{ |
| 738 |
|
| 739 |
int32 padding = 0; |
| 740 |
|
| 741 |
if (fList->PointCount ()) |
| 742 |
{ |
| 743 |
padding += kBadPointPadding; |
| 744 |
} |
| 745 |
|
| 746 |
if (fList->RectCount ()) |
| 747 |
{ |
| 748 |
padding += kBadRectPadding; |
| 749 |
} |
| 750 |
|
| 751 |
dng_rect srcArea = dstArea; |
| 752 |
|
| 753 |
srcArea.t -= padding; |
| 754 |
srcArea.l -= padding; |
| 755 |
|
| 756 |
srcArea.b += padding; |
| 757 |
srcArea.r += padding; |
| 758 |
|
| 759 |
return srcArea; |
| 760 |
|
| 761 |
} |
| 762 |
|
| 763 |
/*****************************************************************************/ |
| 764 |
|
| 765 |
dng_point dng_opcode_FixBadPixelsList::SrcRepeat () |
| 766 |
{ |
| 767 |
|
| 768 |
return dng_point (2, 2); |
| 769 |
|
| 770 |
} |
| 771 |
|
| 772 |
/*****************************************************************************/ |
| 773 |
|
| 774 |
void dng_opcode_FixBadPixelsList::Prepare (dng_negative & /* negative */, |
| 775 |
uint32 /* threadCount */, |
| 776 |
const dng_point & /* tileSize */, |
| 777 |
const dng_rect & /* imageBounds */, |
| 778 |
uint32 imagePlanes, |
| 779 |
uint32 bufferPixelType, |
| 780 |
dng_memory_allocator & /* allocator */) |
| 781 |
{ |
| 782 |
|
| 783 |
// This opcode is restricted to single channel images. |
| 784 |
|
| 785 |
if (imagePlanes != 1) |
| 786 |
{ |
| 787 |
|
| 788 |
ThrowBadFormat (); |
| 789 |
|
| 790 |
} |
| 791 |
|
| 792 |
// This opcode is restricted to 16-bit images. |
| 793 |
|
| 794 |
if (bufferPixelType != ttShort) |
| 795 |
{ |
| 796 |
|
| 797 |
ThrowBadFormat (); |
| 798 |
|
| 799 |
} |
| 800 |
|
| 801 |
} |
| 802 |
|
| 803 |
/*****************************************************************************/ |
| 804 |
|
| 805 |
void dng_opcode_FixBadPixelsList::FixIsolatedPixel (dng_pixel_buffer &buffer, |
| 806 |
dng_point &badPoint) |
| 807 |
{ |
| 808 |
|
| 809 |
uint16 *p0 = buffer.DirtyPixel_uint16 (badPoint.v - 2, badPoint.h - 2, 0); |
| 810 |
uint16 *p1 = buffer.DirtyPixel_uint16 (badPoint.v - 1, badPoint.h - 2, 0); |
| 811 |
uint16 *p2 = buffer.DirtyPixel_uint16 (badPoint.v , badPoint.h - 2, 0); |
| 812 |
uint16 *p3 = buffer.DirtyPixel_uint16 (badPoint.v + 1, badPoint.h - 2, 0); |
| 813 |
uint16 *p4 = buffer.DirtyPixel_uint16 (badPoint.v + 2, badPoint.h - 2, 0); |
| 814 |
|
| 815 |
uint32 est0; |
| 816 |
uint32 est1; |
| 817 |
uint32 est2; |
| 818 |
uint32 est3; |
| 819 |
|
| 820 |
uint32 grad0; |
| 821 |
uint32 grad1; |
| 822 |
uint32 grad2; |
| 823 |
uint32 grad3; |
| 824 |
|
| 825 |
if (IsGreen (badPoint.v, badPoint.h)) // Green pixel |
| 826 |
{ |
| 827 |
|
| 828 |
// g00 b01 g02 b03 g04 |
| 829 |
// r10 g11 r12 g13 r14 |
| 830 |
// g20 b21 g22 b23 g24 |
| 831 |
// r30 g31 r32 g33 r34 |
| 832 |
// g40 b41 g42 b43 g44 |
| 833 |
|
| 834 |
int32 b01 = p0 [1]; |
| 835 |
int32 g02 = p0 [2]; |
| 836 |
int32 b03 = p0 [3]; |
| 837 |
|
| 838 |
int32 r10 = p1 [0]; |
| 839 |
int32 g11 = p1 [1]; |
| 840 |
int32 r12 = p1 [2]; |
| 841 |
int32 g13 = p1 [3]; |
| 842 |
int32 r14 = p1 [4]; |
| 843 |
|
| 844 |
int32 g20 = p2 [0]; |
| 845 |
int32 b21 = p2 [1]; |
| 846 |
int32 b23 = p2 [3]; |
| 847 |
int32 g24 = p2 [4]; |
| 848 |
|
| 849 |
int32 r30 = p3 [0]; |
| 850 |
int32 g31 = p3 [1]; |
| 851 |
int32 r32 = p3 [2]; |
| 852 |
int32 g33 = p3 [3]; |
| 853 |
int32 r34 = p3 [4]; |
| 854 |
|
| 855 |
int32 b41 = p4 [1]; |
| 856 |
int32 g42 = p4 [2]; |
| 857 |
int32 b43 = p4 [3]; |
| 858 |
|
| 859 |
est0 = g02 + g42; |
| 860 |
|
| 861 |
grad0 = Abs_int32 (g02 - g42) + |
| 862 |
Abs_int32 (g11 - g31) + |
| 863 |
Abs_int32 (g13 - g33) + |
| 864 |
Abs_int32 (b01 - b21) + |
| 865 |
Abs_int32 (b03 - b23) + |
| 866 |
Abs_int32 (b21 - b41) + |
| 867 |
Abs_int32 (b23 - b43); |
| 868 |
|
| 869 |
est1 = g11 + g33; |
| 870 |
|
| 871 |
grad1 = Abs_int32 (g11 - g33) + |
| 872 |
Abs_int32 (g02 - g24) + |
| 873 |
Abs_int32 (g20 - g42) + |
| 874 |
Abs_int32 (b01 - b23) + |
| 875 |
Abs_int32 (r10 - r32) + |
| 876 |
Abs_int32 (r12 - r34) + |
| 877 |
Abs_int32 (b21 - b43); |
| 878 |
|
| 879 |
est2 = g20 + g24; |
| 880 |
|
| 881 |
grad2 = Abs_int32 (g20 - g24) + |
| 882 |
Abs_int32 (g11 - g13) + |
| 883 |
Abs_int32 (g31 - g33) + |
| 884 |
Abs_int32 (r10 - r12) + |
| 885 |
Abs_int32 (r30 - r32) + |
| 886 |
Abs_int32 (r12 - r14) + |
| 887 |
Abs_int32 (r32 - r34); |
| 888 |
|
| 889 |
est3 = g13 + g31; |
| 890 |
|
| 891 |
grad3 = Abs_int32 (g13 - g31) + |
| 892 |
Abs_int32 (g02 - g20) + |
| 893 |
Abs_int32 (g24 - g42) + |
| 894 |
Abs_int32 (b03 - b21) + |
| 895 |
Abs_int32 (r14 - r32) + |
| 896 |
Abs_int32 (r12 - r30) + |
| 897 |
Abs_int32 (b23 - b41); |
| 898 |
|
| 899 |
} |
| 900 |
|
| 901 |
else // Red/blue pixel |
| 902 |
{ |
| 903 |
|
| 904 |
// b00 g01 b02 g03 b04 |
| 905 |
// g10 r11 g12 r13 g14 |
| 906 |
// b20 g21 b22 g23 b24 |
| 907 |
// g30 r31 g32 r33 g34 |
| 908 |
// b40 g41 b42 g43 b44 |
| 909 |
|
| 910 |
int32 b00 = p0 [0]; |
| 911 |
int32 g01 = p0 [1]; |
| 912 |
int32 b02 = p0 [2]; |
| 913 |
int32 g03 = p0 [3]; |
| 914 |
int32 b04 = p0 [4]; |
| 915 |
|
| 916 |
int32 g10 = p1 [0]; |
| 917 |
int32 r11 = p1 [1]; |
| 918 |
int32 g12 = p1 [2]; |
| 919 |
int32 r13 = p1 [3]; |
| 920 |
int32 g14 = p1 [4]; |
| 921 |
|
| 922 |
int32 b20 = p2 [0]; |
| 923 |
int32 g21 = p2 [1]; |
| 924 |
int32 g23 = p2 [3]; |
| 925 |
int32 b24 = p2 [4]; |
| 926 |
|
| 927 |
int32 g30 = p3 [0]; |
| 928 |
int32 r31 = p3 [1]; |
| 929 |
int32 g32 = p3 [2]; |
| 930 |
int32 r33 = p3 [3]; |
| 931 |
int32 g34 = p3 [4]; |
| 932 |
|
| 933 |
int32 b40 = p4 [0]; |
| 934 |
int32 g41 = p4 [1]; |
| 935 |
int32 b42 = p4 [2]; |
| 936 |
int32 g43 = p4 [3]; |
| 937 |
int32 b44 = p4 [4]; |
| 938 |
|
| 939 |
est0 = b02 + b42; |
| 940 |
|
| 941 |
grad0 = Abs_int32 (b02 - b42) + |
| 942 |
Abs_int32 (g12 - g32) + |
| 943 |
Abs_int32 (g01 - g21) + |
| 944 |
Abs_int32 (g21 - g41) + |
| 945 |
Abs_int32 (g03 - g23) + |
| 946 |
Abs_int32 (g23 - g43) + |
| 947 |
Abs_int32 (r11 - r31) + |
| 948 |
Abs_int32 (r13 - r33); |
| 949 |
|
| 950 |
est1 = b00 + b44; |
| 951 |
|
| 952 |
grad1 = Abs_int32 (b00 - b44) + |
| 953 |
Abs_int32 (r11 - r33) + |
| 954 |
Abs_int32 (g01 - g23) + |
| 955 |
Abs_int32 (g10 - g32) + |
| 956 |
Abs_int32 (g12 - g34) + |
| 957 |
Abs_int32 (g21 - g43) + |
| 958 |
Abs_int32 (b02 - b24) + |
| 959 |
Abs_int32 (b20 - b42); |
| 960 |
|
| 961 |
est2 = b20 + b24; |
| 962 |
|
| 963 |
grad2 = Abs_int32 (b20 - b24) + |
| 964 |
Abs_int32 (g21 - g23) + |
| 965 |
Abs_int32 (g10 - g12) + |
| 966 |
Abs_int32 (g12 - g14) + |
| 967 |
Abs_int32 (g30 - g32) + |
| 968 |
Abs_int32 (g32 - g34) + |
| 969 |
Abs_int32 (r11 - r13) + |
| 970 |
Abs_int32 (r31 - r33); |
| 971 |
|
| 972 |
est3 = b04 + b40; |
| 973 |
|
| 974 |
grad3 = Abs_int32 (b04 - b40) + |
| 975 |
Abs_int32 (r13 - r31) + |
| 976 |
Abs_int32 (g03 - g21) + |
| 977 |
Abs_int32 (g14 - g32) + |
| 978 |
Abs_int32 (g12 - g30) + |
| 979 |
Abs_int32 (g23 - g41) + |
| 980 |
Abs_int32 (b02 - b20) + |
| 981 |
Abs_int32 (b24 - b42); |
| 982 |
|
| 983 |
} |
| 984 |
|
| 985 |
uint32 minGrad = Min_uint32 (grad0, grad1); |
| 986 |
|
| 987 |
minGrad = Min_uint32 (minGrad, grad2); |
| 988 |
minGrad = Min_uint32 (minGrad, grad3); |
| 989 |
|
| 990 |
uint32 limit = (minGrad * 3) >> 1; |
| 991 |
|
| 992 |
uint32 total = 0; |
| 993 |
uint32 count = 0; |
| 994 |
|
| 995 |
if (grad0 <= limit) |
| 996 |
{ |
| 997 |
total += est0; |
| 998 |
count += 2; |
| 999 |
} |
| 1000 |
|
| 1001 |
if (grad1 <= limit) |
| 1002 |
{ |
| 1003 |
total += est1; |
| 1004 |
count += 2; |
| 1005 |
} |
| 1006 |
|
| 1007 |
if (grad2 <= limit) |
| 1008 |
{ |
| 1009 |
total += est2; |
| 1010 |
count += 2; |
| 1011 |
} |
| 1012 |
|
| 1013 |
if (grad3 <= limit) |
| 1014 |
{ |
| 1015 |
total += est3; |
| 1016 |
count += 2; |
| 1017 |
} |
| 1018 |
|
| 1019 |
count = Max_uint32 (count, 1); // Suppress div-by-zero warning. |
| 1020 |
|
| 1021 |
uint32 estimate = (total + (count >> 1)) / count; |
| 1022 |
|
| 1023 |
p2 [2] = (uint16) estimate; |
| 1024 |
|
| 1025 |
} |
| 1026 |
|
| 1027 |
/*****************************************************************************/ |
| 1028 |
|
| 1029 |
void dng_opcode_FixBadPixelsList::FixClusteredPixel (dng_pixel_buffer &buffer, |
| 1030 |
uint32 pointIndex, |
| 1031 |
const dng_rect &imageBounds) |
| 1032 |
{ |
| 1033 |
|
| 1034 |
const uint32 kNumSets = 3; |
| 1035 |
const uint32 kSetSize = 4; |
| 1036 |
|
| 1037 |
static const int32 kOffset [kNumSets] [kSetSize] [2] = |
| 1038 |
{ |
| 1039 |
{ |
| 1040 |
{ -1, 1 }, |
| 1041 |
{ -1, -1 }, |
| 1042 |
{ 1, -1 }, |
| 1043 |
{ 1, 1 } |
| 1044 |
}, |
| 1045 |
{ |
| 1046 |
{ -2, 0 }, |
| 1047 |
{ 2, 0 }, |
| 1048 |
{ 0, -2 }, |
| 1049 |
{ 0, 2 } |
| 1050 |
}, |
| 1051 |
{ |
| 1052 |
{ -2, -2 }, |
| 1053 |
{ -2, 2 }, |
| 1054 |
{ 2, -2 }, |
| 1055 |
{ 2, 2 } |
| 1056 |
} |
| 1057 |
}; |
| 1058 |
|
| 1059 |
dng_point badPoint = fList->Point (pointIndex); |
| 1060 |
|
| 1061 |
bool isGreen = IsGreen (badPoint.v, badPoint.h); |
| 1062 |
|
| 1063 |
uint16 *p = buffer.DirtyPixel_uint16 (badPoint.v, badPoint.h, 0); |
| 1064 |
|
| 1065 |
for (uint32 set = 0; set < kNumSets; set++) |
| 1066 |
{ |
| 1067 |
|
| 1068 |
if (!isGreen && (kOffset [set] [0] [0] & 1) == 1) |
| 1069 |
{ |
| 1070 |
continue; |
| 1071 |
} |
| 1072 |
|
| 1073 |
uint32 total = 0; |
| 1074 |
uint32 count = 0; |
| 1075 |
|
| 1076 |
for (uint32 entry = 0; entry < kSetSize; entry++) |
| 1077 |
{ |
| 1078 |
|
| 1079 |
dng_point offset (kOffset [set] [entry] [0], |
| 1080 |
kOffset [set] [entry] [1]); |
| 1081 |
|
| 1082 |
if (fList->IsPointValid (badPoint + offset, |
| 1083 |
imageBounds, |
| 1084 |
pointIndex)) |
| 1085 |
{ |
| 1086 |
|
| 1087 |
total += p [offset.v * buffer.fRowStep + |
| 1088 |
offset.h * buffer.fColStep]; |
| 1089 |
|
| 1090 |
count++; |
| 1091 |
|
| 1092 |
} |
| 1093 |
|
| 1094 |
} |
| 1095 |
|
| 1096 |
if (count) |
| 1097 |
{ |
| 1098 |
|
| 1099 |
uint32 estimate = (total + (count >> 1)) / count; |
| 1100 |
|
| 1101 |
p [0] = (uint16) estimate; |
| 1102 |
|
| 1103 |
return; |
| 1104 |
|
| 1105 |
} |
| 1106 |
|
| 1107 |
} |
| 1108 |
|
| 1109 |
// Unable to patch bad pixel. Leave pixel as is. |
| 1110 |
|
| 1111 |
#if qDNGValidate |
| 1112 |
|
| 1113 |
char s [256]; |
| 1114 |
|
| 1115 |
snprintf (s, |
| 1116 |
256, |
| 1117 |
"Unable to repair bad pixel, row %d, column %d", |
| 1118 |
(int) badPoint.v, |
| 1119 |
(int) badPoint.h); |
| 1120 |
|
| 1121 |
ReportWarning (s); |
| 1122 |
|
| 1123 |
#endif |
| 1124 |
|
| 1125 |
} |
| 1126 |
|
| 1127 |
/*****************************************************************************/ |
| 1128 |
|
| 1129 |
void dng_opcode_FixBadPixelsList::FixSingleColumn (dng_pixel_buffer &buffer, |
| 1130 |
const dng_rect &badRect) |
| 1131 |
{ |
| 1132 |
|
| 1133 |
int32 cs = buffer.fColStep; |
| 1134 |
|
| 1135 |
for (int32 row = badRect.t; row < badRect.b; row++) |
| 1136 |
{ |
| 1137 |
|
| 1138 |
uint16 *p0 = buffer.DirtyPixel_uint16 (row - 4, badRect.l - 4, 0); |
| 1139 |
uint16 *p1 = buffer.DirtyPixel_uint16 (row - 3, badRect.l - 4, 0); |
| 1140 |
uint16 *p2 = buffer.DirtyPixel_uint16 (row - 2, badRect.l - 4, 0); |
| 1141 |
uint16 *p3 = buffer.DirtyPixel_uint16 (row - 1, badRect.l - 4, 0); |
| 1142 |
uint16 *p4 = buffer.DirtyPixel_uint16 (row , badRect.l - 4, 0); |
| 1143 |
uint16 *p5 = buffer.DirtyPixel_uint16 (row + 1, badRect.l - 4, 0); |
| 1144 |
uint16 *p6 = buffer.DirtyPixel_uint16 (row + 2, badRect.l - 4, 0); |
| 1145 |
uint16 *p7 = buffer.DirtyPixel_uint16 (row + 3, badRect.l - 4, 0); |
| 1146 |
uint16 *p8 = buffer.DirtyPixel_uint16 (row + 4, badRect.l - 4, 0); |
| 1147 |
|
| 1148 |
uint32 est0; |
| 1149 |
uint32 est1; |
| 1150 |
uint32 est2; |
| 1151 |
uint32 est3; |
| 1152 |
uint32 est4; |
| 1153 |
uint32 est5; |
| 1154 |
uint32 est6; |
| 1155 |
|
| 1156 |
uint32 grad0; |
| 1157 |
uint32 grad1; |
| 1158 |
uint32 grad2; |
| 1159 |
uint32 grad3; |
| 1160 |
uint32 grad4; |
| 1161 |
uint32 grad5; |
| 1162 |
uint32 grad6; |
| 1163 |
|
| 1164 |
uint32 lower = 0; |
| 1165 |
uint32 upper = 0x0FFFF; |
| 1166 |
|
| 1167 |
if (IsGreen (row, badRect.l)) // Green pixel |
| 1168 |
{ |
| 1169 |
|
| 1170 |
// g00 b01 g02 b03 g04 b05 g06 b07 g08 |
| 1171 |
// r10 g11 r12 g13 r14 g15 r16 g17 r18 |
| 1172 |
// g20 b21 g22 b23 g24 b25 g26 b27 g28 |
| 1173 |
// r30 g31 r32 g33 r34 g35 r36 g37 r38 |
| 1174 |
// g40 b41 g42 b43 g44 b45 g46 b47 g48 |
| 1175 |
// r50 g51 r52 g53 r54 g55 r56 g57 r58 |
| 1176 |
// g60 b61 g62 b63 g64 b65 g66 b67 g68 |
| 1177 |
// r70 g71 r72 g73 r74 g75 r76 g77 r78 |
| 1178 |
// g80 b81 g82 b83 g84 b85 g86 b87 g88 |
| 1179 |
|
| 1180 |
int32 b03 = p0 [3 * cs]; |
| 1181 |
int32 b05 = p0 [5 * cs]; |
| 1182 |
|
| 1183 |
int32 g11 = p1 [1 * cs]; |
| 1184 |
int32 g13 = p1 [3 * cs]; |
| 1185 |
int32 g15 = p1 [5 * cs]; |
| 1186 |
int32 g17 = p1 [7 * cs]; |
| 1187 |
|
| 1188 |
int32 g22 = p2 [2 * cs]; |
| 1189 |
int32 b23 = p2 [3 * cs]; |
| 1190 |
int32 b25 = p2 [5 * cs]; |
| 1191 |
int32 g26 = p2 [6 * cs]; |
| 1192 |
|
| 1193 |
int32 r30 = p3 [0 * cs]; |
| 1194 |
int32 g31 = p3 [1 * cs]; |
| 1195 |
int32 r32 = p3 [2 * cs]; |
| 1196 |
int32 g33 = p3 [3 * cs]; |
| 1197 |
int32 g35 = p3 [5 * cs]; |
| 1198 |
int32 r36 = p3 [6 * cs]; |
| 1199 |
int32 g37 = p3 [7 * cs]; |
| 1200 |
int32 r38 = p3 [8 * cs]; |
| 1201 |
|
| 1202 |
int32 g40 = p4 [0 * cs]; |
| 1203 |
int32 g42 = p4 [2 * cs]; |
| 1204 |
int32 b43 = p4 [3 * cs]; |
| 1205 |
int32 b45 = p4 [5 * cs]; |
| 1206 |
int32 g46 = p4 [6 * cs]; |
| 1207 |
int32 g48 = p4 [8 * cs]; |
| 1208 |
|
| 1209 |
int32 r50 = p5 [0 * cs]; |
| 1210 |
int32 g51 = p5 [1 * cs]; |
| 1211 |
int32 r52 = p5 [2 * cs]; |
| 1212 |
int32 g53 = p5 [3 * cs]; |
| 1213 |
int32 g55 = p5 [5 * cs]; |
| 1214 |
int32 r56 = p5 [6 * cs]; |
| 1215 |
int32 g57 = p5 [7 * cs]; |
| 1216 |
int32 r58 = p5 [8 * cs]; |
| 1217 |
|
| 1218 |
int32 g62 = p6 [2 * cs]; |
| 1219 |
int32 b63 = p6 [3 * cs]; |
| 1220 |
int32 b65 = p6 [5 * cs]; |
| 1221 |
int32 g66 = p6 [6 * cs]; |
| 1222 |
|
| 1223 |
int32 g71 = p7 [1 * cs]; |
| 1224 |
int32 g73 = p7 [3 * cs]; |
| 1225 |
int32 g75 = p7 [5 * cs]; |
| 1226 |
int32 g77 = p7 [7 * cs]; |
| 1227 |
|
| 1228 |
int32 b83 = p8 [3 * cs]; |
| 1229 |
int32 b85 = p8 [5 * cs]; |
| 1230 |
|
| 1231 |
// In case there is some green split, make an estimate of |
| 1232 |
// of the local difference between the greens, and adjust |
| 1233 |
// the estimated green values for the difference |
| 1234 |
// between the two types of green pixels when estimating |
| 1235 |
// across green types. |
| 1236 |
|
| 1237 |
int32 split = ((g22 + g62 + g26 + g66) * 4 + |
| 1238 |
(g42 + g46 ) * 8 - |
| 1239 |
(g11 + g13 + g15 + g17) - |
| 1240 |
(g31 + g33 + g35 + g37) * 3 - |
| 1241 |
(g51 + g53 + g55 + g57) * 3 - |
| 1242 |
(g71 + g73 + g75 + g77) + 16) >> 5; |
| 1243 |
|
| 1244 |
est0 = g13 + g75 + split * 2; |
| 1245 |
|
| 1246 |
grad0 = Abs_int32 (g13 - g75) + |
| 1247 |
Abs_int32 (g15 - g46) + |
| 1248 |
Abs_int32 (g22 - g53) + |
| 1249 |
Abs_int32 (g35 - g66) + |
| 1250 |
Abs_int32 (g42 - g73) + |
| 1251 |
Abs_int32 (b03 - b65) + |
| 1252 |
Abs_int32 (b23 - b85); |
| 1253 |
|
| 1254 |
est1 = g33 + g55 + split * 2; |
| 1255 |
|
| 1256 |
grad1 = Abs_int32 (g33 - g55) + |
| 1257 |
Abs_int32 (g22 - g55) + |
| 1258 |
Abs_int32 (g33 - g66) + |
| 1259 |
Abs_int32 (g13 - g35) + |
| 1260 |
Abs_int32 (g53 - g75) + |
| 1261 |
Abs_int32 (b23 - b45) + |
| 1262 |
Abs_int32 (b43 - b65); |
| 1263 |
|
| 1264 |
est2 = g31 + g57 + split * 2; |
| 1265 |
|
| 1266 |
grad2 = Abs_int32 (g31 - g57) + |
| 1267 |
Abs_int32 (g33 - g46) + |
| 1268 |
Abs_int32 (g35 - g48) + |
| 1269 |
Abs_int32 (g40 - g53) + |
| 1270 |
Abs_int32 (g42 - g55) + |
| 1271 |
Abs_int32 (r30 - r56) + |
| 1272 |
Abs_int32 (r32 - r58); |
| 1273 |
|
| 1274 |
est3 = g42 + g46; |
| 1275 |
|
| 1276 |
grad3 = Abs_int32 (g42 - g46) * 2 + |
| 1277 |
Abs_int32 (g33 - g35) + |
| 1278 |
Abs_int32 (g53 - g55) + |
| 1279 |
Abs_int32 (b23 - b25) + |
| 1280 |
Abs_int32 (b43 - b45) + |
| 1281 |
Abs_int32 (b63 - b65); |
| 1282 |
|
| 1283 |
est4 = g37 + g51 + split * 2; |
| 1284 |
|
| 1285 |
grad4 = Abs_int32 (g37 - g51) + |
| 1286 |
Abs_int32 (g35 - g42) + |
| 1287 |
Abs_int32 (g33 - g40) + |
| 1288 |
Abs_int32 (g48 - g55) + |
| 1289 |
Abs_int32 (g46 - g53) + |
| 1290 |
Abs_int32 (r38 - r52) + |
| 1291 |
Abs_int32 (r36 - r50); |
| 1292 |
|
| 1293 |
est5 = g35 + g53 + split * 2; |
| 1294 |
|
| 1295 |
grad5 = Abs_int32 (g35 - g53) + |
| 1296 |
Abs_int32 (g26 - g53) + |
| 1297 |
Abs_int32 (g35 - g62) + |
| 1298 |
Abs_int32 (g15 - g33) + |
| 1299 |
Abs_int32 (g55 - g73) + |
| 1300 |
Abs_int32 (b25 - b43) + |
| 1301 |
Abs_int32 (b45 - b63); |
| 1302 |
|
| 1303 |
est6 = g15 + g73 + split * 2; |
| 1304 |
|
| 1305 |
grad6 = Abs_int32 (g15 - g73) + |
| 1306 |
Abs_int32 (g13 - g42) + |
| 1307 |
Abs_int32 (g26 - g55) + |
| 1308 |
Abs_int32 (g33 - g62) + |
| 1309 |
Abs_int32 (g46 - g75) + |
| 1310 |
Abs_int32 (b05 - b63) + |
| 1311 |
Abs_int32 (b25 - b83); |
| 1312 |
|
| 1313 |
lower = Min_uint32 (Min_uint32 (g33, g35), |
| 1314 |
Min_uint32 (g53, g55)); |
| 1315 |
|
| 1316 |
upper = Max_uint32 (Max_uint32 (g33, g35), |
| 1317 |
Max_uint32 (g53, g55)); |
| 1318 |
|
| 1319 |
lower = Pin_int32 (0, lower + split, 65535); |
| 1320 |
upper = Pin_int32 (0, upper + split, 65535); |
| 1321 |
|
| 1322 |
} |
| 1323 |
|
| 1324 |
else // Red/blue pixel |
| 1325 |
{ |
| 1326 |
|
| 1327 |
// b00 g01 b02 g03 b04 g05 b06 g07 b08 |
| 1328 |
// g10 r11 g12 r13 g14 r15 g16 r17 g18 |
| 1329 |
// b20 g21 b22 g23 b24 g25 b26 g27 b28 |
| 1330 |
// g30 r31 g32 r33 g34 r35 g36 r37 g38 |
| 1331 |
// b40 g41 b42 g43 b44 g45 b46 g47 b48 |
| 1332 |
// g50 r51 g52 r53 g54 r55 g56 r57 g58 |
| 1333 |
// b60 g61 b62 g63 b64 g65 b66 g67 b68 |
| 1334 |
// g70 r71 g72 r73 g74 r75 g76 r77 g78 |
| 1335 |
// b80 g81 b82 g83 b84 g85 b86 g87 b88 |
| 1336 |
|
| 1337 |
int32 b02 = p0 [2 * cs]; |
| 1338 |
int32 g03 = p0 [3 * cs]; |
| 1339 |
int32 g05 = p0 [5 * cs]; |
| 1340 |
int32 b06 = p0 [6 * cs]; |
| 1341 |
|
| 1342 |
int32 r13 = p1 [3 * cs]; |
| 1343 |
int32 r15 = p1 [5 * cs]; |
| 1344 |
|
| 1345 |
int32 b20 = p2 [0 * cs]; |
| 1346 |
int32 b22 = p2 [2 * cs]; |
| 1347 |
int32 g23 = p2 [3 * cs]; |
| 1348 |
int32 g25 = p2 [5 * cs]; |
| 1349 |
int32 b26 = p2 [6 * cs]; |
| 1350 |
int32 b28 = p2 [8 * cs]; |
| 1351 |
|
| 1352 |
int32 r31 = p3 [1 * cs]; |
| 1353 |
int32 g32 = p3 [2 * cs]; |
| 1354 |
int32 r33 = p3 [3 * cs]; |
| 1355 |
int32 r35 = p3 [5 * cs]; |
| 1356 |
int32 g36 = p3 [6 * cs]; |
| 1357 |
int32 r37 = p3 [7 * cs]; |
| 1358 |
|
| 1359 |
int32 g41 = p4 [1 * cs]; |
| 1360 |
int32 b42 = p4 [2 * cs]; |
| 1361 |
int32 g43 = p4 [3 * cs]; |
| 1362 |
int32 g45 = p4 [5 * cs]; |
| 1363 |
int32 b46 = p4 [6 * cs]; |
| 1364 |
int32 g47 = p4 [7 * cs]; |
| 1365 |
|
| 1366 |
int32 r51 = p5 [1 * cs]; |
| 1367 |
int32 g52 = p5 [2 * cs]; |
| 1368 |
int32 r53 = p5 [3 * cs]; |
| 1369 |
int32 r55 = p5 [5 * cs]; |
| 1370 |
int32 g56 = p5 [6 * cs]; |
| 1371 |
int32 r57 = p5 [7 * cs]; |
| 1372 |
|
| 1373 |
int32 b60 = p6 [0 * cs]; |
| 1374 |
int32 b62 = p6 [2 * cs]; |
| 1375 |
int32 g63 = p6 [3 * cs]; |
| 1376 |
int32 g65 = p6 [5 * cs]; |
| 1377 |
int32 b66 = p6 [6 * cs]; |
| 1378 |
int32 b68 = p6 [8 * cs]; |
| 1379 |
|
| 1380 |
int32 r73 = p7 [3 * cs]; |
| 1381 |
int32 r75 = p7 [5 * cs]; |
| 1382 |
|
| 1383 |
int32 b82 = p8 [2 * cs]; |
| 1384 |
int32 g83 = p8 [3 * cs]; |
| 1385 |
int32 g85 = p8 [5 * cs]; |
| 1386 |
int32 b86 = p8 [6 * cs]; |
| 1387 |
|
| 1388 |
est0 = b02 + b86; |
| 1389 |
|
| 1390 |
grad0 = Abs_int32 (b02 - b86) + |
| 1391 |
Abs_int32 (r13 - r55) + |
| 1392 |
Abs_int32 (r33 - r75) + |
| 1393 |
Abs_int32 (g03 - g45) + |
| 1394 |
Abs_int32 (g23 - g65) + |
| 1395 |
Abs_int32 (g43 - g85); |
| 1396 |
|
| 1397 |
est1 = b22 + b66; |
| 1398 |
|
| 1399 |
grad1 = Abs_int32 (b22 - b66) + |
| 1400 |
Abs_int32 (r13 - r35) + |
| 1401 |
Abs_int32 (r33 - r55) + |
| 1402 |
Abs_int32 (r53 - r75) + |
| 1403 |
Abs_int32 (g23 - g45) + |
| 1404 |
Abs_int32 (g43 - g65); |
| 1405 |
|
| 1406 |
est2 = b20 + b68; |
| 1407 |
|
| 1408 |
grad2 = Abs_int32 (b20 - b68) + |
| 1409 |
Abs_int32 (r31 - r55) + |
| 1410 |
Abs_int32 (r33 - r57) + |
| 1411 |
Abs_int32 (g23 - g47) + |
| 1412 |
Abs_int32 (g32 - g56) + |
| 1413 |
Abs_int32 (g41 - g65); |
| 1414 |
|
| 1415 |
est3 = b42 + b46; |
| 1416 |
|
| 1417 |
grad3 = Abs_int32 (b42 - b46) + |
| 1418 |
Abs_int32 (r33 - r35) + |
| 1419 |
Abs_int32 (r53 - r55) + |
| 1420 |
Abs_int32 (g32 - g36) + |
| 1421 |
Abs_int32 (g43 - g43) + |
| 1422 |
Abs_int32 (g52 - g56); |
| 1423 |
|
| 1424 |
est4 = b28 + b60; |
| 1425 |
|
| 1426 |
grad4 = Abs_int32 (b28 - b60) + |
| 1427 |
Abs_int32 (r37 - r53) + |
| 1428 |
Abs_int32 (r35 - r51) + |
| 1429 |
Abs_int32 (g25 - g41) + |
| 1430 |
Abs_int32 (g36 - g52) + |
| 1431 |
Abs_int32 (g47 - g63); |
| 1432 |
|
| 1433 |
est5 = b26 + b62; |
| 1434 |
|
| 1435 |
grad5 = Abs_int32 (b26 - b62) + |
| 1436 |
Abs_int32 (r15 - r33) + |
| 1437 |
Abs_int32 (r35 - r53) + |
| 1438 |
Abs_int32 (r55 - r73) + |
| 1439 |
Abs_int32 (g25 - g43) + |
| 1440 |
Abs_int32 (g45 - g63); |
| 1441 |
|
| 1442 |
est6 = b06 + b82; |
| 1443 |
|
| 1444 |
grad6 = Abs_int32 (b06 - b82) + |
| 1445 |
Abs_int32 (r15 - r53) + |
| 1446 |
Abs_int32 (r35 - r73) + |
| 1447 |
Abs_int32 (g05 - g43) + |
| 1448 |
Abs_int32 (g25 - g63) + |
| 1449 |
Abs_int32 (g45 - g83); |
| 1450 |
|
| 1451 |
lower = Min_uint32 (b42, b46); |
| 1452 |
upper = Max_uint32 (b42, b46); |
| 1453 |
|
| 1454 |
} |
| 1455 |
|
| 1456 |
uint32 minGrad = Min_uint32 (grad0, grad1); |
| 1457 |
|
| 1458 |
minGrad = Min_uint32 (minGrad, grad2); |
| 1459 |
minGrad = Min_uint32 (minGrad, grad3); |
| 1460 |
minGrad = Min_uint32 (minGrad, grad4); |
| 1461 |
minGrad = Min_uint32 (minGrad, grad5); |
| 1462 |
minGrad = Min_uint32 (minGrad, grad6); |
| 1463 |
|
| 1464 |
uint32 limit = (minGrad * 3) >> 1; |
| 1465 |
|
| 1466 |
uint32 total = 0; |
| 1467 |
uint32 count = 0; |
| 1468 |
|
| 1469 |
if (grad0 <= limit) |
| 1470 |
{ |
| 1471 |
total += est0; |
| 1472 |
count += 2; |
| 1473 |
} |
| 1474 |
|
| 1475 |
if (grad1 <= limit) |
| 1476 |
{ |
| 1477 |
total += est1; |
| 1478 |
count += 2; |
| 1479 |
} |
| 1480 |
|
| 1481 |
if (grad2 <= limit) |
| 1482 |
{ |
| 1483 |
total += est2; |
| 1484 |
count += 2; |
| 1485 |
} |
| 1486 |
|
| 1487 |
if (grad3 <= limit) |
| 1488 |
{ |
| 1489 |
total += est3; |
| 1490 |
count += 2; |
| 1491 |
} |
| 1492 |
|
| 1493 |
if (grad4 <= limit) |
| 1494 |
{ |
| 1495 |
total += est4; |
| 1496 |
count += 2; |
| 1497 |
} |
| 1498 |
|
| 1499 |
if (grad5 <= limit) |
| 1500 |
{ |
| 1501 |
total += est5; |
| 1502 |
count += 2; |
| 1503 |
} |
| 1504 |
|
| 1505 |
if (grad6 <= limit) |
| 1506 |
{ |
| 1507 |
total += est6; |
| 1508 |
count += 2; |
| 1509 |
} |
| 1510 |
|
| 1511 |
count = Max_uint32 (count, 1); // Suppress div-by-zero warning. |
| 1512 |
|
| 1513 |
uint32 estimate = (total + (count >> 1)) / count; |
| 1514 |
|
| 1515 |
p4 [4] = (uint16) Pin_uint32 (lower, estimate, upper); |
| 1516 |
|
| 1517 |
} |
| 1518 |
|
| 1519 |
} |
| 1520 |
|
| 1521 |
/*****************************************************************************/ |
| 1522 |
|
| 1523 |
void dng_opcode_FixBadPixelsList::FixSingleRow (dng_pixel_buffer &buffer, |
| 1524 |
const dng_rect &badRect) |
| 1525 |
{ |
| 1526 |
|
| 1527 |
dng_pixel_buffer tBuffer = buffer; |
| 1528 |
|
| 1529 |
tBuffer.fArea = Transpose (buffer.fArea); |
| 1530 |
|
| 1531 |
tBuffer.fRowStep = buffer.fColStep; |
| 1532 |
tBuffer.fColStep = buffer.fRowStep; |
| 1533 |
|
| 1534 |
dng_rect tBadRect = Transpose (badRect); |
| 1535 |
|
| 1536 |
FixSingleColumn (tBuffer, tBadRect); |
| 1537 |
|
| 1538 |
} |
| 1539 |
|
| 1540 |
/*****************************************************************************/ |
| 1541 |
|
| 1542 |
void dng_opcode_FixBadPixelsList::FixClusteredRect (dng_pixel_buffer &buffer, |
| 1543 |
const dng_rect &badRect, |
| 1544 |
const dng_rect &imageBounds) |
| 1545 |
{ |
| 1546 |
|
| 1547 |
const uint32 kNumSets = 8; |
| 1548 |
const uint32 kSetSize = 8; |
| 1549 |
|
| 1550 |
static const int32 kOffset [kNumSets] [kSetSize] [2] = |
| 1551 |
{ |
| 1552 |
{ |
| 1553 |
{ -1, 1 }, |
| 1554 |
{ -1, -1 }, |
| 1555 |
{ 1, -1 }, |
| 1556 |
{ 1, 1 }, |
| 1557 |
{ 0, 0 }, |
| 1558 |
{ 0, 0 }, |
| 1559 |
{ 0, 0 }, |
| 1560 |
{ 0, 0 } |
| 1561 |
}, |
| 1562 |
{ |
| 1563 |
{ -2, 0 }, |
| 1564 |
{ 2, 0 }, |
| 1565 |
{ 0, -2 }, |
| 1566 |
{ 0, 2 }, |
| 1567 |
{ 0, 0 }, |
| 1568 |
{ 0, 0 }, |
| 1569 |
{ 0, 0 }, |
| 1570 |
{ 0, 0 } |
| 1571 |
}, |
| 1572 |
{ |
| 1573 |
{ -2, -2 }, |
| 1574 |
{ -2, 2 }, |
| 1575 |
{ 2, -2 }, |
| 1576 |
{ 2, 2 }, |
| 1577 |
{ 0, 0 }, |
| 1578 |
{ 0, 0 }, |
| 1579 |
{ 0, 0 }, |
| 1580 |
{ 0, 0 } |
| 1581 |
}, |
| 1582 |
{ |
| 1583 |
{ -1, -3 }, |
| 1584 |
{ -3, -1 }, |
| 1585 |
{ 1, -3 }, |
| 1586 |
{ 3, -1 }, |
| 1587 |
{ -1, 3 }, |
| 1588 |
{ -3, 1 }, |
| 1589 |
{ 1, 3 }, |
| 1590 |
{ 3, 1 } |
| 1591 |
}, |
| 1592 |
{ |
| 1593 |
{ -4, 0 }, |
| 1594 |
{ 4, 0 }, |
| 1595 |
{ 0, -4 }, |
| 1596 |
{ 0, 4 }, |
| 1597 |
{ 0, 0 }, |
| 1598 |
{ 0, 0 }, |
| 1599 |
{ 0, 0 }, |
| 1600 |
{ 0, 0 } |
| 1601 |
}, |
| 1602 |
{ |
| 1603 |
{ -3, -3 }, |
| 1604 |
{ -3, 3 }, |
| 1605 |
{ 3, -3 }, |
| 1606 |
{ 3, 3 }, |
| 1607 |
{ 0, 0 }, |
| 1608 |
{ 0, 0 }, |
| 1609 |
{ 0, 0 }, |
| 1610 |
{ 0, 0 } |
| 1611 |
}, |
| 1612 |
{ |
| 1613 |
{ -2, -4 }, |
| 1614 |
{ -4, -2 }, |
| 1615 |
{ 2, -4 }, |
| 1616 |
{ 4, -2 }, |
| 1617 |
{ -2, 4 }, |
| 1618 |
{ -4, 2 }, |
| 1619 |
{ 2, 4 }, |
| 1620 |
{ 4, 2 } |
| 1621 |
}, |
| 1622 |
{ |
| 1623 |
{ -4, -4 }, |
| 1624 |
{ -4, 4 }, |
| 1625 |
{ 4, -4 }, |
| 1626 |
{ 4, 4 }, |
| 1627 |
{ 0, 0 }, |
| 1628 |
{ 0, 0 }, |
| 1629 |
{ 0, 0 }, |
| 1630 |
{ 0, 0 } |
| 1631 |
} |
| 1632 |
}; |
| 1633 |
|
| 1634 |
bool didFail = false; |
| 1635 |
|
| 1636 |
for (int32 row = badRect.t; row < badRect.b; row++) |
| 1637 |
{ |
| 1638 |
|
| 1639 |
for (int32 col = badRect.l; col < badRect.r; col++) |
| 1640 |
{ |
| 1641 |
|
| 1642 |
uint16 *p = buffer.DirtyPixel_uint16 (row, col, 0); |
| 1643 |
|
| 1644 |
bool isGreen = IsGreen (row, col); |
| 1645 |
|
| 1646 |
bool didFixPixel = false; |
| 1647 |
|
| 1648 |
for (uint32 set = 0; set < kNumSets && !didFixPixel; set++) |
| 1649 |
{ |
| 1650 |
|
| 1651 |
if (!isGreen && (kOffset [set] [0] [0] & 1) == 1) |
| 1652 |
{ |
| 1653 |
continue; |
| 1654 |
} |
| 1655 |
|
| 1656 |
uint32 total = 0; |
| 1657 |
uint32 count = 0; |
| 1658 |
|
| 1659 |
for (uint32 entry = 0; entry < kSetSize; entry++) |
| 1660 |
{ |
| 1661 |
|
| 1662 |
dng_point offset (kOffset [set] [entry] [0], |
| 1663 |
kOffset [set] [entry] [1]); |
| 1664 |
|
| 1665 |
if (offset.v == 0 && |
| 1666 |
offset.h == 0) |
| 1667 |
{ |
| 1668 |
break; |
| 1669 |
} |
| 1670 |
|
| 1671 |
if (fList->IsPointValid (dng_point (row, col) + offset, |
| 1672 |
imageBounds)) |
| 1673 |
{ |
| 1674 |
|
| 1675 |
total += p [offset.v * buffer.fRowStep + |
| 1676 |
offset.h * buffer.fColStep]; |
| 1677 |
|
| 1678 |
count++; |
| 1679 |
|
| 1680 |
} |
| 1681 |
|
| 1682 |
} |
| 1683 |
|
| 1684 |
if (count) |
| 1685 |
{ |
| 1686 |
|
| 1687 |
uint32 estimate = (total + (count >> 1)) / count; |
| 1688 |
|
| 1689 |
p [0] = (uint16) estimate; |
| 1690 |
|
| 1691 |
didFixPixel = true; |
| 1692 |
|
| 1693 |
} |
| 1694 |
|
| 1695 |
} |
| 1696 |
|
| 1697 |
if (!didFixPixel) |
| 1698 |
{ |
| 1699 |
|
| 1700 |
didFail = true; |
| 1701 |
|
| 1702 |
} |
| 1703 |
|
| 1704 |
} |
| 1705 |
|
| 1706 |
} |
| 1707 |
|
| 1708 |
#if qDNGValidate |
| 1709 |
|
| 1710 |
if (didFail) |
| 1711 |
{ |
| 1712 |
|
| 1713 |
ReportWarning ("Unable to repair bad rectangle"); |
| 1714 |
|
| 1715 |
} |
| 1716 |
|
| 1717 |
#else |
| 1718 |
|
| 1719 |
(void) didFail; |
| 1720 |
|
| 1721 |
#endif |
| 1722 |
|
| 1723 |
} |
| 1724 |
|
| 1725 |
/*****************************************************************************/ |
| 1726 |
|
| 1727 |
void dng_opcode_FixBadPixelsList::ProcessArea (dng_negative & /* negative */, |
| 1728 |
uint32 /* threadIndex */, |
| 1729 |
dng_pixel_buffer &srcBuffer, |
| 1730 |
dng_pixel_buffer &dstBuffer, |
| 1731 |
const dng_rect &dstArea, |
| 1732 |
const dng_rect &imageBounds) |
| 1733 |
{ |
| 1734 |
|
| 1735 |
uint32 pointCount = fList->PointCount (); |
| 1736 |
uint32 rectCount = fList->RectCount (); |
| 1737 |
|
| 1738 |
dng_rect fixArea = dstArea; |
| 1739 |
|
| 1740 |
if (rectCount) |
| 1741 |
{ |
| 1742 |
fixArea.t -= kBadRectPadding; |
| 1743 |
fixArea.l -= kBadRectPadding; |
| 1744 |
fixArea.b += kBadRectPadding; |
| 1745 |
fixArea.r += kBadRectPadding; |
| 1746 |
} |
| 1747 |
|
| 1748 |
bool didFixPoint = false; |
| 1749 |
|
| 1750 |
if (pointCount) |
| 1751 |
{ |
| 1752 |
|
| 1753 |
for (uint32 pointIndex = 0; pointIndex < pointCount; pointIndex++) |
| 1754 |
{ |
| 1755 |
|
| 1756 |
dng_point badPoint = fList->Point (pointIndex); |
| 1757 |
|
| 1758 |
if (badPoint.v >= fixArea.t && |
| 1759 |
badPoint.h >= fixArea.l && |
| 1760 |
badPoint.v < fixArea.b && |
| 1761 |
badPoint.h < fixArea.r) |
| 1762 |
{ |
| 1763 |
|
| 1764 |
bool isIsolated = fList->IsPointIsolated (pointIndex, |
| 1765 |
kBadPointPadding); |
| 1766 |
|
| 1767 |
if (isIsolated && |
| 1768 |
badPoint.v >= imageBounds.t + kBadPointPadding && |
| 1769 |
badPoint.h >= imageBounds.l + kBadPointPadding && |
| 1770 |
badPoint.v < imageBounds.b - kBadPointPadding && |
| 1771 |
badPoint.h < imageBounds.r - kBadPointPadding) |
| 1772 |
{ |
| 1773 |
|
| 1774 |
FixIsolatedPixel (srcBuffer, |
| 1775 |
badPoint); |
| 1776 |
|
| 1777 |
} |
| 1778 |
|
| 1779 |
else |
| 1780 |
{ |
| 1781 |
|
| 1782 |
FixClusteredPixel (srcBuffer, |
| 1783 |
pointIndex, |
| 1784 |
imageBounds); |
| 1785 |
|
| 1786 |
} |
| 1787 |
|
| 1788 |
didFixPoint = true; |
| 1789 |
|
| 1790 |
} |
| 1791 |
|
| 1792 |
} |
| 1793 |
|
| 1794 |
} |
| 1795 |
|
| 1796 |
if (rectCount) |
| 1797 |
{ |
| 1798 |
|
| 1799 |
if (didFixPoint) |
| 1800 |
{ |
| 1801 |
|
| 1802 |
srcBuffer.RepeatSubArea (imageBounds, |
| 1803 |
SrcRepeat ().v, |
| 1804 |
SrcRepeat ().h); |
| 1805 |
|
| 1806 |
} |
| 1807 |
|
| 1808 |
for (uint32 rectIndex = 0; rectIndex < rectCount; rectIndex++) |
| 1809 |
{ |
| 1810 |
|
| 1811 |
dng_rect badRect = fList->Rect (rectIndex); |
| 1812 |
|
| 1813 |
dng_rect overlap = dstArea & badRect; |
| 1814 |
|
| 1815 |
if (overlap.NotEmpty ()) |
| 1816 |
{ |
| 1817 |
|
| 1818 |
bool isIsolated = fList->IsRectIsolated (rectIndex, |
| 1819 |
kBadRectPadding); |
| 1820 |
|
| 1821 |
if (isIsolated && |
| 1822 |
badRect.r == badRect.l + 1 && |
| 1823 |
badRect.l >= imageBounds.l + SrcRepeat ().h && |
| 1824 |
badRect.r <= imageBounds.r - SrcRepeat ().v) |
| 1825 |
{ |
| 1826 |
|
| 1827 |
FixSingleColumn (srcBuffer, |
| 1828 |
overlap); |
| 1829 |
|
| 1830 |
} |
| 1831 |
|
| 1832 |
else if (isIsolated && |
| 1833 |
badRect.b == badRect.t + 1 && |
| 1834 |
badRect.t >= imageBounds.t + SrcRepeat ().h && |
| 1835 |
badRect.b <= imageBounds.b - SrcRepeat ().v) |
| 1836 |
{ |
| 1837 |
|
| 1838 |
FixSingleRow (srcBuffer, |
| 1839 |
overlap); |
| 1840 |
|
| 1841 |
} |
| 1842 |
|
| 1843 |
else |
| 1844 |
{ |
| 1845 |
|
| 1846 |
FixClusteredRect (srcBuffer, |
| 1847 |
overlap, |
| 1848 |
imageBounds); |
| 1849 |
|
| 1850 |
} |
| 1851 |
|
| 1852 |
} |
| 1853 |
|
| 1854 |
} |
| 1855 |
|
| 1856 |
} |
| 1857 |
|
| 1858 |
dstBuffer.CopyArea (srcBuffer, |
| 1859 |
dstArea, |
| 1860 |
0, |
| 1861 |
dstBuffer.fPlanes); |
| 1862 |
|
| 1863 |
} |
| 1864 |
|
| 1865 |
/*****************************************************************************/ |