OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimWatermarkFilter.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 // Copyright (c) 2005, David Burken, all rights reserved.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: David Burken
7 //
8 // Description: Class definition of ossimWatermarkFilter.
9 // Applies an image or watermark to image. Positioning is based on mode.
10 // Density is base on alpha weight.
11 //
12 //----------------------------------------------------------------------------
13 // $Id: ossimWatermarkFilter.cpp 15766 2009-10-20 12:37:09Z gpotts $
14 
15 #include <vector>
16 
18 #include <ossim/base/ossimTrace.h>
27 
29 
30 
32 
33 static ossimTrace traceDebug(ossimString("ossimWatermarkFilter:debug"));
34 
35 // Keywords:
36 static const char WATERMARK_MODE_KW[] = "watermark_mode";
37 static const char WEIGHT_KW[] = "weight";
38 
39 #ifdef OSSIM_ID_ENABLED
40 static const char OSSIM_ID[] = "$Id: ossimWatermarkFilter.cpp 15766 2009-10-20 12:37:09Z gpotts $";
41 #endif
42 
44 
46  :
47  theFilename(ossimFilename::NIL),
48  theWatermarkWeight(DEFAULT_WEIGHT),
49  theTile(NULL),
50  theWatermark(NULL),
51  theMode(ossimWatermarkFilter::UPPER_LEFT),
52  theInputBoundingRect(),
53  theDirtyFlag(true)
54 {
55  theEnableFlag = true;
56 
57  if (traceDebug())
58  {
60  << "ossimPixelFlipper::ossimPixelFlipper" << std::endl;
61 #ifdef OSSIM_ID_ENABLED
63  << "OSSIM_ID: " << OSSIM_ID << std::endl;
64 #endif
65  }
66 }
67 
69 {
70  // Dereference tiles and force a delete if last reference.
71  theWatermark = NULL;
72  theTile = NULL;
73 }
74 
76 {
77  return ossimString("Watermark Filter");
78 }
79 
81 {
82  return ossimString("Watermark Filter - Applies watermark image onto getTile Request.");
83 }
84 
86 {
87  ossimString description;
88  description = getLongName();
89  description += "\n";
90  description += "Valid modes:\n";
91 
92  vector<ossimString> list;
93  getModeList(list);
94 
95  vector<ossimString>::const_iterator i = list.begin();
96  while (i != list.end())
97  {
98  description +=(*i);
99  description += "\n";
100  ++i;
101  }
102 
103  return description;
104 }
105 
107  const ossimIrect& tile_rect, ossim_uint32 resLevel)
108 {
109  // Lock for the length of this method.
110  // Check for input.
111  if (!theInputConnection)
112  {
113  if (theTile.valid())
114  {
115  theTile->setImageRectangle(tile_rect);
116  theTile->makeBlank();
117  }
118  return theTile;
119  }
120 
121  // Fetch a tile from from the input source.
122  ossimRefPtr<ossimImageData> inputTile =
123  theInputConnection->getTile(tile_rect, resLevel);
124 
125  // Check for bypass.
126  if (theEnableFlag == false) return inputTile;
127 
128  // Check for weight being 0.0.
129  if (theWatermarkWeight == 0.0) return inputTile;
130 
131  //---
132  // Check for dirty state.
133  // Note: This is set in initialize if something changes.
134  //---
135  if (theDirtyFlag == true)
136  {
137  if (allocate() == false) // Something not right if false.
138  {
139  return inputTile;
140  }
141  }
142 
143  // We will only watermark (process) within the input bounding rectangle.
144  if (tile_rect.intersects(theInputBoundingRect) == false)
145  {
146  return inputTile;
147  }
148 
149  // Capture the rectangle and blank out theTile.
150  theTile->setImageRectangle(tile_rect);
151 
152  if (inputTile.valid() &&
153  (inputTile->getDataObjectStatus() != OSSIM_NULL))
154  {
155  // Copy the inputTile to theTile.
156  theTile->loadTile(inputTile.get());
157  }
158  else
159  {
160  theTile->makeBlank();
161  }
162 
163  // Write the watermarks...
164  switch(theTile->getScalarType())
165  {
166  case OSSIM_UINT8:
167  {
168  fill(ossim_uint8(0));
169  break;
170  }
171  case OSSIM_SINT8:
172  {
173  fill(ossim_sint8(0));
174  break;
175  }
176  case OSSIM_USHORT11:
177  case OSSIM_USHORT12:
178  case OSSIM_USHORT13:
179  case OSSIM_USHORT14:
180  case OSSIM_USHORT15:
181  case OSSIM_UINT16:
182  {
183  fill(ossim_uint16(0));
184  break;
185  }
186  case OSSIM_SINT16:
187  {
188  fill(ossim_sint16(0));
189  break;
190  }
191  case OSSIM_UINT32:
192  {
193  fill(ossim_uint32(0));
194  break;
195  }
196  case OSSIM_SINT32:
197  {
198  fill(ossim_sint32(0));
199  break;
200  }
201  case OSSIM_FLOAT32:
203  {
204  fill(ossim_float32(0));
205  break;
206  }
207  case OSSIM_FLOAT64:
209  {
210  fill(ossim_float32(0));
211  break;
212  }
214  default:
215  {
217  << "Scalar type = " << theTile->getScalarType()
218  << " Not supported by ossimWatermarkFilter" << std::endl;
219  return inputTile;
220  }
221  }
222 
223  return theTile;
224 }
225 
226 template <class T> void ossimWatermarkFilter::fill(T /* dummy */)
227 {
228  const ossimIrect TILE_RECT = theTile->getImageRectangle();
229 
230  // We will only fill data within the input bounding rect.
231  const ossimIrect CLIPPED_TILE_RECT =
232  TILE_RECT.clipToRect(theInputBoundingRect);
233 
234  // Get the bounding rectangles.
235  vector<ossimIrect> rects(0);
236  getIntersectingRects(rects);
237 
238  if (rects.size() == 0)
239  {
240  return;
241  }
242 
243  //---
244  // Have watermark rectangles that intersect this tile so we need to process.
245  //---
246  ossim_uint32 band = 0;
247  ossim_float64 inputPixWeight = 1.0 - theWatermarkWeight;
248 
249  // Get a pointers to the watermark buffers (wmBuf) and nulls wn.
250  T** wmBuf = new T*[theWatermarkNumberOfBands];
251  for (band = 0; band < theWatermarkNumberOfBands; ++band)
252  {
253  wmBuf[band] = static_cast<T*>(theWatermark->getBuf(band));
254  }
255 
256  // Get a pointers to the output tile buffers and nulls in.
257  T** otBuf = new T*[theInputNumberOfBands];
258  for (band = 0; band < theInputNumberOfBands; ++band)
259  {
260  otBuf[band] = static_cast<T*>(theTile->getBuf(band));
261  }
262 
263  // Get the width of the buffers for indexing.
264  ossim_int32 wmWidth = static_cast<ossim_int32>(theWatermark->getWidth());
265  ossim_int32 otWidth = static_cast<ossim_int32>(theTile->getWidth());
266 
267  const ossim_float64* wmNull = theWatermark->getNullPix();
268  const ossim_float64* otMin = theTile->getMinPix();
269  const ossim_float64* otMax = theTile->getMaxPix();
270  const ossim_float64* otNull = theTile->getNullPix();
271 
272 
273  // Control loop through intersecting rectangles.
274  vector<ossimIrect>::const_iterator i = rects.begin();
275  while (i != rects.end())
276  {
277  if ( (*i).intersects(CLIPPED_TILE_RECT) )
278  {
279  //---
280  // This is the rectangle we want to fill relative to requesting
281  // image space.
282  //---
283  const ossimIrect CLIPPED_WATERMARRK_RECT =
284  (*i).clipToRect(CLIPPED_TILE_RECT);
285 
286  ossim_int32 clipHeight = CLIPPED_WATERMARRK_RECT.height();
287  ossim_int32 clipWidth = CLIPPED_WATERMARRK_RECT.width();
288 
289  // Compute the starting offset into the wmBuf and otBuf.
290  ossim_int32 wmOffset =
291  (CLIPPED_WATERMARRK_RECT.ul().y - (*i).ul().y) * wmWidth +
292  CLIPPED_WATERMARRK_RECT.ul().x - (*i).ul().x;
293  ossim_int32 otOffset =
294  (CLIPPED_WATERMARRK_RECT.ul().y - TILE_RECT.ul().y)* otWidth +
295  CLIPPED_WATERMARRK_RECT.ul().x - TILE_RECT.ul().x;
296 
297  // Line loop...
298  for (ossim_int32 line = 0; line < clipHeight; ++line)
299  {
300  // Sample loop...
301  for (ossim_int32 sample = 0; sample < clipWidth; ++sample)
302  {
303  // Output band control loop until all output bands are filled.
304  ossim_uint32 otBand = 0;
305  while (otBand < theInputNumberOfBands)
306  {
307  // Band loop through the watermark.
308  for (ossim_uint32 wmBand = 0;
309  wmBand < theWatermarkNumberOfBands;
310  ++wmBand)
311  {
312  if (wmBuf[wmBand][wmOffset+sample] != wmNull[wmBand])
313  {
314  // Apply the weight to the input pixel.
315  ossim_float64 p1 =
316  (otBuf[otBand][otOffset+sample] != otNull[otBand]) ?
317  otBuf[otBand][otOffset+sample] * inputPixWeight :
318  0.0;
319 
320  // Apply the Weight to the watermark pixel.
321  ossim_float64 p2 =
322  wmBuf[wmBand][wmOffset+sample]*theWatermarkWeight;
323 
324  // Add them up.
325  ossim_float64 p3 = p1 + p2;
326 
327  // Cast to output type with range checking.
328  otBuf[otBand][otOffset+sample] = static_cast<T>(
329  ( (p3 >= otMin[otBand]) ?
330  (p3 < otMax[otBand] ? p3 : otMax[otBand]) :
331  otNull[otBand]) );
332  }
333  ++otBand;
334 
335  // We stop when we reach here. All output bands filled.
336  if (otBand == theInputNumberOfBands)
337  {
338  break;
339  }
340 
341  } // End of band through watermark.
342 
343  } // End of outer band loop.
344 
345  } // End of sample loop.
346 
347  wmOffset += wmWidth;
348  otOffset += otWidth;
349 
350  } // End of line loop.
351 
352  } // End "if ( (*i).intersects(TILE_RECT) )"
353 
354  ++i; // Go to next rectangle to fill if any.
355 
356  } // End of "while (i != rects.end())"
357 
358  // Clean up.
359  delete [] wmBuf;
360  delete [] otBuf;
361 
362  theTile->validate();
363 }
364 
365 void ossimWatermarkFilter::getIntersectingRects(vector<ossimIrect>& rects)
366 {
367  switch(theMode)
368  {
369  case UPPER_LEFT:
370  getUpperLeftRect(rects);
371  break;
372  case UPPER_CENTER:
373  getUpperCenterRect(rects);
374  break;
375  case UPPER_RIGHT:
376  getUpperRightRect(rects);
377  break;
378  case CENTER:
379  getCenterRect(rects);
380  break;
381  case LOWER_LEFT:
382  getLowerLeftRect(rects);
383  break;
384  case LOWER_CENTER:
385  getLowerCenterRect(rects);
386  break;
387  case LOWER_RIGHT:
388  getLowerRightRect(rects);
389  break;
390  case UNIFORM_DENSE:
391  getUniformDenseRects(rects);
392  break;
393  case UNIFORM_SPARSE:
394  getUniformSparceRects(rects);
395  break;
396  default:
397  break;
398  }
399 }
400 
401 void ossimWatermarkFilter::getUpperLeftRect(vector<ossimIrect>& rects)
402 {
403  // First clip the rect to the bounding image rectangle.
404  const ossimIrect CLIP_RECT =
408  if (r.intersects(CLIP_RECT))
409  {
410  rects.push_back(r);
411  }
412 }
413 
414 void ossimWatermarkFilter::getUpperCenterRect(vector<ossimIrect>& rects)
415 {
416  // First clip the rect to the bounding image rectangle.
417  const ossimIrect CLIP_RECT =
419  ossim_uint32 watermarkWidth = theWatermark->getImageRectangle().width();
420  ossim_uint32 inputWidth = theInputBoundingRect.width();
421  ossimIpt origin = theInputBoundingRect.ul();
422 
423  // Input wider than watermark so center.
424  if (inputWidth > watermarkWidth)
425  {
426  ossim_int32 offset =
427  static_cast<ossim_int32>((inputWidth - watermarkWidth) / 2);
428  origin.x = origin.x + offset;
429  }
430 
431  theWatermark->setOrigin(origin);
432 
434  if (r.intersects(CLIP_RECT))
435  {
436  rects.push_back(r);
437  }
438 }
439 
440 void ossimWatermarkFilter::getUpperRightRect(vector<ossimIrect>& rects)
441 {
442  // First clip the rect to the bounding image rectangle.
443  const ossimIrect CLIP_RECT =
445  ossim_uint32 watermarkWidth =
447  ossim_uint32 inputWidth = theInputBoundingRect.width();
448 
449  ossimIpt origin = theInputBoundingRect.ul();
450 
451  // Input wider than watermark so center.
452  if (inputWidth > watermarkWidth)
453  {
454  ossim_int32 offset =
455  static_cast<ossim_int32>(inputWidth - watermarkWidth);
456  origin.x = origin.x + offset;
457  }
458 
459  theWatermark->setOrigin(origin);
460 
462  if (r.intersects(CLIP_RECT))
463  {
464  rects.push_back(r);
465  }
466 }
467 
468 void ossimWatermarkFilter::getCenterRect(vector<ossimIrect>& rects)
469 {
470  // First clip the rect to the bounding image rectangle.
471  const ossimIrect CLIP_RECT =
473  ossim_uint32 watermarkWidth = theWatermark->getImageRectangle().width();
474  ossim_uint32 watermarkHeight = theWatermark->getImageRectangle().height();
475  ossim_uint32 inputWidth = theInputBoundingRect.width();
476  ossim_uint32 inputHeight = theInputBoundingRect.height();
477  ossimIpt origin = theInputBoundingRect.ul();
478 
479  // Input wider than watermark so center.
480  if (inputWidth > watermarkWidth)
481  {
482  ossim_int32 offset =
483  static_cast<ossim_int32>((inputWidth - watermarkWidth) / 2);
484  origin.x = origin.x + offset;
485  }
486  // Input higher than watermark so center.
487  if (inputHeight > watermarkHeight)
488  {
489  ossim_int32 offset =
490  static_cast<ossim_int32>((inputHeight - watermarkHeight) / 2);
491  origin.y = origin.y + offset;
492  }
493 
494  theWatermark->setOrigin(origin);
495 
497  if (r.intersects(CLIP_RECT))
498  {
499  rects.push_back(r);
500  }
501 }
502 
503 void ossimWatermarkFilter::getLowerLeftRect(vector<ossimIrect>& rects)
504 {
505  // First clip the rect to the bounding image rectangle.
506  const ossimIrect CLIP_RECT =
508  ossim_uint32 watermarkHeight = theWatermark->getImageRectangle().height();
509  ossim_uint32 inputHeight = theInputBoundingRect.height();
510  ossimIpt origin = theInputBoundingRect.ul();
511 
512  // Input higher than watermark so apply offset.
513  if (inputHeight > watermarkHeight)
514  {
515  ossim_int32 offset =
516  static_cast<ossim_int32>(inputHeight - watermarkHeight);
517  origin.y = origin.y + offset;
518  }
519 
520  theWatermark->setOrigin(origin);
521 
523  if (r.intersects(CLIP_RECT))
524  {
525  rects.push_back(r);
526  }
527 }
528 
529 void ossimWatermarkFilter::getLowerCenterRect(vector<ossimIrect>& rects)
530 {
531  // First clip the rect to the bounding image rectangle.
532  const ossimIrect CLIP_RECT =
534  ossim_uint32 watermarkWidth = theWatermark->getImageRectangle().width();
535  ossim_uint32 watermarkHeight = theWatermark->getImageRectangle().height();
536  ossim_uint32 inputWidth = theInputBoundingRect.width();
537  ossim_uint32 inputHeight = theInputBoundingRect.height();
538  ossimIpt origin = theInputBoundingRect.ul();
539 
540  // Input wider than watermark so center.
541  if (inputWidth > watermarkWidth)
542  {
543  ossim_int32 offset =
544  static_cast<ossim_int32>((inputWidth - watermarkWidth) / 2);
545  origin.x = origin.x + offset;
546  }
547  // Input higher than watermark so apply offset.
548  if (inputHeight > watermarkHeight)
549  {
550  ossim_int32 offset =
551  static_cast<ossim_int32>(inputHeight - watermarkHeight);
552  origin.y = origin.y + offset;
553  }
554 
555  theWatermark->setOrigin(origin);
557  if (r.intersects(CLIP_RECT))
558  {
559  rects.push_back(r);
560  }
561 }
562 
563 void ossimWatermarkFilter::getLowerRightRect(vector<ossimIrect>& rects)
564 {
565  // First clip the rect to the bounding image rectangle.
566  const ossimIrect CLIP_RECT =
568  ossim_uint32 watermarkWidth = theWatermark->getImageRectangle().width();
569  ossim_uint32 watermarkHeight = theWatermark->getImageRectangle().height();
570  ossim_uint32 inputWidth = theInputBoundingRect.width();
571  ossim_uint32 inputHeight = theInputBoundingRect.height();
572  ossimIpt origin = theInputBoundingRect.ul();
573 
574  // Input wider than watermark so center.
575  if (inputWidth > watermarkWidth)
576  {
577  ossim_int32 offset =
578  static_cast<ossim_int32>(inputWidth - watermarkWidth);
579  origin.x = origin.x + offset;
580  }
581  // Input higher than watermark so apply offset.
582  if (inputHeight > watermarkHeight)
583  {
584  ossim_int32 offset =
585  static_cast<ossim_int32>(inputHeight - watermarkHeight);
586  origin.y = origin.y + offset;
587  }
588 
589  theWatermark->setOrigin(origin);
591  if (r.intersects(CLIP_RECT))
592  {
593  rects.push_back(r);
594  }
595 
596 }
597 
598 void ossimWatermarkFilter::getUniformDenseRects(vector<ossimIrect>& rects)
599 {
600  // First clip the rect to the bounding image rectangle.
601  const ossimIrect CLIP_RECT =
603  ossim_uint32 watermarkWidth = theWatermark->getImageRectangle().width();
604  ossim_uint32 watermarkHeight = theWatermark->getImageRectangle().height();
605  ossim_uint32 inputWidth = theInputBoundingRect.width();
606  ossim_uint32 inputHeight = theInputBoundingRect.height();
607 
608  ossim_uint32 watermarksHigh = inputHeight / watermarkHeight;
609  if (inputHeight % watermarkHeight) ++watermarksHigh;
610 
611  ossim_uint32 watermarksWide = inputWidth / watermarkWidth;
612  if (inputWidth % watermarkWidth) ++watermarksWide;
613 
614  ossim_int32 xOffset = static_cast<ossim_int32>(watermarkWidth);
615  ossim_int32 yOffset = static_cast<ossim_int32>(watermarkHeight);
616 
617  ossimIpt origin = theInputBoundingRect.ul();
618 
619  for (ossim_uint32 y = 0; y < watermarksHigh; ++y)
620  {
621  for (ossim_uint32 x = 0; x < watermarksWide; ++x)
622  {
623  theWatermark->setOrigin(origin);
625  if (r.intersects(CLIP_RECT))
626  {
627  rects.push_back(r);
628  }
629  origin.x = origin.x + xOffset;
630  }
631  origin.y = origin.y + yOffset;
632  origin.x = theInputBoundingRect.ul().x;
633  }
634 }
635 
636 void ossimWatermarkFilter::getUniformSparceRects(vector<ossimIrect>& rects)
637 {
638  // First clip the rect to the bounding image rectangle.
639  const ossimIrect CLIP_RECT =
641  ossim_uint32 watermarkWidth = theWatermark->getImageRectangle().width();
642  ossim_uint32 watermarkHeight = theWatermark->getImageRectangle().height();
643  ossim_uint32 inputWidth = theInputBoundingRect.width();
644  ossim_uint32 inputHeight = theInputBoundingRect.height();
645  ossim_uint32 gapWidth = watermarkWidth/2;
646  ossim_uint32 gapHeight = watermarkHeight/2;
647 
648  ossim_uint32 watermarksHigh = inputHeight/(watermarkHeight+gapHeight);
649  if (inputHeight % watermarkHeight) ++watermarksHigh;
650 
651  ossim_uint32 watermarksWide = inputWidth/(watermarkWidth+gapWidth);
652  if (inputWidth % watermarkWidth) ++watermarksWide;
653 
654  ossim_int32 xOffset = static_cast<ossim_int32>(watermarkWidth + gapWidth);
655  ossim_int32 yOffset = static_cast<ossim_int32>(watermarkHeight + gapHeight);
656 
657  ossimIpt origin = theInputBoundingRect.ul();
658 
659  for (ossim_uint32 y = 0; y < watermarksHigh; ++y)
660  {
661  for (ossim_uint32 x = 0; x < watermarksWide; ++x)
662  {
663  theWatermark->setOrigin(origin);
665  if (r.intersects(CLIP_RECT))
666  {
667  rects.push_back(r);
668  }
669  origin.x = origin.x + xOffset;
670  }
671  origin.y = origin.y + yOffset;
672  origin.x = theInputBoundingRect.ul().x;
673  }
674 }
675 
677 {
678  //---
679  // If state is not already dirty and there is an input connection
680  // check for:
681  //
682  // 1) Scalar change
683  // 2) band number change
684  // 3) bounding box change
685  //
686  // Set state to dirty on a change.
687  //
688  // NOTE: This method intentionally only sets the dirty state and doesn't do
689  // anything else as it is called repetitively during chain setup or chain
690  // state changes.
691  //
692  // The first getTile call will do the real work, call allocate(),
693  // if the state is dirty.
694  //---
695 
696  // Lock for the length of this method.
697  // Set the input connection.
699 
700  // Once dirty flag is set no need to do it again.
701  if (theDirtyFlag == false)
702  {
703  if (theInputConnection)
704  {
705  // Check for scalar type change.
707  {
708  theDirtyFlag = true;
709  return;
710  }
711 
712  // Check for band change.
713  if (theInputNumberOfBands !=
715  {
716  theDirtyFlag = true;
717  return;
718  }
719 
720  // Check for bounding rectangle change.
722  {
723  theDirtyFlag = true;
724  return;
725  }
726  }
727  }
728 }
729 
731 {
732  // Capture the bounding rect:
734 
735  // Capture the scalar type:
737 
738  // Capture the number of bands:
740 
741  //---
742  // Check the watermark scalar type.
743  //---
744  if (theWatermark.valid())
745  {
747  {
748  //---
749  // We'll need to make a new one with a scalar remapper after it.
750  //---
751  theWatermark = NULL; // We'll need to make a new one.
752  }
753  }
754 
755  //---
756  // Make a new watermark tile. This will do a scalar remap if needed.
757  // If we don't have a watermark no point in going on...
758  //---
759  if (!theWatermark)
760  {
761  if (openWatermarkFile() == false)
762  {
763  return false;
764  }
765  }
766 
767  if (theTile.valid())
768  {
771  {
772  theTile = NULL; // We'll need to make a new one.
773  }
774  }
775 
776  // Make a new output tile if we need to.
777  if (!theTile)
778  {
781  if (theTile.valid())
782  {
783  theTile->initialize();
784  }
785  else
786  {
787  return false;
788  }
789  }
790 
791  //---
792  // If we get here things are good so clear the dirty flag so we don't
793  // get called again needlessly.
794  //---
795  theDirtyFlag = false;
796 
797  return true;
798 }
799 
801 {
802  if (traceDebug())
803  {
805  << "ossimWatermarkFilter::openWatermarkFile DEBUG: entered..."
806  << std::endl;
807  }
808 
810  {
811  return false;
812  }
813 
814  theWatermark = NULL; // This will destroy any previous tiles.
815 
816  // Open the watermark image.
819  if (!ih)
820  {
821  if (traceDebug())
822  {
824  << "ossimWatermarkFilter::openWatermarkFile"
825  << "\nCould not open: " << theFilename
826  << std::endl;
827  }
828 
829  return false;
830  }
832  {
833  if (traceDebug())
834  {
836  << "ossimWatermarkFilter::openWatermarkFile"
837  << "\nError reading image: " << theFilename
838  << std::endl;
839  return false;
840  }
841  }
842 
843  ih->initialize();
844  ossimRefPtr<ossimImageSource> imageSource = ih.get();
846 
848  {
849  // Remap the watemark to the same scalar type as the input.
850  remapper = new ossimScalarRemapper(imageSource.get(),
853  remapper->initialize();
854  imageSource = remapper.get();
855  }
856 
857  // Get the full image rectangle.
858  theWatermark = imageSource->getTile(ih->getImageRectangle(), 0);
859 
860  // Cleanup...
861  if (remapper.valid())
862  {
863  remapper->disconnect();
864  remapper = NULL;
865  }
866  if(ih.valid())
867  {
868  ih->disconnect();
869  ih = 0;
870  }
871  imageSource = 0;
872 
873  if (theWatermark.valid() == false)
874  {
875  return false;
876  }
877 
878  // Capture the bands as we will need this repetitively.
880 
881  if (traceDebug())
882  {
884  << "ossimWatermarkFilter::openWatermarkFile DEBUG:"
885  << *(theWatermark.get())
886  << endl;
887  }
888 
889  return true;
890 }
891 
893  const char* prefix) const
894 {
895  kwl.add(prefix,
897  theFilename.c_str());
898  kwl.add(prefix,
899  WATERMARK_MODE_KW,
900  getModeString().c_str());
901  kwl.add(prefix,
902  WEIGHT_KW,
904 
905  return ossimImageSourceFilter::saveState(kwl, prefix);
906 }
907 
909  const char* prefix)
910 {
911  // Do this first so connections get set up.
912  if (ossimImageSourceFilter::loadState(kwl, prefix) == false)
913  {
914  return false;
915  }
916 
917  const char* lookupReturn;
918 
919  lookupReturn = kwl.find(prefix, WEIGHT_KW);
920  if(lookupReturn)
921  {
922  setWeight(ossimString(lookupReturn).toDouble());
923  }
924 
925  lookupReturn = kwl.find(prefix, WATERMARK_MODE_KW);
926  if(lookupReturn)
927  {
928  setMode(ossimString(lookupReturn));
929  }
930 
931  lookupReturn = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
932  if(lookupReturn)
933  {
934  setFilename(lookupReturn);
935  }
936 
937  if (traceDebug())
938  {
940  << "ossimWatermarkFilter::loadState DEBUG:"
941  << std::endl;
943  }
944 
945  return true;
946 }
947 
949  const ossimString& name) const
950 {
951  // Lock for the length of this method.
952  if (name == ossimKeywordNames::FILENAME_KW)
953  {
954  ossimFilenameProperty* ofp =
957  ofp->setCacheRefreshBit();
959  }
960  else if (name == WATERMARK_MODE_KW)
961  {
962  vector<ossimString> constraintList;
963  getModeList(constraintList);
964 
966  new ossimStringProperty(name,
967  getModeString(),
968  false,
969  constraintList);
970  p->setCacheRefreshBit();
971  return ossimRefPtr<ossimProperty>(p);
972  }
973  else if (name == WEIGHT_KW)
974  {
975  ossimProperty* p =
976  new ossimNumericProperty(name,
978  p->setCacheRefreshBit();
979  return ossimRefPtr<ossimProperty>(p);
980  }
981 
983 }
984 
986 {
987  if (!property) return;
988 
989  ossimString os = property->valueToString();
990 
991  ossimString name = property->getName();
992  if (name == ossimKeywordNames::FILENAME_KW)
993  {
994  setFilename(os);
995  }
996  else if (name == WATERMARK_MODE_KW)
997  {
998  setMode(os);
999  }
1000  else if (name == WEIGHT_KW)
1001  {
1002  setWeight(os.toDouble());
1003  }
1004  else
1005  {
1007  }
1008 }
1009 
1011  std::vector<ossimString>& propertyNames) const
1012 {
1013  propertyNames.push_back(ossimKeywordNames::FILENAME_KW);
1014  propertyNames.push_back(WATERMARK_MODE_KW);
1015  propertyNames.push_back(WEIGHT_KW);
1017 }
1018 
1019 void ossimWatermarkFilter::getModeList(vector<ossimString>& list) const
1020 {
1021  list.clear();
1022  list.resize(ossimWatermarkFilter::END);
1023  list[0] = ossimString("upper_left");
1024  list[1] = ossimString("upper_center");
1025  list[2] = ossimString("upper_right");
1026  list[3] = ossimString("center");
1027  list[4] = ossimString("lower_left");
1028  list[5] = ossimString("lower_center");
1029  list[6] = ossimString("lower_right");
1030  list[7] = ossimString("uniform_dense");
1031  list[8] = ossimString("uniform_sparse");
1032 }
1033 
1035 {
1036  return theMode;
1037 }
1038 
1040 {
1041  switch(theMode)
1042  {
1043  case UPPER_LEFT:
1044  return ossimString("upper_left");
1045  case UPPER_CENTER:
1046  return ossimString("upper_center");
1047  case UPPER_RIGHT:
1048  return ossimString("upper_right");
1049  case CENTER:
1050  return ossimString("center");
1051  case LOWER_LEFT:
1052  return ossimString("lower_left");
1053  case LOWER_CENTER:
1054  return ossimString("lower_center");
1055  case LOWER_RIGHT:
1056  return ossimString("lower_right");
1057  case UNIFORM_DENSE:
1058  return ossimString("uniform_dense");
1059  case UNIFORM_SPARSE:
1060  return ossimString("uniform_sparse");
1061  default:
1062  break;
1063  }
1064 
1065  return ossimString("UNKNOWN_MODE");
1066 }
1067 
1069 {
1070  if (file != theFilename)
1071  {
1072  theFilename = file;
1073  theWatermark = NULL; // Will be reallocated next getTile.
1074  theDirtyFlag = true;
1075  }
1076 
1077  if (traceDebug())
1078  {
1080  << "ossimWatermarkFilter::setFilename DEBUG:" << std::endl;
1082  }
1083 }
1084 
1086 {
1087  ossimString os = mode;
1088  os.downcase();
1089 
1090  if (os == "upper_left")
1091  {
1092  theMode = UPPER_LEFT;
1093  }
1094  else if (os == "upper_center")
1095  {
1097  }
1098  else if (os == "upper_right")
1099  {
1100  theMode = UPPER_RIGHT;
1101  }
1102  else if (os == "center")
1103  {
1104  theMode = CENTER;
1105  }
1106  else if (os == "lower_left")
1107  {
1108  theMode = LOWER_LEFT;
1109  }
1110  else if (os == "lower_center")
1111  {
1113  }
1114  else if (os == "lower_right")
1115  {
1116  theMode = LOWER_RIGHT;
1117  }
1118  else if (os == "uniform_dense")
1119  {
1121  }
1122  else if (os == "uniform_sparse")
1123  {
1125  }
1126  else
1127  {
1128  // Invalid mode...
1129  if (traceDebug())
1130  {
1132  << "ossimWatermarkFilter::setMode DEBUG:"
1133  << "\nInvalid mode! " << mode
1134  << std::endl;
1135  }
1136  }
1137 }
1138 
1140 {
1141  if ( (weight >= 0.0) && (weight <= 1.0) )
1142  {
1143  theWatermarkWeight = weight;
1144  }
1145  if (traceDebug())
1146  {
1148  << "ossimWatermarkFilter::setWeight DEBUG:" << std::endl;
1150  }
1151 
1152 }
1153 
1155 {
1156  out << "ossimWatermarkFilter::print"
1157  << "\ntheFilename: " << theFilename
1158  << "\ntheWatermarkWeight: " << theWatermarkWeight
1159  << "\ntheMode: " << getModeString()
1160  << std::endl;
1161  return ossimImageSourceFilter::print(out);
1162 }
1163 
16 bit unsigned integer (15 bits used)
virtual std::ostream & print(std::ostream &out) const
Print method.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of the object from a keyword list.
8 bit signed integer
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Set property.
virtual ossim_uint32 getWidth() const
ossim_uint32 x
virtual ossimIrect getBoundingRect(ossim_uint32 resLevel=0) const
This will return the bounding rect of the source.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual const ossim_float64 * getMaxPix() const
void getUpperRightRect(vector< ossimIrect > &rects)
Addes upper right watermark rectangle to rects if it intersects theTile rect clipped to input boundin...
virtual ossim_uint32 getNumberOfBands() const
64 bit floating point
virtual void setImageRectangle(const ossimIrect &rect)
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
16 bit unsigned integer
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
ossimString getModeString() const
virtual void disconnect(ossimConnectableObject *object=0)
Will disconnect the object passed in.
Represents serializable keyword/value map.
bool theEnableFlag
Definition: ossimSource.h:62
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
ossim_uint32 y
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
float ossim_float32
void getModeList(vector< ossimString > &list) const
virtual ~ossimWatermarkFilter()
destructor
virtual ossimString getLongName() const
bool openWatermarkFile()
Attempts to open "theFilename".
ossim_uint32 height() const
Definition: ossimIrect.h:487
void getUniformSparceRects(vector< ossimIrect > &rects)
Addes rectangles to rects if it intersects theTile rect clipped to input bounding rect...
static ossimString toString(bool aValue)
Numeric to string methods.
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Adds this objects properties to the list.
16 bit signed integer
ossimScalarType theInputScalarType
The input scalar type.
const ossimIpt & ul() const
Definition: ossimIrect.h:274
virtual ossimDataObjectStatus getDataObjectStatus() const
16 bit unsigned integer (14 bits used)
static const ossimErrorCode OSSIM_ERROR
signed char ossim_sint8
16 bit unsigned integer (13 bits used)
32 bit floating point
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
unsigned short ossim_uint16
32 bit unsigned integer
virtual void initialize()
Initialize the data buffer.
void getUpperCenterRect(vector< ossimIrect > &rects)
Addes upper center watermark rectangle to rects if it intersects theTile rect clipped to input boundi...
WatermarkMode theMode
The filter mode.
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual void loadTile(const void *src, const ossimIrect &src_rect, ossimInterleaveType il_type)
virtual std::ostream & print(std::ostream &out) const
Outputs theErrorStatus as an ossimErrorCode and an ossimString.
static ossimImageDataFactory * instance()
ossim_uint32 theInputNumberOfBands
The number of input bands.
virtual ossimString getShortName() const
virtual ossimDataObjectStatus validate() const
signed short ossim_sint16
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
32 bit signed integer
ossimRefPtr< ossimImageData > theWatermark
Tile storage for watermark image.
void getIntersectingRects(vector< ossimIrect > &rects)
Computes the bounding rectangles.
ossimImageSource * theInputConnection
unsigned int ossim_uint32
virtual const ossim_float64 * getNullPix() const
32 bit normalized floating point
double toDouble() const
signed int ossim_sint32
void setFilename(const ossimFilename &file)
Sets theFilename to file.
virtual ossimIrect getImageRectangle() const
void setWeight(ossim_float64 weight)
Sets the weight.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossim_uint32 theWatermarkNumberOfBands
The number of watermark bands.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossimIrect getImageRectangle(ossim_uint32 resLevel=0) const
Returns zero-based bounding rectangle of the image.
const ossim_float64 DEFAULT_WEIGHT
virtual ossimRefPtr< ossimImageData > create(ossimSource *owner, ossimScalarType scalar, ossim_uint32 bands=1) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
void getLowerLeftRect(vector< ossimIrect > &rects)
Addes lower left watermark rectangle to rects if it intersects theTile rect clipped to input bounding...
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
ossimRefPtr< ossimImageData > theTile
The returned tile.
void setMode(const ossimString &mode)
Sets the filter mode.
void fill(T dummy)
Writes watermark(s) to theTile.
void getUniformDenseRects(vector< ossimIrect > &rects)
Addes rectangles to rects if it intersects theTile rect clipped to input bounding rect...
virtual void initialize()
virtual void setOrigin(const ossimIpt &origin)
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
virtual const ossim_float64 * getMinPix() const
virtual ossimScalarType getScalarType() const
virtual void makeBlank()
Initializes data to null pixel values.
64 bit normalized floating point
16 bit unsigned integer (11 bits used)
ossimIrect theInputBoundingRect
The bounding rectangle of the input connection.
class ossimWatermarkFilter Applies an image or watermark to image.
virtual void initialize()
initialize Does nothing in this class.
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual ossimErrorCode getErrorStatus() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossimWatermarkFilter::WatermarkMode getMode() const
ossim_int32 y
Definition: ossimIpt.h:142
void setIoType(ossimFilenamePropertyIoType ioType)
virtual const void * getBuf() const
ossimFilename theFilename
File name of watermark image.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
virtual ossimString getDescription() const
virtual void initialize()
Initializes state of the object from the input connection.
static ossimImageHandlerRegistry * instance()
ossim_int32 x
Definition: ossimIpt.h:141
8 bit unsigned integer
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
void getCenterRect(vector< ossimIrect > &rects)
Addes center watermark rectangle to rects if it intersects theTile rect clipped to input bounding rec...
void getLowerCenterRect(vector< ossimIrect > &rects)
Addes lower center watermark rectangle to rects if it intersects theTile rect clipped to input boundi...
void getLowerRightRect(vector< ossimIrect > &rects)
Addes lower right watermark rectangle to rects if it intersects theTile rect clipped to input boundin...
static const char * FILENAME_KW
ossim_float64 theWatermarkWeight
Normalized between 0.0 and 1.0.
void getUpperLeftRect(vector< ossimIrect > &rects)
Addes upper left watermark rectangle to rects if it intersects theTile rect clipped to input bounding...
unsigned char ossim_uint8
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
bool allocate()
Allocates / recomputes things that are needed.
std::basic_ostream< char > ostream
Base class for char output streams.
Definition: ossimIosFwd.h:23
void setCacheRefreshBit()
int ossim_int32
bool theDirtyFlag
Set in the initialize method this instructs the getTile that something has changes and it need to cal...
virtual ossimRefPtr< ossimImageData > getTile(const ossimIrect &tile_rect, ossim_uint32 resLevel=0)
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)
16 bit unsigned integer (12 bits used)