"Fossies" - the Fresh Open Source Software Archive

Member "rawtherapee-5.7/rtgui/editbuffer.cc" (10 Sep 2019, 3618 Bytes) of package /linux/misc/rawtherapee-5.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "editbuffer.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.6_vs_5.7.

    1 /*
    2  *  This file is part of RawTherapee.
    3  *
    4  *  Copyright (c) 2019 Jean-Christophe FRISCH <natureh.510@gmail.com>
    5  *
    6  *  RawTherapee is free software: you can redistribute it and/or modify
    7  *  it under the terms of the GNU General Public License as published by
    8  *  the Free Software Foundation, either version 3 of the License, or
    9  *  (at your option) any later version.
   10  *
   11  *  RawTherapee is distributed in the hope that it will be useful,
   12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  *  GNU General Public License for more details.
   15  *
   16  *  You should have received a copy of the GNU General Public License
   17  *  along with RawTherapee.  If not, see <https://www.gnu.org/licenses/>.
   18  */
   19 
   20 #include "editbuffer.h"
   21 #include "editcallbacks.h"
   22 
   23 ObjectMOBuffer::ObjectMOBuffer(EditDataProvider *dataProvider) : objectMap(nullptr), objectMode(OM_255), dataProvider(dataProvider) {}
   24 
   25 ObjectMOBuffer::~ObjectMOBuffer()
   26 {
   27     flush();
   28 }
   29 
   30 
   31 /* Upgrade or downgrade the objectModeType */
   32 void ObjectMOBuffer::setObjectMode(ObjectMode newType)
   33 {
   34     if (!objectMap) {
   35         objectMode = newType;
   36         return;
   37     }
   38 
   39     int w = objectMap->get_width ();
   40     int h = objectMap->get_height ();
   41     if (w && h) {
   42         switch (newType) {
   43         case (OM_255):
   44             if (objectMode==OM_65535) {
   45                 objectMap->unreference();
   46                 objectMap = Cairo::ImageSurface::create(Cairo::FORMAT_A8, w, h);
   47             }
   48             break;
   49 
   50         case (OM_65535):
   51             if (objectMode==OM_255) {
   52                 objectMap->unreference();
   53                 objectMap = Cairo::ImageSurface::create(Cairo::FORMAT_RGB16_565, w, h);
   54             }
   55             break;
   56         }
   57     }
   58     objectMode = newType;
   59 }
   60 
   61 void ObjectMOBuffer::flush()
   62 {
   63     if (objectMap ) {
   64         objectMap.clear();
   65     }
   66 }
   67 
   68 EditSubscriber *ObjectMOBuffer::getEditSubscriber () {
   69     if (dataProvider) {
   70         return dataProvider->getCurrSubscriber();
   71     } else {
   72         return nullptr;
   73     }
   74 }
   75 
   76 
   77 // Resize buffers if they already exist
   78 void ObjectMOBuffer::resize(int newWidth, int newHeight)
   79 {
   80     if (!dataProvider) {
   81         return;
   82     }
   83 
   84     if (const auto currSubscriber = dataProvider->getCurrSubscriber ()) {
   85         if (currSubscriber->getEditingType() == ET_OBJECTS) {
   86             if (objectMap && (objectMap->get_width() != newWidth || objectMap->get_height() != newHeight)) {
   87                 objectMap.clear();
   88             }
   89 
   90             if (!objectMap && newWidth>0 && newHeight>0) {
   91                 objectMap = Cairo::ImageSurface::create(objectMode==OM_255?Cairo::FORMAT_A8:Cairo::FORMAT_RGB16_565, newWidth, newHeight);
   92             }
   93 
   94         } else {
   95             flush();
   96         }
   97     } else {
   98         flush();
   99     }
  100 }
  101 
  102 int ObjectMOBuffer::getObjectID(const rtengine::Coord& location)
  103 {
  104     int id = 0;
  105 
  106     if (!objectMap || location.x < 0 || location.y < 0 || location.x >= objectMap->get_width() || location.y >= objectMap->get_height()) {
  107         return -1;
  108     }
  109 
  110     if (objectMode == OM_255) {
  111         id = (unsigned char)(*( objectMap->get_data() + location.y * objectMap->get_stride() + location.x ));
  112     } else {
  113         id = (unsigned short)(*( objectMap->get_data() + location.y * objectMap->get_stride() + location.x ));
  114     }
  115 
  116     return id - 1;
  117 }
  118 
  119 bool ObjectMOBuffer::bufferCreated()
  120 {
  121     EditSubscriber* subscriber;
  122 
  123     if (dataProvider && (subscriber = dataProvider->getCurrSubscriber())) {
  124         return subscriber->getEditingType() == ET_OBJECTS ? bool(objectMap) : false;
  125     }
  126 
  127     return false;
  128 }
  129