Ejemplo n.º 1
0
int Scrollbar::thumbPosition()
{
    if (!totalSize())
        return 0;

    int trackLen = trackLength();
    float proportion = static_cast<float>(currentPos()) / totalSize();
    return round(proportion * trackLen);
}
Ejemplo n.º 2
0
int Scrollbar::thumbLength()
{
    int trackLen = trackLength();

    if (!totalSize())
        return trackLen;

    float proportion = static_cast<float>(visibleSize()) / totalSize();
    int length = round(proportion * trackLen);
    length = std::min(std::max(length, minimumThumbLength()), trackLen);
    return length;
}
Ejemplo n.º 3
0
void RemoteProtocol::listRoot()
{
	KIO::UDSEntry entry;

	KIO::UDSEntryList remote_entries;
        m_impl.listRoot(remote_entries);

	totalSize(remote_entries.count()+2);

	m_impl.createTopLevelEntry(entry);
	listEntry(entry, false);

	m_impl.createWizardEntry(entry);
	listEntry(entry, false);

	KIO::UDSEntryList::ConstIterator it = remote_entries.constBegin();
	const KIO::UDSEntryList::ConstIterator end = remote_entries.constEnd();
	for(; it!=end; ++it)
	{
		listEntry(*it, false);
	}

	entry.clear();
	listEntry(entry, true);

	finished();
}
Ejemplo n.º 4
0
void BufferedTransport::setReadPos(size_t pos) {
	ScopedMutexLock(lock_);
	if(pos >= totalSize())
		throw ProtocolException("readpos less than 0 by rewind");

	readPos_ = pos;
}
Ejemplo n.º 5
0
void AbstractLut::reset( size_t dimSize, double* data /* = NULL */ )
{
	if( _data && !_shared )
		delete [] _data;
	_dimSize = dimSize;
	if( _data == NULL )
	{
		_data = new double[ totalSize() * 3 ];
		memset( _data, 0, sizeof( double ) * totalSize() * 3 );
	}
	_data   = data;
	_shared = false;
	if( _interpolator )
		delete _interpolator;
	_interpolator = new TrilinInterpolator();
}
Ejemplo n.º 6
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB__DMSSU_DUMPINFO2, "_dmsStorageUnit::dumpInfo" )
   void _dmsStorageUnit::dumpInfo ( set<_monStorageUnit> &storageUnitList,
                                    BOOLEAN sys )
   {
      monStorageUnit su ;
      const dmsStorageUnitHeader *dataHeader = _pDataSu->getHeader() ;

      PD_TRACE_ENTRY ( SDB__DMSSU_DUMPINFO2 ) ;
      if ( !sys && dmsIsSysCSName( CSName() ) )
      {
         goto done ;
      }

      ossMemset ( su._name, 0, sizeof ( su._name ) ) ;
      ossStrncpy ( su._name, CSName(), DMS_SU_NAME_SZ ) ;
      su._pageSize = getPageSize() ;
      su._lobPageSize = getLobPageSize() ;
      su._sequence = CSSequence() ;
      su._numCollections = dataHeader->_numMB ;
      su._collectionHWM = dataHeader->_MBHWM ;
      su._size = totalSize() ;
      su._CSID = CSID() ;
      su._logicalCSID = LogicalCSID() ;

      storageUnitList.insert ( su ) ;
   done :
      PD_TRACE_EXIT ( SDB__DMSSU_DUMPINFO2 ) ;
   }
Ejemplo n.º 7
0
void MainWindow::scaleImage(double factor)
{
    ui->scrollArea->setWidgetResizable(false);

    double scrollfactor = (scaleFactor + factor) / scaleFactor;
    scaleFactor += factor;

    for (int i = 0; i < camNumber; ++i)
    {
        frameProcessor[i].setOutScaleFactor(scaleFactor);

        switch(i)
        {
        case 0:
            ui->imageLabel1->resize(currentSize);
            break;
        case 1:
            ui->imageLabel2->resize(currentSize);
            break;
        default:
            throw std::logic_error("There is no camera with index" + std::to_string(i));
        }
    }

    QSize totalSize(currentSize.width() * 2, currentSize.height());
    ui->scrollArea->widget()->resize(totalSize);

    adjustScrollBar(ui->scrollArea->horizontalScrollBar(), scrollfactor);
    adjustScrollBar(ui->scrollArea->verticalScrollBar(), scrollfactor);
    updateStatusBar();
}
// -----------------------------------------------------------------------------
// CHttpDownloadManagerServerEngine::AllDownloadsSizeInDriveL
// ?implementation_description
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
TInt CHttpDownloadManagerServerEngine::AllDownloadsSizeInDriveL(const CHttpDownload *aDownload, TInt aDriveId) const
    {
    LOGGER_ENTERFN( "AllDownloadsSizeInDriveL" );

    TInt allDownloadsSize( 0 );
    TInt numClientApps = iClientApps->Count();
    for( TInt apps = 0; apps < numClientApps; ++apps )
        {
        CArrayPtrFlat<CHttpDownload>* dlArray = (*iClientApps)[apps]->Downloads();
        TInt numDownloads = dlArray->Count();
        for( TInt dl = 0; dl < numDownloads; ++dl )
            {
            if( ( aDownload != (*dlArray)[dl]) && (*dlArray)[dl]->State() != EHttpDlMultipleMOCompleted 
                  && aDriveId == (*dlArray)[dl]->GetDestinationDriveID())
                {
                TInt32 totalSize(0);
                TInt32 downloadedSize(0);
                
                (*dlArray)[dl]->GetIntAttributeL(EDlAttrMultipleMOLength, totalSize);
                (*dlArray)[dl]->GetIntAttributeL(EDlAttrMultipleMODownloadedSize, downloadedSize);

                //Do not conside the downloads with unknown size
                if(KDefaultContentLength != totalSize)
                	allDownloadsSize += (totalSize - downloadedSize);
                }
            }
        }
    
    return allDownloadsSize;
    }
Ejemplo n.º 9
0
void MediaProtocol::listRoot()
{
    KIO::UDSEntry entry;

    KIO::UDSEntryList media_entries;
    bool ok = m_impl.listMedia(media_entries);

    if (!ok)
    {
        error( m_impl.lastErrorCode(), m_impl.lastErrorMessage() );
        return;
    }

    totalSize(media_entries.count()+1);

    m_impl.createTopLevelEntry(entry);
    listEntry(entry, false);

    KIO::UDSEntryListIterator it = media_entries.begin();
    KIO::UDSEntryListIterator end = media_entries.end();

    for(; it!=end; ++it)
    {
        listEntry(*it, false);
    }

    entry.clear();
    listEntry(entry, true);

    finished();
}
Ejemplo n.º 10
0
void AtlasTexture::commitFull(Image const &fullImage) const
{
    DENG2_ASSERT(fullImage.size() == totalSize());

    // While the Atlas is const, the texture isn't...
    const_cast<AtlasTexture *>(this)->setImage(fullImage);
}
Ejemplo n.º 11
0
/**
 * \brief Remove directories until total size > watermark
 */
void Scanner::removeDirs()
{
	Directory *dir, *parent;
	
	while (totalSize() > _watermark) {
		dir = getDirToRemove();
		
		if (!dir) {
			MSG_WARNING(msg_module, "cannot remove data (only active directories)");
			return;
		}
		
		MSG_DEBUG(msg_module, "remove %s", dir->getName().c_str());
		_cleaner->removeDir(dir->getName());
		
		/* Remove dir from its parent */
		parent = dir->getParent();
		parent->removeOldest();
		
		/* Update parent's age to the second oldest subdir and correct it's size */
		while (parent) {
			parent->updateAge();
			parent->setSize(parent->getSize() - dir->getSize());
			parent = parent->getParent();
		}
		
		delete dir;
		
		if (_multiple) {
			/* Multiple data witers - sort top dirs so next time we remove the oldest dir again */
			_rootdir->sortChildren();
		}
	}
}
Ejemplo n.º 12
0
Archivo: ls.c Proyecto: hristogg1/OS
//--------------------------------------------
// FUNCTION: printdir
// It prints the file list, given as an argument.
// The print format depends on flagl, if
// flagl is 0 prints only file names
// else if flagl is 1, it prints detailed information
// PARAMETERS:
// struct dirent **flist
// - The list of the files to be printed.
// int length
// - The length of the file list.
// char *dirpath
// - The path of the directory from which the file
//   list comes. This path is needed to get
//   file stats in -l mode.
//----------------------------------------------
void printdir(struct dirent **flist, int length, char *dirpath) {
	int i;
	struct stat fstat;

	if(!flagl) {
		if(flagmulti) {
			printf("%s:\n", dirpath);
		}
		
		for (i = 0; i < length; ++i) {
			printf("%s  ", flist[i]->d_name);
		}
		printf("\n");
	} else {
		if(flagmulti) {
			printf("%s:\n", dirpath);
		}

		// prints the total number of blocks, used in the directory
		printf("total %d\n", totalSize(dirpath));
		
		for(i = 0; i < length; ++i) {	
			char path[200];
			strcpy(path, dirpath);
			strcat(path, "/");
			strcat(path,flist[i] -> d_name);
		
			stat(path, &fstat);
			// prints file permissions
			printf((S_ISDIR(fstat.st_mode)) ? "d" : "-");
			printf((fstat.st_mode & S_IRUSR) ? "r" : "-");
			printf((fstat.st_mode & S_IWUSR) ? "w" : "-");
			printf((fstat.st_mode & S_IXUSR) ? "x" : "-");
			printf((fstat.st_mode & S_IRGRP) ? "r" : "-");
			printf((fstat.st_mode & S_IWGRP) ? "w" : "-");
			printf((fstat.st_mode & S_IXGRP) ? "x" : "-");
			printf((fstat.st_mode & S_IROTH) ? "r" : "-");
			printf((fstat.st_mode & S_IWOTH) ? "w" : "-");
			printf((fstat.st_mode & S_IXOTH) ? "x" : "-");
			
			// prints the number of links to this file
			printf(" %d", (int) fstat.st_nlink);
			// prints the owner name
			printf(" %s", getpwuid(fstat.st_uid)->pw_name);
			// prints the group name
			printf(" %s", getgrgid(fstat.st_gid)->gr_name);
			// prints the number of block used by this file
			printf(" %5d", (int) fstat.st_size);
			// prints the time of last modification
			char mtime[20];
			strftime(mtime, 20,"%b  %d %R", localtime(&fstat.st_mtime));	
			printf(" %s", mtime);
			// prints the file name
			printf(" %s", flist[i] -> d_name);

			printf("\n");
		}
	}
}
Ejemplo n.º 13
0
	SnapshotItem(const IFileContainer *container, const Location &fileName, const struct RARHeaderDataEx &info, SnapshotItem *parent) :
		::VFS::SnapshotItem(container, unpackedSize(info), parent)
	{
		m_data.path = QString::fromWCharArray(info.FileNameW);
		m_data.fileName = fileName;
		m_data.fileSize = totalSize();
		m_data.lastModified = fromDosTime(info.FileTime);
	}
Ejemplo n.º 14
0
void TrashProtocol::listDir(const KUrl& url)
{
    INIT_IMPL;
    kDebug() << "listdir: " << url;
    if ( url.path(KUrl::AddTrailingSlash) == QLatin1String("/") ) {
        listRoot();
        return;
    }
    int trashId;
    QString fileId;
    QString relativePath;
    bool ok = TrashImpl::parseURL( url, trashId, fileId, relativePath );
    if ( !ok ) {
        error( KIO::ERR_SLAVE_DEFINED, i18n( "Malformed URL %1", url.prettyUrl() ) );
        return;
    }
    //was: const QString physicalPath = impl.physicalPath( trashId, fileId, relativePath );

    // Get info for deleted directory - the date of deletion and orig path will be used
    // for all the items in it, and we need the physicalPath.
    TrashedFileInfo info;
    ok = impl.infoForFile( trashId, fileId, info );
    if ( !ok || info.physicalPath.isEmpty() ) {
        error( impl.lastErrorCode(), impl.lastErrorMessage() );
        return;
    }
    if ( !relativePath.isEmpty() ) {
        info.physicalPath += QLatin1Char('/');
        info.physicalPath += relativePath;
    }

    // List subdir. Can't use kio_file here since we provide our own info...
    kDebug() << "listing " << info.physicalPath;
    const QStringList entryNames = impl.listDir( info.physicalPath );
    totalSize( entryNames.count() );
    KIO::UDSEntry entry;
    for ( QStringList::const_iterator entryIt = entryNames.begin(), entryEnd = entryNames.end();
          entryIt != entryEnd ; ++entryIt )
    {
        const QString fileName = *entryIt;
        if (fileName == QLatin1String(".."))
            continue;
        const QString filePath = info.physicalPath + QLatin1Char('/') + fileName;
        // shouldn't be necessary
        //const QString url = TrashImpl::makeURL( trashId, fileId, relativePath + '/' + fileName );
        entry.clear();
        TrashedFileInfo infoForItem( info );
        infoForItem.origPath += QLatin1Char('/');
        infoForItem.origPath += fileName;

        if (createUDSEntry(filePath, fileName, fileName, entry, infoForItem)) {
            listEntry( entry, false );
        }
    }
    entry.clear();
    listEntry( entry, true );
    finished();
}
Ejemplo n.º 15
0
 AlignedArray getAsArray() const {
     AlignedArray ret(totalSize(), false);
     size_t off = 0;
     for (const AlignedArray& ary : v_) {
         ::memcpy(&ret[off], ary.data(), ary.size());
         off += ary.size();
     }
     return ret;
 }
Ejemplo n.º 16
0
void ApplicationsProtocol::listDir(const KUrl& url)
{
    QString groupPath = url.path( KUrl::AddTrailingSlash );
    groupPath.remove(0, 1); // remove starting '/'

    KServiceGroup::Ptr grp = KServiceGroup::group(groupPath);

    if (!grp || !grp->isValid()) {
        error(KIO::ERR_DOES_NOT_EXIST, groupPath);
        return;
    }

    unsigned int count = 0;
    KIO::UDSEntry entry;

    foreach (const KSycocaEntry::Ptr &e, grp->entries(true, true)) {
        if (e->isType(KST_KServiceGroup)) {
            KServiceGroup::Ptr g(KServiceGroup::Ptr::staticCast(e));
            QString groupCaption = g->caption();

            kDebug() << "ADDING SERVICE GROUP WITH PATH " << g->relPath();

            // Avoid adding empty groups.
            KServiceGroup::Ptr subMenuRoot = KServiceGroup::group(g->relPath());
            if (subMenuRoot->childCount() == 0)
                continue;

            // Ignore dotfiles.
            if ((g->name().at(0) == '.'))
                continue;

            QString relPath = g->relPath();
            KUrl dirUrl = url; // preserve protocol, whether that's programs:/ or applications:/
            dirUrl.setPath('/' + relPath);
            dirUrl.adjustPath(KUrl::RemoveTrailingSlash);
            kDebug() << "ApplicationsProtocol: adding entry" << dirUrl;
            createDirEntry(entry, groupCaption, dirUrl.url(), "inode/directory", g->icon());

        } else {
            KService::Ptr service(KService::Ptr::staticCast(e));

            kDebug() << "the entry name is" << service->desktopEntryName()
                     << "with path" << service->entryPath();

            if (!service->isApplication()) // how could this happen?
                continue;
            createFileEntry(entry, service, url);
        }

        listEntry(entry, false);
        count++;
    }

    totalSize(count);
    listEntry(entry, true);
    finished();
}
Ejemplo n.º 17
0
void MainWindow::setImage(const QImage &img, int imgIndex)
{
    currentQImage[imgIndex] = img;

    QSize totalSize(currentSize.width() * 2, currentSize.height());
    ui->scrollArea->widget()->resize(totalSize);

    update();
    updateActions();
}
Ejemplo n.º 18
0
 grid(std::vector<size_t> & sz)
 : size_tot(totalSize(sz)), sz(sz)
 {
   sz_s.resize(sz.size());
   sz_s[0] = sz[0];
   for (size_t i = 1 ;  i < sz.size() ; i++)
   {
     sz_s[i] = sz[i]*sz_s[i-1];
   }
 };
void testEmpty(){
    printf("Testing empty stack\n");
    
    Stack s = NULL;
    s = createStack();
    assert(s != NULL);  
    
    printf("%d\n", numPancakes(s));
    assert(numPancakes(s) == 0);

    assert(totalSize(s) == 0);
    printf("%d\n",totalSize(s));

    eatPancake(s);
    
    printToppings(s);
    printf("\n");
    consumeStack(s);
}
Ejemplo n.º 20
0
void AtlasTexture::commit(Image const &image, Vector2i const &topLeft) const
{
    GLTexture *tex = const_cast<AtlasTexture *>(this);

    if(size() == GLTexture::Size(0, 0))
    {
        // Hasn't been full-committed yet.
        tex->setUndefinedImage(totalSize(), Image::RGBA_8888);
    }

    tex->setSubImage(image, topLeft);
}
Ejemplo n.º 21
0
void AtlasTexture::commit(Image const &fullImage, Rectanglei const &subregion) const
{
    GLTexture *tex = const_cast<AtlasTexture *>(this);

    if (size() == GLTexture::Size(0, 0))
    {
        // Hasn't been full-committed yet.
        tex->setUndefinedImage(totalSize(), Image::RGBA_8888);
    }

    tex->setSubImage(fullImage, subregion);
}
void testOne(void){
    printf("Testing one pancake\n");
    Stack s = NULL;
    s = createStack();
    assert(s != NULL); 
    

    addPancake(s, "blueberry",10);
    
    printf("%d\n", numPancakes(s));
    assert(numPancakes(s) == 1);

    assert(totalSize(s) == 10);
    printf("%d\n",totalSize(s));

    printToppings(s);
    printf("\n");
    eatPancake(s);

    consumeStack(s);
}
Ejemplo n.º 23
0
/**
 * \brief Main loop
 */
void Scanner::loop()
{
	prctl(PR_SET_NAME, "fbitexp:Scanner\0", 0, 0, 0);
	
	std::mutex mtx;
	std::unique_lock<std::mutex> lock(mtx);
	
	MSG_DEBUG(msg_module, "started");
	
	while (!_done) {
		/* 
		 * This is before waiting because we want to check size on startup before 
		 * any scan or add requests
		 */
		if (totalSize() > _max_size) {
			removeDirs();
		}
		
		MSG_DEBUG(msg_module, "Total size: %s, Max: %s, Watermark: %s", 
			sizeToStr(totalSize()).c_str(), sizeToStr(_max_size).c_str(), sizeToStr(_watermark).c_str());
		_cv.wait(lock, [&]{ return scanCount() > 0 || addCount() > 0 || _done || totalSize() > _max_size; });
		
		if (_done) {
			break;
		}
		
		/* Add dirs from queue */
		if (addCount() > 0) {
			addNewDirs();
		}
		
		/* Scan dirs in queue */
		if (scanCount() > 0) {
			rescanDirs();
		}
	}
	
	MSG_DEBUG(msg_module, "closing thread");
}
void testTooManyPancakes(void){
    printf("Testing too many blueberry pancakes\n");
    Stack s = NULL;
    s = createStack();
    assert(s != NULL); 

    int i;
    for(i = 0; i < MAX_PANCAKES+3; i++){
        addPancake(s, "blueberry",10);
    }

    printf("%d\n", numPancakes(s));
    assert(numPancakes(s) == 40);

    assert(totalSize(s) == 400);
    printf("%d\n",totalSize(s));

    printToppings(s);
    printf("\n");
    consumeStack(s);

}
Ejemplo n.º 25
0
/*!
 * \brief Parses the header read using the specified \a reader.
 * \throws Throws InvalidDataException if the data read from the stream is
 *         no valid frame header.
 */
void AdtsFrame::parseHeader(IoUtilities::BinaryReader &reader)
{
    m_header1 = reader.readUInt16BE();
    // check whether syncword is present
    if ((m_header1 & 0xFFF6u) != 0xFFF0u) {
        throw InvalidDataException();
    }
    m_header2 = hasCrc() ? reader.readUInt56BE() : (reader.readUInt40BE() << 16);
    // check whether frame length is ok
    if (totalSize() < headerSize()) {
        throw InvalidDataException();
    }
}
Ejemplo n.º 26
0
	//////////////////////////////////////////////////////////////////////////
	//cross entropy
	float CrossEntropyFunctor::getLoss(const std::shared_ptr<DataBucket> labelDataBucket,
		const std::shared_ptr<DataBucket> outputDataBucket)
	{
		const auto outputSize = outputDataBucket->getSize();
		const float* labelData = labelDataBucket->getData().get();
		const float* outputData = outputDataBucket->getData().get();
		float loss = 0.0f;
		for (size_t i = 0; i < outputSize.totalSize(); i++)
		{
			const float curLoss = -labelData[i] * std::log(outputData[i]);
			loss = moving_average(loss, i+1, curLoss);
		}		
		return loss*outputSize._3DSize();
	}
Ejemplo n.º 27
0
	Point2d OverlayCategory::doGetTotalSize()const
	{
		OverlaySPtr parent = getOverlay().getParent();
		Size renderSize = getOverlay().getEngine()->getOverlayCache().getRenderer()->getSize();
		Point2d totalSize( renderSize.getWidth(), renderSize.getHeight() );

		if ( parent )
		{
			Point2d parentSize = parent->getAbsoluteSize();
			totalSize[0] = parentSize[0] * totalSize[0];
			totalSize[1] = parentSize[1] * totalSize[1];
		}

		return totalSize;
	}
Ejemplo n.º 28
0
void KJob::setTotalAmount(Unit unit, qulonglong amount)
{
    Q_D(KJob);
    bool should_emit = (d->totalAmount[unit] != amount);

    d->totalAmount[unit] = amount;

    if ( should_emit )
    {
        emit totalAmount(this, unit, amount);
        if (unit==d->progressUnit) {
            emit totalSize(this, amount);
            emitPercent(d->processedAmount[unit], d->totalAmount[unit]);
        }
    }
}
Ejemplo n.º 29
0
bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, void* planes[3],
                     bool useCache) {
    if (useCache) {
        fCachedData.reset(SkYUVPlanesCache::FindAndRef(provider->onGetID(), yuvInfo));
    }

    if (fCachedData.get()) {
        planes[0] = (void*)fCachedData->data();
        planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] *
                                           yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
        planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] *
                                           yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight);
    } else {
        // Fetch yuv plane sizes for memory allocation.
        if (!provider->onQueryYUV8(&yuvInfo->fSizeInfo, &yuvInfo->fColorSpace)) {
            return false;
        }

        // Allocate the memory for YUV
        size_t totalSize(0);
        for (int i = 0; i < 3; i++) {
            totalSize += yuvInfo->fSizeInfo.fWidthBytes[i] * yuvInfo->fSizeInfo.fSizes[i].fHeight;
        }
        if (useCache) {
            fCachedData.reset(SkResourceCache::NewCachedData(totalSize));
            planes[0] = fCachedData->writable_data();
        } else {
            fStorage.reset(totalSize);
            planes[0] = fStorage.get();
        }
        planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] *
                                           yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
        planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] *
                                           yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight);

        // Get the YUV planes.
        if (!provider->onGetYUV8Planes(yuvInfo->fSizeInfo, planes)) {
            return false;
        }

        if (useCache) {
            // Decoding is done, cache the resulting YUV planes
            SkYUVPlanesCache::Add(provider->onGetID(), fCachedData, yuvInfo);
        }
    }
    return true;
}
Ejemplo n.º 30
0
bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, void* planes[3],
                     bool useCache) {
    if (useCache) {
        fCachedData.reset(SkYUVPlanesCache::FindAndRef(provider->onGetID(), yuvInfo));
    }

    if (fCachedData.get()) {
        planes[0] = (void*)fCachedData->data();
        planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0];
        planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1];
    } else {
        // Fetch yuv plane sizes for memory allocation. Here, width and height can be
        // rounded up to JPEG block size and be larger than the image's width and height.
        if (!provider->onGetYUVSizes(yuvInfo->fSize)) {
            return false;
        }

        // Allocate the memory for YUV
        size_t totalSize(0);
        for (int i = 0; i < GrYUVProvider::kPlaneCount; ++i) {
            yuvInfo->fRowBytes[i] = yuvInfo->fSize[i].fWidth; // we assume snug fit: rb == width
            yuvInfo->fSizeInMemory[i] = yuvInfo->fRowBytes[i] * yuvInfo->fSize[i].fHeight;
            totalSize += yuvInfo->fSizeInMemory[i];
        }
        if (useCache) {
            fCachedData.reset(SkResourceCache::NewCachedData(totalSize));
            planes[0] = fCachedData->writable_data();
        } else {
            fStorage.reset(totalSize);
            planes[0] = fStorage.get();
        }
        planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0];
        planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1];

        // Get the YUV planes and update plane sizes to actual image size
        if (!provider->onGetYUVPlanes(yuvInfo->fSize, planes, yuvInfo->fRowBytes,
                                      &yuvInfo->fColorSpace)) {
            return false;
        }

        if (useCache) {
            // Decoding is done, cache the resulting YUV planes
            SkYUVPlanesCache::Add(provider->onGetID(), fCachedData, yuvInfo);
        }
    }
    return true;
}