Texture2d* Texture2d::load(std::string path) { arc<internal::PngData> image = internal::PngData::create(); path = path + ".png"; if(lodepng_decode32_file(&image->image, &image->width, &image->height, path.c_str()) != 0) { throw std::exception(); } Texture2d* texture = new Texture2d(image->width, image->height); if(texture->nativeTexture.get() == NULL) { texture->nativeTexture = gl::Uint::genTexture(); } int sampleWidth = image->width; int sampleHeight = image->height; sampleWidth = poweroftwo(image->width); sampleHeight = poweroftwo(image->height); std::cout << sampleWidth << " " << sampleHeight << std::endl; std::vector<GLbyte> imageBytes(sampleHeight * sampleWidth * 4); double scaleWidth = (double)sampleWidth / (double)image->width; double scaleHeight = (double)sampleHeight / (double)image->height; for(int cy = 0; cy < sampleHeight; cy++) { for(int cx = 0; cx < sampleWidth; cx++) { int pixel = (cy * (sampleWidth * 4)) + (cx * 4); int nearestMatch = (((int)(cy / scaleHeight) * (image->width * 4)) + ((int)(cx / scaleWidth) * 4) ); imageBytes[pixel ] = image->image[nearestMatch ]; imageBytes[pixel + 1] = image->image[nearestMatch + 1]; imageBytes[pixel + 2] = image->image[nearestMatch + 2]; imageBytes[pixel + 3] = image->image[nearestMatch + 3]; } } glBindTexture(GL_TEXTURE_2D, texture->nativeTexture->getGLuint()); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sampleWidth, sampleHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, &imageBytes[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); //glGenerateMipmap(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); return texture; }
int main() { int tl,x; printf("Enter\n"); scanf("%d",&tl); x=poweroftwo(tl); if(x==1) printf("YES\n"); else{ printf("0\n"); } }
/* if a number is power of 2 then most significant bit is 1 remain are 0 x=4 100 y=5 101 x-1=3 011 y-1=4 100 x&(x-1)=0 000 y&(y-1)=4 100 */ int main() { int a; do { scanf("%d",&a); if(poweroftwo(a)==0) printf("YES\n"); else printf("NO\n"); }while(a!=-1); return 0; }
MP_API void * __mp_alloc(size_t l, size_t a, alloctype f, char *s, char *t, unsigned long u, char *g, size_t h, size_t k) { void *p; size_t n; checkalloca(&l); if (l == 0) l = 1; switch (f) { case AT_MALLOC: p = malloc(l); break; case AT_CALLOC: if ((p = malloc(l)) != NULL) memset(p, 0, l); break; case AT_MEMALIGN: case AT_VALLOC: case AT_PVALLOC: /* We cannot rely on any system having implementations of memalign(), * valloc() or pvalloc() and so we must either implement them with * malloc() or with memalign() if it exists. For the former * implementation, this is done by allocating extra space and then * rounding up the start address of the new allocation to the specified * alignment. This means that there is likely to be some space wasted * for each allocation and the memory allocated by such functions * cannot be freed with free(). The latter point is also likely to be * true even if we allocated the memory with memalign(). */ n = pagesize(); if (f == AT_PVALLOC) l = ((l - 1) & ~(n - 1)) + n; if ((f == AT_VALLOC) || (f == AT_PVALLOC) || (a > n)) a = n; else if (a < sizeof(long)) a = sizeof(long); else a = poweroftwo(a); #if MP_MEMALIGN_SUPPORT p = memalign(a, l); #else /* MP_MEMALIGN_SUPPORT */ if (p = malloc(l + a - 1)) p = (void *) ((((unsigned long) p - 1) & ~(a - 1)) + a); #endif /* MP_MEMALIGN_SUPPORT */ break; case AT_ALLOCA: p = __mp_xmalloc(l + sizeof(allocaheader), s, t, u, g, h); ((allocaheader *) p)->data.next = allocastack; ((allocaheader *) p)->data.frame = (void *) &l; allocastack = (allocaheader *) p; p = (char *) p + sizeof(allocaheader); break; case AT_XMALLOC: p = __mp_xmalloc(l, s, t, u, g, h); break; case AT_XCALLOC: p = __mp_xcalloc(l, s, t, u, g, h); break; case AT_NEW: case AT_NEWVEC: /* This implementation should really call the new handler if it * has been installed, but for now just abort if no memory can be * allocated. */ p = __mp_xmalloc(l, s, t, u, g, h); break; default: illegalfunction("__mp_alloc", s, t, u); break; } return p; }
//-------------------------------------------------------------- void testApp::setup(){ cout << "4 x 4 = " << poweroftwo(4) << endl; }