Marmalade SDKФорум

Помогите получить доступ к битам изображения =)

#0
19:11, 6 июля 2012

В SDL это делается так:

fmt = surface->format;
SDL_LockSurface(surface);
pixel = *((Uint32*)surface->pixels); /* первый пиксель */
SDL_UnlockSurface(surface);

В Cocos2d-x должна быть возможность получить доступ к битам CCImage через GetData(); (Вот тут косяк, у меня - указатель на пустое место)
А как получить доступ к битам в marmalade? Поидее CIwImage должен помоч:

CIwImage image;
image->LoadFromFile ("Name") ;
uint8 *   pointerToData=image->GetTexels () ;

Но и тут байда - указатель на пустую область данных =(
Вопрос задавал в теме 2D графики =)

#1
19:15, 6 июля 2012

не выгружай из памяти растр после загрузки текстуры
и читай данные прямо из растра

unsigned int  CTexture::getPixel( int x, int y ) const
{
  if( !m_texturedata )
    return 0;

  return m_texturedata[ x + m_ImgWidthPow2 * y];
}

bool CTexture::createTexture( const char* file, const char* resource, bool savetexturememory )
{
  if( file )
    m_textureFileName = file;
  
  if( resource )
    m_resourcePakName = resource;

  // Load image from file
  CIwImage img;

  s3eFile* sFile = _S(resourceManager)->openMemoryFile( file, resource );

  if( !sFile )
  {    
    img.LoadFromFile( file );
  }
  else
  {
    img.ReadFile( sFile );       
    _S(resourceManager)->closeFile( sFile );
    return false;
  }

  // Convert to an OpenGL ES native format
  CIwImage nativeImg;
  nativeImg.SetFormat( CIwImage::ABGR_8888 );
  img.ConvertToImage(&nativeImg);

  // Generate texture object
  glGenTextures(1, &m_textureID);
  glBindTexture( GL_TEXTURE_2D, m_textureID );


  m_width      = img.GetWidth();
  m_height    = img.GetHeight();


  m_ImageFileWidth  = m_width;
  m_ImageFileHeight  = m_height;

  m_ImgWidthPow2  = convert( m_width  );
  m_ImgHeightPow2  = convert( m_height  );


  unsigned char* srcTexels = nativeImg.GetTexels();

  int sz = m_ImageFileWidth * m_ImageFileHeight;
  
  unsigned int* dstTexelsInt =  (unsigned int*)srcTexels;

  //потому что эта пизда сделанный в фотошопе 32 битный растр грузит с прозрачной альфой блять
  if( strstr( file, ".bmp" ) )
  {
    for( int it = 0; it < sz; it++ )
      dstTexelsInt[ it ] |= 0xFF000000;
  }

  // проверочку на колоркей сюда
  for( int it = 0; it < sz; it++ )
  {
    if( dstTexelsInt[ it ] == m_colorkey )
      dstTexelsInt[ it ] = 0;
  }

  unsigned char* dstTexels = (unsigned char*)_S(resourceManager)->malloc( m_ImgWidthPow2 * m_ImgHeightPow2 * 4 );
  
  if( !dstTexels || !srcTexels )
    return false;

  memset( dstTexels, 0, m_ImgWidthPow2 * m_ImgHeightPow2 * 4 );

  for( int y = 0; y < m_height; y++ )
  {
    memcpy( &dstTexels[ 4 * m_ImgWidthPow2 * y ], &srcTexels[ 4 * m_width * y ],  4*m_width );

    unsigned int* srcTexelsInt  = (unsigned int*)&srcTexels[ 4 * m_width * y ];
    unsigned int* dstTexelsInt  = (unsigned int*)&dstTexels[ 4 * m_ImgWidthPow2 * y];

    unsigned int mLastPixel    = srcTexelsInt[ m_width - 1 ];
    
    for( int x = m_width; x < m_ImgWidthPow2; x++ )
      dstTexelsInt[ x ] = mLastPixel;
    
  }
  
  unsigned int* srcTexelsInt  = (unsigned int*)&srcTexels[ 4 * m_width * ( m_height - 1 ) ];

  for( int x = 0; x < m_ImgWidthPow2; x++ )
  {
    unsigned int mLastPixel    = srcTexelsInt[ x ];

    for( int y = m_height; y < m_ImgHeightPow2; y++ )
    {
      unsigned int* dstTexelsInt =  (unsigned int*)&dstTexels[ 4 * m_ImgWidthPow2 * y + 4 * x ];
      dstTexelsInt[ 0 ] = mLastPixel;
    }
  }

  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_ImgWidthPow2, m_ImgHeightPow2, 0, GL_RGBA, GL_UNSIGNED_BYTE, dstTexels );

  m_texturedata = (unsigned int*)dstTexels;
  
  if( false == savetexturememory )
  {
    _S(resourceManager)->free( (void*)dstTexels );
    m_texturedata = NULL;
  }

  // Disable mipmapping
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

  return true;
}
#2
19:26, 6 июля 2012

Спасибо, примерно то что надо =) В оригинале надо объединить два изображения, одно в jpeg, второе в png(маска). Думаю по этому гайду все выйдет =)

#3
19:40, 6 июля 2012

_S(resourceManager)->openMemoryFile а это что такое если не секрет?

#4
20:29, 6 июля 2012
Косяк | Помогите получить доступ к битам изображения =) вообщем вот иллюстрацию проблемы =)
Marmalade SDKФорум

Тема в архиве.