//******************************************** // Alloc //******************************************** int CTexture::Alloc(unsigned int width, unsigned int height, unsigned int depth) { Free(); unsigned int BytePerPixel = (unsigned int)(depth / 8); unsigned int Width32 = WidthByte32(width,depth); // Only rgb and rgba modes ASSERT(BytePerPixel == 3 || BytePerPixel == 4); m_pData = new unsigned char [Width32 * height]; if(m_pData == NULL) { TRACE("CTexture::Alloc : Insuffisant memory\n"); AfxMessageBox("CTexture::Alloc : Insufisant memory"); return 0; } // Set members variables m_Width = width; m_WidthByte32 = Width32; m_Height = height; m_Depth = depth; UpdateHeader(); return 1; }
//******************************************** // Extract //******************************************** int Texture::Extract(int left, int top, int right, int bottom) { // Saturate if(right == -1) right = m_Width-1; if(bottom == -1) bottom = m_Height-1; // Check if(left >= right || top >= bottom) return 0; if(left < 0 || left >= (int)m_Width || right < 0 || right >= (int)m_Width) return 0; if(top < 0 || top >= (int)m_Height || bottom < 0 || bottom >= (int)m_Height) return 0; int NewWidth = right-left+1; int NewWidthByte32 = WidthByte32(NewWidth,m_Depth); int NewHeight = bottom-top+1; int BytePerPixel = m_Depth / 8; int i,j,k; //TRACE("Start extracting...\n"); //TRACE("New width : %d\n",NewWidth); //TRACE("New height : %d\n",NewHeight); // Alloc unsigned char *pData = new unsigned char[NewWidthByte32*NewHeight]; if(pData == NULL) { //TRACE("Insufficiant memory"); return 0; } for(j=0;j<NewHeight;j++) for(i=0;i<NewWidth;i++) for(k=0;k<BytePerPixel;k++) pData[NewWidthByte32*j+i*BytePerPixel+k] = m_pData[m_WidthByte32*(m_Height-1-(j+top))+(i+left)*BytePerPixel+k]; // Replace datas delete [] m_pData; m_pData = pData; m_Width = NewWidth; m_WidthByte32 = NewWidthByte32; m_Height = NewHeight; UpdateHeader(); return 1; }
//******************************************** // DuplicateRepeatWidth //******************************************** int Texture::DuplicateRepeatWidth(int left, int top, int right, int bottom) { if(!Extract(left,top,right,bottom)) return 0; left = 0; right = m_Width-1; top = 0; bottom = m_Height-1; int NewWidth = 2*m_Width; int NewWidthByte32 = WidthByte32(NewWidth,m_Depth); int NewHeight = m_Height; int BytePerPixel = m_Depth / 8; int i,j,k; ////TRACE("Start duplicate repeat width...\n"); ////TRACE("New width : %d\n",NewWidth); ////TRACE("New widthbyte32 : %d\n",NewWidthByte32); ////TRACE("New height : %d\n",NewHeight); // Alloc unsigned char *pData = new unsigned char[NewWidthByte32*NewHeight]; if(pData == NULL) { ////TRACE("Insufficiant memory"); return 0; } // x o for(j=0;j<NewHeight;j++) for(i=0;i<NewWidth/2;i++) for(k=0;k<BytePerPixel;k++) pData[NewWidthByte32*j+i*BytePerPixel+k] = m_pData[m_WidthByte32*(bottom-(j+top))+(i+left)*BytePerPixel+k]; // o x for(j=0;j<NewHeight;j++) for(i=NewWidth/2;i<NewWidth;i++) for(k=0;k<BytePerPixel;k++) pData[NewWidthByte32*j+i*BytePerPixel+k] = m_pData[m_WidthByte32*(bottom-(j+top))+(i-NewWidth/2+left)*BytePerPixel+k]; // Replace datas delete [] m_pData; m_pData = pData; m_Width = NewWidth; m_WidthByte32 = NewWidthByte32; m_Height = NewHeight; UpdateHeader(); return 1; }
//******************************************** // Alloc //******************************************** int Texture::Alloc(unsigned int width, unsigned int height, unsigned int depth) { Free(); unsigned int Width32 = WidthByte32(width,depth); m_pData = new unsigned char [Width32 * height]; if(m_pData == NULL) { return 0; } // Set members variables m_Width = width; m_WidthByte32 = Width32; m_Height = height; m_Depth = depth; UpdateHeader(); return 1; }
//******************************************** // UpdateWidthByte32 //******************************************** void Texture::UpdateWidthByte32() { m_WidthByte32 = WidthByte32(m_Width,m_Depth); }