void TextureChooser::onFileTxtRowChanged( int row ) { if( row < 0 ) return; QListWidgetItem *item = d_ptr->fileTextures->item( row ); QString fn = item->text(); std::string rfn = fn.toUtf8().constData(); rfn = NLMISC::CPath::lookup( rfn ); NLMISC::CIFile f; bool b = f.open( rfn ); if( !b ) { return; } NLMISC::CBitmap bm; uint8 depth = bm.load( f ); f.close(); b = bm.convertToType( NLMISC::CBitmap::RGBA ); if( !b ) { return; } setPreviewImage( bm ); }
bool CIconWnd::loadIcon(const std::string &filename, NLMISC::CBitmap &bmp) { // Try to get the file path string filepath = CPath::lookup(filename, false, false); if (filepath == "") { bmp.makeDummy(); bmp.convertToType(NLMISC::CBitmap::RGBA); bmp.resample(40, 40); return false; } // load icon CIFile f; f.open(filepath); bmp.load(f); bmp.convertToType(NLMISC::CBitmap::RGBA); bmp.resample(40, 40); f.close(); return true; }
// --------------------------------------------------------------------------- void CBuilderZone::snapshotCustom (const char *fileName, uint width, uint height, bool keepRatio, uint sizeSource, bool grayscale) { if (_ZoneRegions.size() == 0) return; // Some bitmaps NLMISC::CBitmap bitmapTmp; NLMISC::CBitmap bitmapDest; const CZoneRegion *pBZR = &(getDocument ()->getZoneRegion (_ZoneRegionSelected)); sint32 nMinX = pBZR->getMinX(); sint32 nMaxX = pBZR->getMaxX(); sint32 nMinY = pBZR->getMinY(); sint32 nMaxY = pBZR->getMaxY(); uint nSizeX = (nMaxX - nMinX + 1)*sizeSource; uint nSizeY = (nMaxY - nMinY + 1)*sizeSource; sint x, y, j; // Keep ratio ? if (keepRatio) height = (width * nSizeY) / nSizeX; // Resize the bitmaps bitmapDest.resize (nSizeX, nSizeY, NLMISC::CBitmap::RGBA); // white all NLMISC::CObjectVector<uint8> &rPixels = bitmapDest.getPixels(); memset (&rPixels[0], 0xff, rPixels.size ()); // Copy ZoneBitmaps in the bitmap CUV uvMin, uvMax; ITexture *pTexture; CZoneBankElement *pZBE; uint8 nRot, nFlip; // For each tiles for (y = nMinY; y <= nMaxY; ++y) for (x = nMinX; x <= nMaxX; ++x) { const string &rsZoneName = pBZR->getName (x, y); if ((rsZoneName == STRING_OUT_OF_BOUND) && (rsZoneName == STRING_UNUSED)) continue; pZBE = _ZoneBank.getElementByZoneName (rsZoneName); if (pZBE == NULL) continue; // Get the texture pTexture = _DataBase.getTexture (rsZoneName, pBZR->getPosX(x, y), pBZR->getPosY(x, y), uvMin, uvMax); // Generate it pTexture->generate (); // Be sure it is tga pTexture->convertToType (NLMISC::CBitmap::RGBA); // Get rot nRot = pBZR->getRot(x, y); // Get flip nFlip = pBZR->getFlip(x, y); // Copy the texture // Dest bitmap size uint destWidth = 1+(uint)((float)pTexture->getWidth() * (uvMax.U - uvMin.U)); uint destHeight = 1+(uint)((float)pTexture->getHeight() * (uvMax.V - uvMin.V)); bitmapTmp.resize (destWidth, destHeight, NLMISC::CBitmap::RGBA); // Source bitmap size and position uint u = (uint)((float)pTexture->getWidth() * uvMin.U); uint v = (uint)((float)pTexture->getHeight() * uvMin.V); uint sourceWidth = pTexture->getWidth(); uint sourceHeight = pTexture->getHeight(); // Source pointer uint8 *srcPixels = &(pTexture->getPixels ()[0]); // Destination pointer uint8 *destPixels = &(bitmapTmp.getPixels ()[0]); // Copy the temp bitmap for (j = 0; j < (sint)destHeight; ++j) // Copy the line memcpy (destPixels+(4*j*destWidth), srcPixels + 4 * ( (v + j) * sourceWidth + u), destWidth*4); // Flip ? if (nFlip) bitmapTmp.flipH(); // Rot ? while (nRot) { bitmapTmp.rot90CW (); nRot--; } // Resize the bitmap to normal size if ( (bitmapTmp.getWidth () != sizeSource) || (bitmapTmp.getHeight () != sizeSource) ) bitmapTmp.resample (sizeSource, sizeSource); // Copy it in the map bitmapDest.blit (&bitmapTmp, (x-nMinX)*sizeSource, (y-nMinY)*sizeSource); pTexture->release (); } // Resample the final bitmap bitmapDest.resample (width, height); bitmapDest.flipV (); COFile f(fileName, false, false, true); if (grayscale) { bitmapDest.convertToType (NLMISC::CBitmap::Luminance); if (bitmapDest.writeTGA (f, 8)) f.close(); } else { if (bitmapDest.writeTGA (f, 32)) f.close(); } }