bool ImageInfo::PasteImageInfo( const wxPoint& point, ImageInfoPtr src ) { bool res = false; size_t size = mPalette->GetCorrectImageSize(10, 10, true); int bytesOnPixel = size / (10 * 10); switch (bytesOnPixel) { case 1: res = mIndexMask->InsertMask<char>( point, src->GetImage() ); break; case 2: res = mIndexMask->InsertMask<short>( point, src->GetImage() ); break; case 3: res = mIndexMask->InsertMask<Pixel>( point, src->GetImage() ); break; case 4: res = mIndexMask->InsertMask<PixelA>( point, src->GetImage() ); break; default: wxLogError( wxString::Format("ImageInfo::PasteImageInfo: Bytes on pixel = %d", bytesOnPixel)); } return res; }
ImageInfoPtr ImageInfo::CopyToImageInfo( const wxRect& rect ) { ImageInfoPtr result; wxRect checkRect = rect; checkRect.Intersect( wxRect(0, 0, mIndexMask->GetWidth(), mIndexMask->GetHeight()) ); if ( !(checkRect.GetWidth() >= 0 && checkRect.GetHeight() >= 0) ) { return result; } int w = checkRect.GetWidth(); int h = checkRect.GetHeight(); size_t size = mPalette->GetCorrectImageSize(w, h, true); wxByte* buf = (wxByte*) malloc( size ); int bytesOnPixel = size / (w * h); switch (bytesOnPixel) { case 1: Helpers::CropSubBuffer( buf, w, h, mIndexMask->GetMask(), mIndexMask->GetWidth(), rect.x, rect.y); break; case 2: Helpers::CropSubBuffer<short>((short*) buf, w, h, (const short*) mIndexMask->GetMask(), mIndexMask->GetWidth(), rect.x, rect.y); break; case 3: Helpers::CropSubBuffer<Pixel>((Pixel*)(buf), w, h, (const Pixel*) mIndexMask->GetMask(), mIndexMask->GetWidth(), rect.x, rect.y); break; case 4: Helpers::CropSubBuffer<PixelA>((PixelA*) buf, w, h, (const PixelA*) mIndexMask->GetMask(), mIndexMask->GetWidth(), rect.x, rect.y); break; default: wxLogError( wxString::Format("ImageInfo::CopyToImageInfo: Bytes on pixel = %d", bytesOnPixel)); } IndexMaskPtr mask = std::make_shared<IndexMask>(); mask->SetMask( buf, size, w, h ); free(buf); result = std::make_shared<ImageInfo>(mask, mPalette); if (!result->IsOk()) { result = nullptr; } return result; }
bool DB::ValueCategoryMatcher::eval(ImageInfoPtr info, QMap<QString, StringSet>& alreadyMatched) { // Only add the tag _option to the alreadyMatched tags, // and omit the tags in _members if ( m_shouldPrepareMatchedSet ) alreadyMatched[m_category].insert(m_option); if ( info->hasCategoryInfo( m_category, m_option ) ) { return true; } if ( info->hasCategoryInfo( m_category, m_members ) ) return true; return false; }
bool ImageInfo::CopyToClipBoard( const wxRect& rect ) { ImageInfoPtr newBuffered = CopyToImageInfo( rect ); bool res = newBuffered->IsOk(); if (res) { sBuffered = newBuffered; wxBitmap* bmp = sBuffered->GetBitmap(); Helpers::CopyToClipboard(bmp->ConvertToImage()); delete bmp; } return res; }
bool EditPanel::CommandPaste(ImageInfoPtr newValue ) { if ( mImageInfo == NULL ) { return false; } wxRect zone( mCursor, newValue->GetSize() ); ImageInfoPtr old = mImageInfo->CopyToImageInfo( zone ); if (old) { ImagePasteCommand* paste = new ImagePasteCommand(this, old->Clone(), newValue->Clone(), mCursor ); return COMMAND->Submit( paste ); } return false; }
DB::FileName ImageDB::findFirstItemInRange(const DB::FileNameList& images, const ImageDate& range, bool includeRanges) const { DB::FileName candidate; QDateTime candidateDateStart; for (const DB::FileName& fileName : images) { ImageInfoPtr iInfo = info(fileName); ImageDate::MatchType match = iInfo->date().isIncludedIn(range); if (match == DB::ImageDate::ExactMatch || (includeRanges && match == DB::ImageDate::RangeMatch)) { if (candidate.isNull() || iInfo->date().start() < candidateDateStart) { candidate = fileName; // Looking at this, can't this just be iInfo->date().start()? // Just in the middle of refactoring other stuff, so leaving // this alone now. TODO(hzeller): revisit. candidateDateStart = info(candidate)->date().start(); } } } return candidate; }
bool DB::NoTagCategoryMatcher::eval(ImageInfoPtr info, QMap<QString, StringSet>& alreadyMatched) { Q_UNUSED( alreadyMatched ); return info->itemsOfCategory(m_category).isEmpty(); }
bool ImageSearchInfo::match( ImageInfoPtr info ) const { if ( m_isNull ) return true; if ( !m_compiled ) compile(); bool ok = true; #ifdef HAVE_EXIV2 ok = m_exifSearchInfo.matches( info->fileName() ); #endif QDateTime actualStart = info->date().start(); QDateTime actualEnd = info->date().end(); if ( actualEnd <= actualStart ) { QDateTime tmp = actualStart; actualStart = actualEnd; actualEnd = tmp; } if ( !m_date.start().isNull() ) { // Date // the search date matches the actual date if: // actual.start <= search.start <= actuel.end or // actual.start <= search.end <=actuel.end or // search.start <= actual.start and actual.end <= search.end bool b1 =( actualStart <= m_date.start() && m_date.start() <= actualEnd ); bool b2 =( actualStart <= m_date.end() && m_date.end() <= actualEnd ); bool b3 = ( m_date.start() <= actualStart && ( actualEnd <= m_date.end() || m_date.end().isNull() ) ); ok = ok && ( ( b1 || b2 || b3 ) ); } else if ( !m_date.end().isNull() ) { bool b1 = ( actualStart <= m_date.end() && m_date.end() <= actualEnd ); bool b2 = ( actualEnd <= m_date.end() ); ok = ok && ( ( b1 || b2 ) ); } // -------------------------------------------------- Options // alreadyMatched map is used to make it possible to search for // Jesper & None QMap<QString, StringSet> alreadyMatched; for (CategoryMatcher* optionMatcher : m_categoryMatchers) { ok = ok && optionMatcher->eval(info, alreadyMatched); } // -------------------------------------------------- Label ok = ok && ( m_label.isEmpty() || info->label().indexOf(m_label) != -1 ); // -------------------------------------------------- RAW ok = ok && ( m_searchRAW == false || ImageManager::RAWImageDecoder::isRAW( info->fileName()) ); // -------------------------------------------------- Rating //ok = ok && (_rating == -1 ) || ( _rating == info->rating() ); if (m_rating != -1) { switch( m_ratingSearchMode ) { case 1: // Image rating at least selected ok = ok && ( m_rating <= info->rating() ); break; case 2: // Image rating less than selected ok = ok && ( m_rating >= info->rating() ); break; case 3: // Image rating not equal ok = ok && ( m_rating != info->rating() ); break; default: ok = ok && ((m_rating == -1 ) || ( m_rating == info->rating() )); break; } } // -------------------------------------------------- Resolution if ( m_megapixel ) ok = ok && ( m_megapixel * 1000000 <= info->size().width() * info->size().height() ); // -------------------------------------------------- Text QString txt = info->description(); if ( !m_description.isEmpty() ) { QStringList list = m_description.split(QChar::fromLatin1(' '), QString::SkipEmptyParts); Q_FOREACH( const QString &word, list ) { ok = ok && ( txt.indexOf( word, 0, Qt::CaseInsensitive ) != -1 ); } }
ImageInfoDataObject::ImageInfoDataObject( ImageInfoPtr info ): wxBitmapDataObject( *info->GetBitmap() ), mImageInfo( info->Clone() ) { }