当前位置: 首页>>代码示例>>C++>>正文


C++ ImageLoader::GetImageData方法代码示例

本文整理汇总了C++中ImageLoader::GetImageData方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageLoader::GetImageData方法的具体用法?C++ ImageLoader::GetImageData怎么用?C++ ImageLoader::GetImageData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImageLoader的用法示例。


在下文中一共展示了ImageLoader::GetImageData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: memcpy

unsigned int __stdcall Texture::Atlas::ThreadLoadTexture( void* data ) {
  Thread::Work *work = ( Thread::Work* ) data;
  ThreadDataLoadTexture *loader = ( ThreadDataLoadTexture* ) work->data;
  //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::ThreadLoadTexture => begin: data[%d] size[%d; %d]", loader->data->getLength(), loader->size.width, loader->size.height );
  //

  ImageLoader image;
  if( !image.LoadFromBuffer( ( Byte* ) loader->data->getData(), loader->data->getLength() ) ) {
    __log.PrintInfo( Filelevel_ERROR, "Texture::Atlas::ThreadLoadTexture => image.LoadFromBuffer failed" );
    work->status = Thread::THREAD_WORK_STATUS_ERROR;
    return 1;
  }
  Dword
    *dst = ( Dword* ) loader->atlas->textureData.getData(),
    *src = ( Dword* ) image.GetImageData();
  for( Dword y = 0; y < image.GetImageSize().height; ++y ) {
    memcpy( dst + ( loader->item->rect.top + y ) * loader->atlas->size.width + loader->item->rect.left, src + y * image.GetImageSize().width, image.GetImageSize().width * 4 );
  }
  loader->atlas->FlushToGPU();

  //done
  delete loader->data;
  delete loader;
  work->status = Thread::THREAD_WORK_STATUS_DONE;
  //__log.PrintInfo( Filelevel_DEBUG, "Texture::Atlas::ThreadLoadTexture => done" );
  return 0;
}//ThreadLoadTexture
开发者ID:KoMaTo3,项目名称:flatuniverse,代码行数:27,代码来源:textureatlas.cpp

示例2: size

/*
=============
  LoadTexture
=============
*/
Texture::Atlas::Item* Texture::Atlas::LoadTexture( const std::string& textureFileName, const bool forceLoad )
{
  ImageLoader image;
  Size size( 0, 0 );
  memory *deferredLoadingData;

  if( forceLoad ) {
    if( !image.LoadFromFile( textureFileName ) ) {
      __log.PrintInfo( Filelevel_ERROR, "Texture::Atlas::LoadTexture => file not found '%s'", textureFileName.c_str() );
      return NULL;
    }
    size = image.GetImageSize();
  } else {
    deferredLoadingData = new memory();
    __fileManager->GetFile( textureFileName, *deferredLoadingData );
    size = ImageLoader::GetImageSizeFromBuffer( ( Byte* ) deferredLoadingData->getData(), deferredLoadingData->getLength() );
  }

  if( !this->atlas.HasPlace( size ) ) {
    __log.PrintInfo( Filelevel_ERROR, "Texture::Atlas::LoadTexture => atlas can't find needed place [ %d; %d ]", size.width, size.height );
    return NULL;
  }

  Texture::Atlas::Item *item = new Texture::Atlas::Item();
  Rect< Dword > fullRect;
  this->atlas.Cut( size + Size( this->borderPerItem * 2, this->borderPerItem * 2 ), &fullRect );
  item->rect = Rect< Dword >( fullRect.left + 1, fullRect.top + 1, fullRect.right - 1, fullRect.bottom - 1 );
  item->textureFileName = textureFileName;

  Vec2 scale( float( item->rect.right - item->rect.left + 1 ) / float( this->size.width ), float( item->rect.bottom - item->rect.top + 1 ) / float( this->size.height ) );
  Vec2 translate( float( item->rect.left ) / float( this->size.width ), float( item->rect.top ) / float( this->size.height ) );

  item->matTransform.Identity();
  Mat4 matTranslate, matScale, matInvTranslate, matInvScale;
  matTranslate.Identity();
  matInvTranslate.Identity();
  matScale.Identity();
  matInvScale.Identity();

  matScale[ 0 ][ 0 ] = scale.x;
  matScale[ 1 ][ 1 ] = scale.y;
  matInvScale[ 0 ][ 0 ] = 1.0f / scale.x;
  matInvScale[ 1 ][ 1 ] = 1.0f / scale.y;

  matTranslate[ 0 ][ 3 ] = translate.x;
  matTranslate[ 1 ][ 3 ] = translate.y;
  matInvTranslate[ 0 ][ 3 ] = -translate.x;
  matInvTranslate[ 1 ][ 3 ] = -translate.y;

  //__log.PrintInfo( Filelevel_DEBUG, "matrix translate: [ %3.3f; %3.3f ]", translate.x, translate.y );
  //__log.PrintInfo( Filelevel_DEBUG, "matrix scale: [ %3.3f; %3.3f ]", scale.x, scale.y );

  item->matTransform = matTranslate * matScale;
  item->matInvTransform = matInvScale * matInvTranslate;

  //размещение картинки в текстуре
  if( forceLoad ) {
    //this->Bind();
    Dword
      *dst = ( Dword* ) this->textureData.getData(),
      *src = ( Dword* ) image.GetImageData();
    for( Dword y = 0; y < image.GetImageSize().height; ++y ) {
      memcpy( dst + ( item->rect.top + y ) * this->size.width + item->rect.left, src + y * image.GetImageSize().width, image.GetImageSize().width * 4 );
    }
    //glTexImage2D( GL_TEXTURE_2D, 0, 4, this->size.width, this->size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, this->textureData.getData() );
    //this->Unbind();
    this->FlushToGPU();
  } else {
    // TODO: здесь отложенная загрузка
    // класть в стек deferredLoadingData, указатель на атлас и Texture::Atlas::Item item
    ThreadDataLoadTexture *loader = new ThreadDataLoadTexture();
    loader->data = deferredLoadingData;
    loader->size = size;
    loader->atlas = this;
    loader->item = item;
    extern Thread::Pipeline *__workPipeline;
    __workPipeline->Add( loader, Texture::Atlas::ThreadLoadTexture );
  }

  this->textures.push_back( item );
  return item;
}//LoadTexture
开发者ID:KoMaTo3,项目名称:flatuniverse,代码行数:87,代码来源:textureatlas.cpp


注:本文中的ImageLoader::GetImageData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。