本文整理汇总了C++中CBitmap::Alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ CBitmap::Alloc方法的具体用法?C++ CBitmap::Alloc怎么用?C++ CBitmap::Alloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CBitmap
的用法示例。
在下文中一共展示了CBitmap::Alloc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateSplatDetailTextures
void CSMFReadMap::CreateSplatDetailTextures()
{
if (!haveSplatTexture) {
return;
}
CBitmap splatDistrTexBM;
CBitmap splatDetailTexBM;
// if the map supplies an intensity- AND a distribution-texture for
// detail-splat blending, the regular detail-texture is not used
if (!splatDetailTexBM.Load(mapInfo->smf.splatDetailTexName)) {
// default detail-texture should be all-grey
splatDetailTexBM.channels = 4;
splatDetailTexBM.Alloc(1, 1);
splatDetailTexBM.mem[0] = 127;
splatDetailTexBM.mem[1] = 127;
splatDetailTexBM.mem[2] = 127;
splatDetailTexBM.mem[3] = 127;
}
if (!splatDistrTexBM.Load(mapInfo->smf.splatDistrTexName)) {
splatDistrTexBM.channels = 4;
splatDistrTexBM.Alloc(1, 1);
splatDistrTexBM.mem[0] = 255;
splatDistrTexBM.mem[1] = 0;
splatDistrTexBM.mem[2] = 0;
splatDistrTexBM.mem[3] = 0;
}
splatDetailTex = splatDetailTexBM.CreateTexture(true);
splatDistrTex = splatDistrTexBM.CreateTexture(true);
}
示例2: SetUnitDefImage
void CUnitDefHandler::SetUnitDefImage(const UnitDef* unitDef, const std::string& texName)
{
if (unitDef->buildPic == NULL) {
unitDef->buildPic = new UnitDefImage();
} else {
unitDef->buildPic->Free();
}
CBitmap bitmap;
if (!texName.empty()) {
bitmap.Load("unitpics/" + texName);
}
else {
if (!LoadBuildPic("unitpics/" + unitDef->name + ".dds", bitmap) &&
!LoadBuildPic("unitpics/" + unitDef->name + ".png", bitmap) &&
!LoadBuildPic("unitpics/" + unitDef->name + ".pcx", bitmap) &&
!LoadBuildPic("unitpics/" + unitDef->name + ".bmp", bitmap)) {
bitmap.Alloc(1, 1); // last resort
}
}
const unsigned int texID = bitmap.CreateTexture(false);
UnitDefImage* unitImage = unitDef->buildPic;
unitImage->textureID = texID;
unitImage->imageSizeX = bitmap.xsize;
unitImage->imageSizeY = bitmap.ysize;
}
示例3: Blur
void CBitmap::Blur(int iterations, float weight)
{
if (type == BitmapTypeDDS) {
return;
}
CBitmap* src = this;
CBitmap* dst = new CBitmap();
dst->channels = src->channels;
dst->Alloc(xsize,ysize);
for (int i=0; i < iterations; ++i){
{
int j,y,x;
// Threading::OMPCheck();
// This is currently used too early, OMP is not initialized here
// #pragma omp parallel for private(j,x,y)
for (y=0; y < ysize; y++) {
for (x=0; x < xsize; x++) {
for (j=0; j < channels; j++) {
kernelBlur(dst, src->mem, x, y, j, weight);
}
}
}
}
std::swap(src, dst);
}
if (dst == this) {
// make sure we don't delete `this`
std::swap(src, dst);
}
delete dst;
}
示例4: Blur
void CBitmap::Blur(int iterations, float weight)
{
if (type == BitmapTypeDDS) {
return;
}
CBitmap* src = this;
CBitmap* dst = new CBitmap();
dst->channels = src->channels;
dst->Alloc(xsize,ysize);
for (int i=0; i < iterations; ++i){
{
for_mt(0, ysize, [&](const int y) {
for (int x=0; x < xsize; x++) {
for (int j=0; j < channels; j++) {
kernelBlur(dst, src->mem, x, y, j, weight);
}
}
});
}
std::swap(src, dst);
}
if (dst == this) {
// make sure we don't delete `this`
std::swap(src, dst);
}
delete dst;
}
示例5: glSaveTexture
void glSaveTexture(const GLuint textureID, const char* filename)
{
const GLenum target = GL_TEXTURE_2D;
GLenum format = GL_RGBA8;
int sizeX, sizeY;
int bits = 0;
{
glBindTexture(GL_TEXTURE_2D, textureID);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &sizeX);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &sizeY);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT, (GLint*)&format);
GLint _cbits;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &_cbits); bits += _cbits;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &_cbits); bits += _cbits;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &_cbits); bits += _cbits;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &_cbits); bits += _cbits;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_DEPTH_SIZE, &_cbits); bits += _cbits;
}
assert(bits == 32);
assert(format == GL_RGBA8);
CBitmap bmp;
bmp.Alloc(sizeX, sizeY, 4);
glGetTexImage(target, 0, GL_RGBA, GL_UNSIGNED_BYTE, bmp.GetRawMem());
bmp.Save(filename, false);
}
示例6: LoadCursorImage
bool CMouseCursor::LoadCursorImage(const string& name, ImageData& image)
{
CFileHandler f(name);
if (!f.FileExists()) {
return false;
}
CBitmap b;
if (!b.Load(name)) {
LOG_L(L_ERROR, "CMouseCursor: Bad image file: %s", name.c_str());
return false;
}
// hardcoded bmp transparency mask
if (FileSystem::GetExtension(name) == "bmp") {
b.SetTransparent(SColor(84, 84, 252));
}
if (hwCursor->NeedsYFlip()) {
//WINDOWS
b.ReverseYAxis();
hwCursor->PushImage(b.xsize,b.ysize,&b.mem[0]);
}else{
//X11
hwCursor->PushImage(b.xsize,b.ysize,&b.mem[0]);
b.ReverseYAxis();
}
const int nx = next_power_of_2(b.xsize);
const int ny = next_power_of_2(b.ysize);
if (b.xsize != nx || b.ysize != ny) {
CBitmap bn;
bn.Alloc(nx, ny);
bn.CopySubImage(b, 0, ny - b.ysize);
image.texture = bn.CreateTexture();
image.xOrigSize = b.xsize;
image.yOrigSize = b.ysize;
image.xAlignedSize = bn.xsize;
image.yAlignedSize = bn.ysize;
} else {
image.texture = b.CreateTexture();
image.xOrigSize = b.xsize;
image.yOrigSize = b.ysize;
image.xAlignedSize = b.xsize;
image.yAlignedSize = b.ysize;
}
return true;
}
示例7: CreateSplatDetailTextures
void CSMFReadMap::CreateSplatDetailTextures()
{
if (!haveSplatDetailDistribTexture)
return;
CBitmap splatDistrTexBM;
CBitmap splatDetailTexBM;
// if the map supplies an intensity- AND a distribution-texture for
// detail-splat blending, the regular detail-texture is not used
if (!splatDetailTexBM.Load(mapInfo->smf.splatDetailTexName)) {
// default detail-texture should be all-grey
splatDetailTexBM.channels = 4;
splatDetailTexBM.AllocDummy(SColor(127,127,127,127));
}
if (!splatDistrTexBM.Load(mapInfo->smf.splatDistrTexName)) {
splatDistrTexBM.channels = 4;
splatDistrTexBM.AllocDummy(SColor(255,0,0,0));
}
splatDetailTex.SetRawTexID(splatDetailTexBM.CreateTexture(texAnisotropyLevels[true], true));
splatDetailTex.SetRawSize(int2(splatDetailTexBM.xsize, splatDetailTexBM.ysize));
splatDistrTex.SetRawTexID(splatDistrTexBM.CreateTexture(texAnisotropyLevels[true], true));
splatDistrTex.SetRawSize(int2(splatDistrTexBM.xsize, splatDistrTexBM.ysize));
// only load the splat detail normals if any of them are defined and present
if (!haveSplatNormalDistribTexture)
return;
for (size_t i = 0; i < mapInfo->smf.splatDetailNormalTexNames.size(); i++) {
if (i == NUM_SPLAT_DETAIL_NORMALS)
break;
CBitmap splatDetailNormalTextureBM;
if (!splatDetailNormalTextureBM.Load(mapInfo->smf.splatDetailNormalTexNames[i])) {
splatDetailNormalTextureBM.channels = 4;
splatDetailNormalTextureBM.Alloc(1, 1);
splatDetailNormalTextureBM.mem[0] = 127; // RGB is packed standard normal map
splatDetailNormalTextureBM.mem[1] = 127;
splatDetailNormalTextureBM.mem[2] = 255; // With a single upward (+Z) pointing vector
splatDetailNormalTextureBM.mem[3] = 127; // Alpha is diffuse as in old-style detail textures
}
splatNormalTextures[i].SetRawTexID(splatDetailNormalTextureBM.CreateTexture(texAnisotropyLevels[true], true));
splatNormalTextures[i].SetRawSize(int2(splatDetailNormalTextureBM.xsize, splatDetailNormalTextureBM.ysize));
}
}
示例8: CreateRescaled
CBitmap CBitmap::CreateRescaled(int newx, int newy) const
{
newx = std::max(1, newx);
newy = std::max(1, newy);
CBitmap bm;
bm.Alloc(newx, newy);
const float dx = (float) xsize / newx;
const float dy = (float) ysize / newy;
float cy = 0;
for (int y=0; y < newy; ++y) {
const int sy = (int) cy;
cy += dy;
int ey = (int) cy;
if (ey == sy) {
ey = sy+1;
}
float cx = 0;
for (int x=0; x < newx; ++x) {
const int sx = (int) cx;
cx += dx;
int ex = (int) cx;
if (ex == sx) {
ex = sx + 1;
}
int r=0, g=0, b=0, a=0;
for (int y2 = sy; y2 < ey; ++y2) {
for (int x2 = sx; x2 < ex; ++x2) {
const int index = (y2*xsize + x2) * 4;
r += mem[index + 0];
g += mem[index + 1];
b += mem[index + 2];
a += mem[index + 3];
}
}
const int index = (y*bm.xsize + x) * 4;
const int denom = (ex - sx) * (ey - sy);
bm.mem[index + 0] = r / denom;
bm.mem[index + 1] = g / denom;
bm.mem[index + 2] = b / denom;
bm.mem[index + 3] = a / denom;
}
}
return bm;
}
示例9: GenWaterQuadsList
CBasicWater::CBasicWater()
{
CBitmap waterTexBM;
if (!waterTexBM.Load(mapInfo->water.texture)) {
LOG_L(L_WARNING, "[%s] could not read water texture from file \"%s\"", __FUNCTION__, mapInfo->water.texture.c_str());
// fallback
waterTexBM.channels = 4;
waterTexBM.Alloc(1, 1);
waterTexBM.mem[0] = 0;
waterTexBM.mem[1] = 0;
waterTexBM.mem[2] = 255;
waterTexBM.mem[3] = 255;
}
// create mipmapped texture
textureID = waterTexBM.CreateTexture(true);
displistID = GenWaterQuadsList(waterTexBM.xsize, waterTexBM.ysize);
}
示例10: content_error
int CS3OTextureHandler::LoadS3OTextureNow(const S3DModel* model)
{
GML_STDMUTEX_LOCK(model); // LoadS3OTextureNow
string totalName = model->tex1 + model->tex2;
if (s3oTextureNames.find(totalName) != s3oTextureNames.end()){
return s3oTextureNames[totalName];
}
const int newNum = s3oTextures.size();
S3oTex tex;
tex.num = newNum;
CBitmap bm;
if (!bm.Load(std::string("unittextures/" + model->tex1))) {
throw content_error("Could not load texture unittextures/" + model->tex1 + " from S3O model " + model->name);
}
tex.tex1 = bm.CreateTexture(true);
tex.tex1SizeX = bm.xsize;
tex.tex1SizeY = bm.ysize;
tex.tex2 = 0;
tex.tex2SizeX = 0;
tex.tex2SizeY = 0;
//if (unitDrawer->advShading)
{
CBitmap bm;
// No error checking here... other code relies on an empty texture
// being generated if it couldn't be loaded.
// Also many map features specify a tex2 but don't ship it with the map,
// so throwing here would cause maps to break.
if (!bm.Load(std::string("unittextures/" + model->tex2))) {
bm.Alloc(1, 1);
bm.mem[3] = 255; // file not found, set alpha to white so unit is visible
}
tex.tex2 = bm.CreateTexture(true);
tex.tex2SizeX = bm.xsize;
tex.tex2SizeY = bm.ysize;
}
s3oTextures.push_back(tex);
s3oTextureNames[totalName] = newNum;
return newNum;
}
示例11: CreateSpecularTex
void CSMFReadMap::CreateSpecularTex()
{
if (!haveSpecularTexture) {
return;
}
CBitmap specularTexBM;
CBitmap skyReflectModTexBM;
CBitmap detailNormalTexBM;
CBitmap lightEmissionTexBM;
CBitmap parallaxHeightTexBM;
if (!specularTexBM.Load(mapInfo->smf.specularTexName)) {
// maps wants specular lighting, but no moderation
specularTexBM.channels = 4;
specularTexBM.Alloc(1, 1);
specularTexBM.mem[0] = 255;
specularTexBM.mem[1] = 255;
specularTexBM.mem[2] = 255;
specularTexBM.mem[3] = 255;
}
specularTex = specularTexBM.CreateTexture(false);
// no default 1x1 textures for these
if (skyReflectModTexBM.Load(mapInfo->smf.skyReflectModTexName)) {
skyReflectModTex = skyReflectModTexBM.CreateTexture(false);
}
if (detailNormalTexBM.Load(mapInfo->smf.detailNormalTexName)) {
detailNormalTex = detailNormalTexBM.CreateTexture(false);
}
if (lightEmissionTexBM.Load(mapInfo->smf.lightEmissionTexName)) {
lightEmissionTex = lightEmissionTexBM.CreateTexture(false);
}
if (parallaxHeightTexBM.Load(mapInfo->smf.parallaxHeightTexName)) {
parallaxHeightTex = parallaxHeightTexBM.CreateTexture(false);
}
}
示例12: GetMinimap
/*
* Class: aflobby_CUnitSyncJNIBindings
* Method: WriteMiniMap
* Signature: (II)I
*/
JNIEXPORT jboolean JNICALL Java_aflobby_CUnitSyncJNIBindings_WriteMiniMap
(JNIEnv *env, jclass myobject, jstring mapfile, jstring imagename, jint miplevel){
const char *filename = env->GetStringUTFChars(mapfile, 0);
const char *bitmap_filename = env->GetStringUTFChars(imagename, 0);
void* minimap = GetMinimap(filename, miplevel);
if (!minimap){
env->ReleaseStringUTFChars(mapfile, filename);
env->ReleaseStringUTFChars(mapfile, bitmap_filename);
return false;
}
int size = 1024 >> miplevel;
CBitmap bm;
bm.Alloc(size, size);
unsigned short *src = (unsigned short*)minimap;
unsigned char *dst = bm.mem;
for (int y = 0; y < size; y++) {
for (int x = 0; x < size; x++){
dst[0] = RED_RGB565 ((*src)) << 3;
dst[1] = GREEN_RGB565 ((*src)) << 2;
dst[2] = BLUE_RGB565 ((*src)) << 3;
dst[3] = 255;
++src;
dst += 4;
}
}
remove(bitmap_filename); //somehow overwriting doesn't work??
bm.Save(bitmap_filename);
// check whether the bm.Save succeeded?
FILE* f = fopen(bitmap_filename, "rb");
bool success = !!f;
if (success) {
fclose(f);
}
env->ReleaseStringUTFChars(mapfile, filename);
env->ReleaseStringUTFChars(mapfile, bitmap_filename);
return success;
}
示例13: Blur
void CBitmap::Blur(int iterations, float weight)
{
if (type == BitmapTypeDDS) {
return;
}
CBitmap* src = this;
CBitmap* dst = new CBitmap();
dst->channels = src->channels;
dst->Alloc(xsize,ysize);
for (int i=0; i < iterations; ++i){
{
int j,y,x;
#pragma omp parallel for private(j,x,y)
for (y=0; y < ysize; y++) {
for (x=0; x < xsize; x++) {
for (j=0; j < channels; j++) {
kernelBlur(dst, src->mem, x, y, j, weight);
}
}
}
}
CBitmap* buf = dst;
dst = src;
src = buf;
}
if (dst == this) {
CBitmap* buf = dst;
dst = src;
src = buf;
}
delete dst;
}
示例14: Blur
void CBitmap::Blur(int iterations, float weight)
{
if (type == BitmapTypeDDS) {
return;
}
CBitmap* src = this;
CBitmap* dst = new CBitmap();
dst->channels = src->channels;
dst->Alloc(xsize,ysize);
for (int i=0; i < iterations; ++i){
#pragma omp parallel private(y,x,i)
{
#pragma omp for
for (int y=0; y < ysize; ++y) {
for (int x=0; x < xsize; ++x) {
for (int i=0; i < channels; ++i) {
kernelBlur(dst, src->mem, x, y, i, weight);
}
}
}
}
CBitmap* buf = dst;
dst = src;
src = buf;
}
if (dst == this) {
CBitmap* buf = dst;
dst = src;
src = buf;
}
delete dst;
}
示例15: content_error
CSMFReadMap::CSMFReadMap(std::string mapname): file(mapname)
{
loadscreen->SetLoadMessage("Loading SMF");
ConfigureAnisotropy();
for (int a = 0; a < 1024; ++a) {
for (int b = 0; b < 3; ++b) {
const float absorbColor = mapInfo->water.baseColor[b] - mapInfo->water.absorb[b] * a;
const float clampedColor = max(mapInfo->water.minColor[b], absorbColor);
waterHeightColors[a * 4 + b] = clampedColor * 210;
}
waterHeightColors[a * 4 + 3] = 1;
}
const SMFHeader& header = file.GetHeader();
const CMapInfo::smf_t& smf = mapInfo->smf;
width = header.mapx;
height = header.mapy;
numBigTexX = (header.mapx / bigSquareSize);
numBigTexY = (header.mapy / bigSquareSize);
bigTexSize = (SQUARE_SIZE * bigSquareSize);
tileMapSizeX = (header.mapx / tileScale);
tileMapSizeY = (header.mapy / tileScale);
tileCount = (header.mapx * header.mapy) / (tileScale * tileScale);
mapSizeX = (header.mapx * SQUARE_SIZE);
mapSizeZ = (header.mapy * SQUARE_SIZE);
maxHeightMapIdx = ((header.mapx + 1) * (header.mapy + 1)) - 1;
heightMapSizeX = (header.mapx + 1);
cornerHeightMapSynced.resize((width + 1) * (height + 1));
#ifdef USE_UNSYNCED_HEIGHTMAP
cornerHeightMapUnsynced.resize((width + 1) * (height + 1));
#endif
groundDrawer = NULL;
const float minH = smf.minHeightOverride ? smf.minHeight : header.minHeight;
const float maxH = smf.maxHeightOverride ? smf.maxHeight : header.maxHeight;
file.ReadHeightmap(&cornerHeightMapSynced[0], minH, (maxH - minH) / 65536.0f);
CReadMap::Initialize();
shadingTexPixelRow.resize(gs->mapxp1 * 4, 0);
shadingTexUpdateIter = 0;
shadingTexUpdateRate = std::max(1.0f, math::ceil((width + 1) / float(height + 1)));
// with GLSL, the shading texture has very limited use (minimap etc) so we increase the update interval
if (globalRendering->haveGLSL)
shadingTexUpdateRate *= 10;
for (unsigned int a = 0; a < mapname.size(); ++a) {
mapChecksum += mapname[a];
mapChecksum *= mapname[a];
}
haveSpecularLighting = !(mapInfo->smf.specularTexName.empty());
haveSplatTexture = (!mapInfo->smf.splatDetailTexName.empty() && !mapInfo->smf.splatDistrTexName.empty());
CBitmap detailTexBM;
CBitmap grassShadingTexBM;
detailTex = 0;
shadingTex = 0;
normalsTex = 0;
minimapTex = 0;
specularTex = 0;
splatDetailTex = 0;
splatDistrTex = 0;
skyReflectModTex = 0;
detailNormalTex = 0;
lightEmissionTex = 0;
if (haveSpecularLighting) {
CBitmap specularTexBM;
CBitmap skyReflectModTexBM;
CBitmap detailNormalTexBM;
CBitmap lightEmissionTexBM;
if (!specularTexBM.Load(mapInfo->smf.specularTexName)) {
// maps wants specular lighting, but no moderation
specularTexBM.channels = 4;
specularTexBM.Alloc(1, 1);
specularTexBM.mem[0] = 255;
specularTexBM.mem[1] = 255;
specularTexBM.mem[2] = 255;
specularTexBM.mem[3] = 255;
}
specularTex = specularTexBM.CreateTexture(false);
if (haveSplatTexture) {
CBitmap splatDistrTexBM;
CBitmap splatDetailTexBM;
// if the map supplies an intensity- and a distribution-texture for
// detail-splat blending, the regular detail-texture is not used
//.........这里部分代码省略.........