Mat imdecode( InputArray _buf, int flags ) { CV_TRACE_FUNCTION(); Mat buf = _buf.getMat(), img; imdecode_( buf, flags, LOAD_MAT, &img ); /// optionally rotate the data if EXIF' orientation flag says so if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) { ApplyExifOrientation(buf, img); } return img; }
void GeneralImage::ApplyTransforms() { if (m_BitmapProcessed && m_BitmapProcessed->GetKey() == m_Options) return; if (m_BitmapProcessed) { delete m_BitmapProcessed; m_BitmapProcessed = nullptr; } ImageCacheHandle* handle = GetImageCache().Get(m_Options); if (!handle) { auto& canvas = m_Skin->GetCanvas(); auto stream = m_Bitmap->GetBitmap()->CreateEffectStream(); ApplyCrop(stream); if (m_Options.m_Rotate != 0.0f) stream->Rotate(canvas, m_Options.m_Rotate); stream->Flip(canvas, m_Options.m_Flip); if (m_Options.m_UseExifOrientation) stream->ApplyExifOrientation(canvas); if (m_Options.m_GreyScale) stream->Tint(canvas, c_GreyScaleMatrix); if (!CompareColorMatrix(m_Options.m_ColorMatrix, c_IdentityMatrix)) stream->Tint(canvas, m_Options.m_ColorMatrix); auto bitmap = stream->ToBitmap(canvas); delete stream; stream = nullptr; if (bitmap != nullptr) { GetImageCache().Put(m_Options, bitmap); handle = GetImageCache().Get(m_Options); if (!handle) return; } } if (handle) { m_BitmapProcessed = handle; } }
/** * Read an image * * This function merely calls the actual implementation above and returns itself. * * @param[in] filename File to load * @param[in] flags Flags you wish to set. */ Mat imread( const String& filename, int flags ) { CV_TRACE_FUNCTION(); /// create the basic container Mat img; /// load the data imread_( filename, flags, LOAD_MAT, &img ); /// optionally rotate the data if EXIF' orientation flag says so if( !img.empty() && (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) { ApplyExifOrientation(filename, img); } /// return a reference to the data return img; }
/** * Read an image into memory and return the information * * @param[in] filename File to load * @param[in] flags Flags * @param[in] mats Reference to C++ vector<Mat> object to hold the images * */ static bool imreadmulti_(const String& filename, int flags, std::vector<Mat>& mats) { /// Search for the relevant decoder to handle the imagery ImageDecoder decoder; #ifdef HAVE_GDAL if (flags != IMREAD_UNCHANGED && (flags & IMREAD_LOAD_GDAL) == IMREAD_LOAD_GDAL){ decoder = GdalDecoder().newDecoder(); } else{ #endif decoder = findDecoder(filename); #ifdef HAVE_GDAL } #endif /// if no decoder was found, return nothing. if (!decoder){ return 0; } /// set the filename in the driver decoder->setSource(filename); // read the header to make sure it succeeds if (!decoder->readHeader()) return 0; for (;;) { // grab the decoded type int type = decoder->type(); if( (flags & IMREAD_LOAD_GDAL) != IMREAD_LOAD_GDAL && flags != IMREAD_UNCHANGED ) { if ((flags & CV_LOAD_IMAGE_ANYDEPTH) == 0) type = CV_MAKETYPE(CV_8U, CV_MAT_CN(type)); if ((flags & CV_LOAD_IMAGE_COLOR) != 0 || ((flags & CV_LOAD_IMAGE_ANYCOLOR) != 0 && CV_MAT_CN(type) > 1)) type = CV_MAKETYPE(CV_MAT_DEPTH(type), 3); else type = CV_MAKETYPE(CV_MAT_DEPTH(type), 1); } // read the image data Mat mat(decoder->height(), decoder->width(), type); if (!decoder->readData(mat)) { // optionally rotate the data if EXIF' orientation flag says so if( (flags & IMREAD_IGNORE_ORIENTATION) == 0 && flags != IMREAD_UNCHANGED ) { ApplyExifOrientation(filename, mat); } break; } mats.push_back(mat); if (!decoder->nextPage()) { break; } } return !mats.empty(); }