Author: post
Date: 2013-09-20 22:06:01 +0200 (Fri, 20 Sep 2013)
New Revision: 582

Modified:
   RawSpeed/Camera.cpp
   RawSpeed/CameraSensorInfo.cpp
   RawSpeed/CameraSensorInfo.h
   RawSpeed/ColorFilterArray.cpp
   RawSpeed/ColorFilterArray.h
   RawSpeed/RawDecoder.cpp
   RawSpeed/RawDecoder.h
Log:
Add:
* Separate black values for CFA components.
* Task based thread helper for decoders.
* Start different size CFA code.
* Various decoder controls (Apply crop?  Output uncorrected values?)

Modified: RawSpeed/Camera.cpp
===================================================================
--- RawSpeed/Camera.cpp 2013-09-20 19:44:14 UTC (rev 581)
+++ RawSpeed/Camera.cpp 2013-09-20 20:06:01 UTC (rev 582)
@@ -322,19 +322,24 @@
     max_iso = StringToInt(key, cur->name, "iso_max");
     xmlFree(key);
   }
+  key = xmlGetProp(cur, (const xmlChar *)"black_colors");
+  vector<int> black_colors;
+  if (key) {
+    black_colors = MultipleStringToInt(key, cur->name, "black_colors");
+    xmlFree(key);
+  }
   key = xmlGetProp(cur, (const xmlChar *)"iso_list");
   if (key) {
     vector<int> values = MultipleStringToInt(key, cur->name, "iso_list");
     xmlFree(key);
     if (!values.empty()) {
       for (uint32 i = 0; i < values.size(); i++) {
-        sensorInfo.push_back(CameraSensorInfo(black, white, values[i], 
values[i]));
+        sensorInfo.push_back(CameraSensorInfo(black, white, values[i], 
values[i], black_colors));
       }      
     }
   } else {
-    sensorInfo.push_back(CameraSensorInfo(black, white, min_iso, max_iso));
+    sensorInfo.push_back(CameraSensorInfo(black, white, min_iso, max_iso, 
black_colors));
   }
-
 }
 
 const CameraSensorInfo* Camera::getSensorInfo( int iso )

Modified: RawSpeed/CameraSensorInfo.cpp
===================================================================
--- RawSpeed/CameraSensorInfo.cpp       2013-09-20 19:44:14 UTC (rev 581)
+++ RawSpeed/CameraSensorInfo.cpp       2013-09-20 20:06:01 UTC (rev 582)
@@ -24,11 +24,12 @@
 
 namespace RawSpeed {
 
-CameraSensorInfo::CameraSensorInfo(int black_level, int white_level, int 
min_iso, int max_iso) :
+CameraSensorInfo::CameraSensorInfo(int black_level, int white_level, int 
min_iso, int max_iso, vector<int> black_separate) :
 mBlackLevel(black_level),
 mWhiteLevel(white_level),
 mMinIso(min_iso), 
-mMaxIso(max_iso)
+mMaxIso(max_iso),
+mBlackLevelSeparate(black_separate)
 {
 }
 

Modified: RawSpeed/CameraSensorInfo.h
===================================================================
--- RawSpeed/CameraSensorInfo.h 2013-09-20 19:44:14 UTC (rev 581)
+++ RawSpeed/CameraSensorInfo.h 2013-09-20 20:06:01 UTC (rev 582)
@@ -29,7 +29,7 @@
 class CameraSensorInfo
 {
 public:
-  CameraSensorInfo(int black_level, int white_level, int min_iso, int max_iso);
+  CameraSensorInfo(int black_level, int white_level, int min_iso, int max_iso, 
vector<int> black_separate);
   virtual ~CameraSensorInfo(void);
   bool isIsoWithin(int iso);
   bool isDefault();
@@ -37,6 +37,7 @@
   int mWhiteLevel;
   int mMinIso; 
   int mMaxIso;
+  vector<int> mBlackLevelSeparate;
 };
 
 } // namespace RawSpeed

Modified: RawSpeed/ColorFilterArray.cpp
===================================================================
--- RawSpeed/ColorFilterArray.cpp       2013-09-20 19:44:14 UTC (rev 581)
+++ RawSpeed/ColorFilterArray.cpp       2013-09-20 20:06:01 UTC (rev 582)
@@ -24,11 +24,15 @@
 
 namespace RawSpeed {
 
-ColorFilterArray::ColorFilterArray(void) {
+ColorFilterArray::ColorFilterArray(void) :
+size(2,2) 
+{
   setCFA(CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN, CFA_UNKNOWN);
 }
 
-ColorFilterArray::ColorFilterArray(CFAColor up_left, CFAColor up_right, 
CFAColor down_left, CFAColor down_right) {
+ColorFilterArray::ColorFilterArray(CFAColor up_left, CFAColor up_right, 
CFAColor down_left, CFAColor down_right)  :
+size(2,2) 
+{
   cfa[0] = up_left;
   cfa[1] = up_right;
   cfa[2] = down_left;

Modified: RawSpeed/ColorFilterArray.h
===================================================================
--- RawSpeed/ColorFilterArray.h 2013-09-20 19:44:14 UTC (rev 581)
+++ RawSpeed/ColorFilterArray.h 2013-09-20 20:06:01 UTC (rev 582)
@@ -61,6 +61,7 @@
   uint32 getDcrawFilter();
   void shiftLeft();
   void shiftDown();
+  iPoint2D size;
   std::string asString();
   static std::string colorToString(CFAColor c);
 private:

Modified: RawSpeed/RawDecoder.cpp
===================================================================
--- RawSpeed/RawDecoder.cpp     2013-09-20 19:44:14 UTC (rev 581)
+++ RawSpeed/RawDecoder.cpp     2013-09-20 20:06:01 UTC (rev 582)
@@ -29,9 +29,15 @@
   failOnUnknown = FALSE;
   interpolateBadPixels = TRUE;
   applyStage1DngOpcodes = TRUE;
+  applyCrop = TRUE;
+  uncorrectedRawValues = FALSE;
 }
 
 RawDecoder::~RawDecoder(void) {
+  for (vector<void*>::iterator i = ownedObjects.begin(); i != 
ownedObjects.end(); ++i) {
+    delete(*i);
+  }
+  ownedObjects.clear();
 }
 
 void RawDecoder::decodeUncompressed(TiffIFD *rawIFD, BitOrder order) {
@@ -234,36 +240,52 @@
     return;
   }
 
-  iPoint2D new_size = cam->cropSize;
+  mRaw->cfa = cam->cfa;
+  if (applyCrop) {
+    iPoint2D new_size = cam->cropSize;
 
-  // If crop size is negative, use relative cropping
-  if (new_size.x <= 0)
-    new_size.x = mRaw->dim.x - cam->cropPos.x + new_size.x;
+    // If crop size is negative, use relative cropping
+    if (new_size.x <= 0)
+      new_size.x = mRaw->dim.x - cam->cropPos.x + new_size.x;
 
-  if (new_size.y <= 0)
-    new_size.y = mRaw->dim.y - cam->cropPos.y + new_size.y;
+    if (new_size.y <= 0)
+      new_size.y = mRaw->dim.y - cam->cropPos.y + new_size.y;
 
-  iRectangle2D(cam->cropPos, new_size);
-  mRaw->subFrame(iRectangle2D(cam->cropPos, new_size));
-  mRaw->cfa = cam->cfa;
+    mRaw->subFrame(iRectangle2D(cam->cropPos, new_size));
 
-  // Shift CFA to match crop
-  if (cam->cropPos.x & 1)
-    mRaw->cfa.shiftLeft();
-  if (cam->cropPos.y & 1)
-    mRaw->cfa.shiftDown();
+    // Shift CFA to match crop
+    if (cam->cropPos.x & 1)
+      mRaw->cfa.shiftLeft();
+    if (cam->cropPos.y & 1)
+      mRaw->cfa.shiftDown();
+  }
 
+
   const CameraSensorInfo *sensor = cam->getSensorInfo(iso_speed);
   mRaw->blackLevel = sensor->mBlackLevel;
   mRaw->whitePoint = sensor->mWhiteLevel;
   mRaw->blackAreas = cam->blackAreas;
+  if (mRaw->blackAreas.empty() && !sensor->mBlackLevelSeparate.empty()) {
+    if (mRaw->isCFA && mRaw->cfa.size.area() <= 
sensor->mBlackLevelSeparate.size()) {
+      for (uint32 i = 0; i < mRaw->cfa.size.area(); i++) {
+        mRaw->blackLevelSeparate[i] = sensor->mBlackLevelSeparate[i];
+      }
+    } else if (!mRaw->isCFA && mRaw->getCpp() <= 
sensor->mBlackLevelSeparate.size()) {
+      for (uint32 i = 0; i < mRaw->getCpp(); i++) {
+        mRaw->blackLevelSeparate[i] = sensor->mBlackLevelSeparate[i];
+      }
+    }
+  }
 }
 
 
 void *RawDecoderDecodeThread(void *_this) {
   RawDecoderThread* me = (RawDecoderThread*)_this;
   try {
+    if (me->taskNo >= 0)
       me->parent->decodeThreaded(me);
+    else
+      me->parent->decodeThreaded(me);
   } catch (RawDecoderException &ex) {
     me->parent->mRaw->setError(ex.what());
   } catch (IOException &ex) {
@@ -352,4 +374,36 @@
   }
 }
 
+void RawDecoder::startTasks( uint32 tasks )
+{
+  uint32 threads;
+  threads = min(tasks, getThreadCount()); 
+  int ctask = 0;
+  RawDecoderThread *t = new RawDecoderThread[threads];
+
+  pthread_attr_t attr;
+
+  /* Initialize and set thread detached attribute */
+  pthread_attr_init(&attr);
+  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+  /* TODO: Create a way to re-use threads */
+  void *status;
+  while ((uint32)ctask < tasks) {
+    for (uint32 i = 0; i < threads && (uint32)ctask < tasks; i++) {
+      t[i].taskNo = ctask++;
+      t[i].parent = this;
+      pthread_create(&t[i].threadid, &attr, RawDecoderDecodeThread, &t[i]);
+    }
+    for (uint32 i = 0; i < threads; i++) {
+      pthread_join(t[i].threadid, &status);
+    }
+  } 
+
+  if (mRaw->errors.size() >= tasks)
+    ThrowRDE("RawDecoder::startThreads: All threads reported errors. Cannot 
load image.");
+
+  delete[] t;
+}
+
 } // namespace RawSpeed

Modified: RawSpeed/RawDecoder.h
===================================================================
--- RawSpeed/RawDecoder.h       2013-09-20 19:44:14 UTC (rev 581)
+++ RawSpeed/RawDecoder.h       2013-09-20 20:06:01 UTC (rev 582)
@@ -41,12 +41,13 @@
 class RawDecoderThread
 {
   public:
-    RawDecoderThread() {error = 0;};
+    RawDecoderThread() {error = 0; taskNo = -1;};
     uint32 start_y;
     uint32 end_y;
     const char* error;
     pthread_t threadid;
     RawDecoder* parent;
+    uint32 taskNo;
 };
 
 class RawDecoder 
@@ -105,6 +106,22 @@
   /* This usually maps out bad pixels, etc */
   bool applyStage1DngOpcodes;
 
+  /* Apply crop - if false uncropped image is delivered */
+  bool applyCrop;
+
+  /* This will skip all corrections, and deliver the raw data */
+  /* This will skip any compression curves or other things that */
+  /* is needed to get the correct values */
+  /* Only enable if you are sure that is what you want */
+  bool uncorrectedRawValues;
+
+  /* Vector of objects that will be destroyed alongside the decoder */
+  vector<void*> ownedObjects;
+
+  /* Retrieve the main RAW chunk */
+  /* Returns NULL if unknown */
+  virtual FileMap* getCompressedData() {return NULL;}
+
 protected:
   /* Attempt to decode the image */
   /* A RawDecoderException will be thrown if the image cannot be decoded, */
@@ -120,6 +137,12 @@
   /* If all threads report an error an exception will be thrown*/
   void startThreads();
 
+  /* Helper function for decoders -  */
+  /* The function returns when all tasks are done */
+  /* All errors are silently pushed into the "errors" array.*/
+  /* If all threads report an error an exception will be thrown*/
+  void startTasks(uint32 tasks);
+
   /* Check the camera and mode against the camera database. */
   /* A RawDecoderException will be thrown if the camera isn't supported */
   /* Unknown cameras does NOT generate any errors, but returns false */


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to