void Codigo::Dibuja(){ static bitmap imagen("cpp.bmp"); static GLUquadricObj *mon1 = gluNewQuadric(); glPushMatrix(); glDisable(GL_LIGHTING); glColor3ub(255, 255, 255); imagen.usarTextura(); glTranslatef(posicion.x, posicion.y, posicion.z); Anima(); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(0.6, -0.6, -0.5); glTexCoord2f(0.0, 1.0); glVertex3f(-0.6, -0.6, 0.5); glTexCoord2f(1.0, 1.0); glVertex3f(-0.6, 0.6, 0.5); glTexCoord2f(1.0, 0.0); glVertex3f(0.6, 0.6, -0.5); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); glPopMatrix(); }
// NOLINTNEXTLINE(runtime/references) void construct_bitmap_with_erasure(bitmap &bits) { construct_bitmap(bits); EXPECT_FALSE(bits.erase(5)); // 1 0 0 1 1 1 0 0 1 1 0 EXPECT_TRUE(bits.erase(0)); // 0 0 1 1 1 0 0 1 1 0 EXPECT_FALSE(bits.erase(6)); // 0 0 1 1 1 0 1 1 0 EXPECT_FALSE(bits.erase(5)); // 0 0 1 1 1 1 1 0 EXPECT_TRUE(bits.erase(3)); // 0 0 1 1 1 1 0 EXPECT_FALSE(bits.erase(6)); // 0 0 1 1 1 1 }
bitmap< T > module< T >::apply_raster(bitmap< T > const& image)const{ bitmap< T > result( (image.width() - 1) / param.raster + 1, (image.height() - 1) / param.raster + 1 ); for(std::size_t y = 0; y < result.height(); ++y){ for(std::size_t x = 0; x < result.width(); ++x){ result(x, y) = image(x * param.raster, y * param.raster); } } return result; }
void addbitmap(const bitmap& bmp) { size_t id = bmp.id(); if (available(id)) return; glGenTextures(1, &bitmaps[id]); glBindTexture(GL_TEXTURE_2D, bitmaps[id]); glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, bmp.width(), bmp.height(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, bmp.data()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); }
BitmapWrapperD2D::BitmapWrapperD2D(bitmap bmp) { IWICBitmap* wic = 0; Graphics::locator.getfactory()->CreateBitmapFromMemory( bmp.width(), bmp.height(), GUID_WICPixelFormat32bppBGRA, 4 * bmp.width(), bmp.length(), (BYTE*)bmp.data(), &wic); if (wic != 0) { IWICFormatConverter* converter = nullptr; IWICBitmap* temp = nullptr; int result = Graphics::locator.getfactory()->CreateFormatConverter(&converter); if (result == 0) { converter->Initialize(wic, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, 0, 0.f, WICBitmapPaletteTypeMedianCut); Graphics::locator.getfactory()->CreateBitmapFromSource(converter, WICBitmapNoCache, &temp); converter->Release(); } wic->Release(); ID2D1BitmapRenderTarget* target = Graphics::locator.gettarget(); if (target) { target->CreateBitmapFromWicBitmap(temp, &source); temp->Release(); temp = nullptr; } else { source = nullptr; } } else { source = nullptr; } }
graph(word_t maxedges, word_t maxnodes, u32 maxsols, char *bytes) : visited(2*maxnodes) { MAXEDGES = maxedges; MAXNODES = maxnodes; MAXSOLS = maxsols; adjlist = new (bytes) word_t[2*MAXNODES]; // index into links array links = new (bytes += sizeof(word_t[2*MAXNODES])) link[2*MAXEDGES]; compressu = compressv = 0; sharedmem = true; sols = new proof[MAXSOLS]; visited.clear(); }
graph(word_t maxedges, word_t maxnodes, u32 maxsols) : visited(2*maxnodes) { MAXEDGES = maxedges; MAXNODES = maxnodes; MAXSOLS = maxsols; adjlist = new word_t[2*MAXNODES]; // index into links array links = new link[2*MAXEDGES]; compressu = compressv = 0; sharedmem = false; sols = new proof[MAXSOLS+1]; // extra one for current path visited.clear(); }
graph(word_t maxedges, word_t maxnodes, u32 maxsols, u32 compressbits) : visited(2*maxnodes) { MAXEDGES = maxedges; MAXNODES = maxnodes; MAXSOLS = maxsols; adjlist = new word_t[2*MAXNODES]; // index into links array links = new link[2*MAXEDGES]; compressu = new compressor<word_t>(EDGEBITS, compressbits); compressv = new compressor<word_t>(EDGEBITS, compressbits); sharedmem = false; sols = new proof[MAXSOLS]; visited.clear(); }
// NOLINTNEXTLINE(runtime/references) void construct_bitmap(bitmap &bits) { bits.insert(0, true); // [1] bits.insert(1, false); // 1 [0] bits.insert(0, false); // [0] 1 0 bits.insert(1, false); // 0 [0] 1 0 bits.insert(2, true); // 0 0 [1] 1 0 bits.insert(5, true); // 0 0 1 1 0 [1] bits.insert(3, false); // 0 0 1 [0] 1 0 1 bits.insert(6, false); // 0 0 1 0 1 0 [0] 1 bits.insert(3, true); // 0 0 1 [1] 0 1 0 0 1 bits.insert(9, true); // 0 0 1 1 0 1 0 0 1 [1] bits.insert(10, false); // 0 0 1 1 0 1 0 0 1 1 [0] bits.insert(0, true); // [1] 0 0 1 1 0 1 0 0 1 1 0 }
void cycles_with_link(u32 len, word_t u, word_t dest) { // printf("cycles_with_link(%d, %x, %x)\n", len, u, dest); if (visited.test(u)) return; if (u == dest) { print_log(" %d-cycle found\n", len); if (len == PROOFSIZE && nsols < MAXSOLS) { qsort(sols[nsols++], PROOFSIZE, sizeof(word_t), nonce_cmp); memcpy(sols[nsols], sols[nsols-1], sizeof(sols[0])); } return; } if (len == PROOFSIZE) return; word_t au1 = adjlist[u]; if (au1 != NIL) { visited.set(u); for (; au1 != NIL; au1 = links[au1].next) { sols[nsols][len] = au1/2; cycles_with_link(len+1, links[au1 ^ 1].to, dest); } visited.reset(u); } }
void add_edge(word_t u, word_t v) { assert(u < MAXNODES); assert(v < MAXNODES); v += MAXNODES; // distinguish partitions if (adjlist[u] != NIL && adjlist[v] != NIL) { // possibly part of a cycle sols[nsols][0] = nlinks/2; assert(!visited.test(u)); cycles_with_link(1, u, v); } word_t ulink = nlinks++; word_t vlink = nlinks++; // the two halfedges of an edge differ only in last bit assert(vlink != NIL); // avoid confusing links with NIL; guaranteed if bits in word_t > EDGEBITS + 1 links[ulink].next = adjlist[u]; links[vlink].next = adjlist[v]; links[adjlist[u] = ulink].to = u; links[adjlist[v] = vlink].to = v; }
GRESULT gsys::LoadTIFF(gsys::gfile *file,bitmap & clarr,int Options,int* pOptionsQuery) { TIFF* tif = TIFFClientOpen("","r",reinterpret_cast<thandle_t>(file), _tiff_read, _tiff_read, _tiff_seek, _tiff_close, _tiff_size, _tiff_map, _tiff_unmap); if(!tif) return GERR_INVALID_DATA; uint32 w, h; size_t npixels; uint32* raster; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h); npixels = w * h; raster = (uint32*) _TIFFmalloc((tsize_t)(npixels * sizeof (uint32))); if (raster != NULL) { if (TIFFReadRGBAImage(tif, w, h, raster, 0)) { //gsys::array2d<gsys::dwcolor> clarr(w,h); clarr.init(w,h); for(uint i=0;i<npixels;i++) { dwcolor cl; uint32 ucl = raster[i]; clarr(i) = dwcolor( (gbyte)TIFFGetR(ucl), (gbyte)TIFFGetG(ucl), (gbyte)TIFFGetB(ucl), (gbyte)TIFFGetA(ucl)); } } _TIFFfree(raster); } TIFFClose(tif); GTransformImage(clarr,ImagePremultipliedAlpha,Options,pOptionsQuery); return G_OK; }
pair<imgcontext, size_t> imagecache::createimage(bitmap bmp) { size_t id = bmp.id(); if (temp[imgcon][id] || cache[imgcon][id]) { return make_pair(imgcon, id); } else { IWICBitmap* wic = 0; imgfactory->CreateBitmapFromMemory( bmp.width(), bmp.height(), GUID_WICPixelFormat32bppBGRA, 4 * bmp.width(), bmp.length(), (BYTE*)bmp.data(), &wic); if (wic) { IWICFormatConverter* spConverter = 0; int result = imgfactory->CreateFormatConverter(&spConverter); if (result == 0) { spConverter->Initialize(wic, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeMedianCut); imgfactory->CreateBitmapFromSource(spConverter, WICBitmapNoCache, &temp[imgcon][id]); spConverter->Release(); } wic->Release(); } } return make_pair(imgcon, id); }
void generator::save_image(const bitmap& bm) { FILE* fp = fopen(string(font_name_ + ".png").c_str(), "wb"); if(!fp) { throw runtime_error("Can't open png output file."); } png_structp png_ptr = NULL; png_infop info_ptr = NULL; png_byte ** row_pointers = NULL; int status = -1; int pixel_size = 4; int depth = 8; png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (png_ptr == NULL) { throw runtime_error("Can't open png output structure."); } info_ptr = png_create_info_struct (png_ptr); if (info_ptr == NULL) { throw runtime_error("Can't create png info struct."); } png_set_IHDR (png_ptr, info_ptr, bm.get_width(), bm.get_height(), depth, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); row_pointers = static_cast<png_byte**>(png_malloc (png_ptr, bm.get_height() * sizeof (png_byte *))); for (uint32_t y = 0; y < bm.get_height(); ++y) { png_byte *row = static_cast<png_byte*>(png_malloc (png_ptr, sizeof (uint8_t) * bm.get_width() * pixel_size)); row_pointers[y] = row; for (uint32_t x = 0; x < bm.get_width(); ++x) { pixel p = bm.get_pixel(x, y); *row++ = p.red; *row++ = p.green; *row++ = p.blue; *row++ = p.alpha; } } png_init_io (png_ptr, fp); png_set_rows (png_ptr, info_ptr, row_pointers); png_write_png (png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); status = 0; for (size_t y = 0; y < bm.get_height(); y++) { png_free (png_ptr, row_pointers[y]); } png_free (png_ptr, row_pointers); png_destroy_write_struct (&png_ptr, &info_ptr); fclose (fp); }