int KeyModifiers::getState(int modifiers, bool reset) { int state = getState(); int mask; mask = getMask("Shift"); if(modifiers & Qt::ShiftButton){ state |= mask; } else { if(reset){ state &= ~mask; } } mask = getMask("Control"); if(modifiers & Qt::ControlButton){ state |= mask; } else { if(reset){ state &= ~mask; } } mask = getMask("Alt"); if(modifiers & Qt::AltButton){ state |= mask; } else { if(reset){ state &= ~mask; } } return(state); }
void* s_request_memory_block() { int i; for (i = 0; i < NUM_BLOCKS; i++) { if ((free_memory & getMask(i)) != 0x00000000) { free_memory ^= getMask(i);// Set the i-th bit to 0 return (void*)(heap + BLOCK_SIZE * i); } } return (void*)NULL; //nothing available }
int KeyModifiers::getModifiers(int modifiers) { int state = getState(); if(state & getMask("Shift")){ modifiers |= Qt::ShiftButton; } if(state & getMask("Control")){ modifiers |= Qt::ControlButton; } if(state & getMask("Alt")){ modifiers |= Qt::AltButton; } return(modifiers); }
bool PortVideoSDL::setupWindow() { if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { printf("SDL could not be initialized: %s\n", SDL_GetError()); return false; } window_ = SDL_SetVideoMode(width_, height_, 32, SDL_HWSURFACE); if ( window_ == NULL ) { printf("Could not open window: %s\n", SDL_GetError()); SDL_Quit(); return false; } iconImage_ = getIcon(); #ifndef __APPLE__ SDL_WM_SetIcon(iconImage_, getMask()); #endif FontTool::init(); SDL_EnableKeyRepeat(200, 10); SDL_WM_SetCaption(app_name_.c_str(), NULL); return true; }
void IPV4Cidr::set(const char *cp) { char cbuf[INET_IPV4_ADDRESS_SIZE]; char *ep; unsigned dots = 0; #ifdef _MSWINDOWS_ DWORD addr; #endif memset(&netmask, 0, sizeof(netmask)); bitset((bit_t *)&netmask, getMask(cp)); setString(cbuf, sizeof(cbuf), cp); ep = (char *)strchr(cp, '/'); if(ep) *ep = 0; cp = cbuf; while(NULL != (cp = strchr(cp, '.'))) { ++dots; ++cp; } while(dots++ < 3) addString(cbuf, sizeof(cbuf), ".0"); #ifdef _MSWINDOWS_ addr = inet_addr(cbuf); memcpy(&network, &addr, sizeof(network)); #else inet_aton(cbuf, &network); #endif bitmask((bit_t *)&network, (bit_t *)&netmask, sizeof(network)); }
int main(void) { unsigned char c; int n; printf("Keyboard Test:\n"); printf("initializing interrupts...\n"); initInterrupts(); printf("setting kbd ISR...\n"); setISR(4, kbdISR); printf("enabling kbd interrupt mask bit...\n"); setMask(getMask() | (1 << 4)); printf("enabling interrupts in kbd controller...\n"); kbdEnable(); n = 0; while (1) { while (charAvail == 0) ; disable(); c = charRead; charAvail = 0; enable(); printf("%02X ", c); if (++n == 24) { n = 0; printf("\n"); } } return 0; }
void Document::generateMaskBoundaries(Mask* mask) { if (m_bound.seg) { base_free(m_bound.seg); m_bound.seg = NULL; m_bound.nseg = 0; } // No mask specified? Use the current one in the document if (!mask) { if (!isMaskVisible()) // The mask is hidden return; // Done, without boundaries else mask = getMask(); // Use the document mask } ASSERT(mask != NULL); if (!mask->isEmpty()) { m_bound.seg = find_mask_boundary(mask->getBitmap(), &m_bound.nseg, IgnoreBounds, 0, 0, 0, 0); for (int c=0; c<m_bound.nseg; c++) { m_bound.seg[c].x1 += mask->getBounds().x; m_bound.seg[c].y1 += mask->getBounds().y; m_bound.seg[c].x2 += mask->getBounds().x; m_bound.seg[c].y2 += mask->getBounds().y; } } }
/* * Initialize the disk driver. * Read the partition table. */ static void ideInitialize(void) { unsigned int totalSectors; /* determine disk size */ waitDiskReady(); totalSectors = *DISK_CAP; if (totalSectors == 0) { panic("IDE disk not found"); } /* read partition table */ readPartitionTable(); if (debugIdeDisk) { printf("IDE disk has %d (0x%X) sectors\n", totalSectors, totalSectors); showPartitionTable(); } /* disk queue is empty */ ideTab.b_actf = NULL; ideTab.b_actl = NULL; /* no disk operation in progress, no errors */ ideTab.b_active = 0; ideTab.b_errcnt = 0; /* set ISR and enable interrupts */ setISR(DISK_IRQ, ideISR); setMask(getMask() | (1 << DISK_IRQ)); /* the disk is now initialized */ ideInitialized = TRUE; }
static int hop_addEvent(lua_State *L) { snHopLoop *hloop = checkLoop(L); int fd = luaL_checknumber(L, 2); const char *chFilter = luaL_checkstring(L, 3); if (! lua_isfunction(L, 4)) return luaL_error(L, "Function was expected."); if (fd > SN_SETSIZE) { return luaL_error(L, "File descriptor outside SN_SETSIZE"); } int mask = getMask(chFilter); if (mask == -1) return luaL_error(L, "Invalid event mask."); if (hloop->api->addEvent(hloop, fd, mask) == -1) { return luaL_error(L, "Could not add event listener."); } int clbref = luaL_ref(L, LUA_ENVIRONINDEX); hloop->events[fd].L = L; hloop->events[fd].mask |= mask; if (mask & SN_READABLE) hloop->events[fd].rcallback = clbref; if (mask & SN_WRITABLE) hloop->events[fd].wcallback = clbref; return 0; }
terrama2::core::DataSetSeries terrama2::core::DataAccessorDcpToa5::getSeries(const std::string& uri, const terrama2::core::Filter& filter, terrama2::core::DataSetPtr dataSet) const { std::string mask = getMask(dataSet); std::string folder = getFolder(dataSet); QTemporaryDir tempBaseDir; if(!tempBaseDir.isValid()) { QString errMsg = QObject::tr("Can't create temporary folder."); TERRAMA2_LOG_ERROR() << errMsg; throw DataAccessException() << ErrorDescription(errMsg); } QDir tempDir(tempBaseDir.path()); tempDir.mkdir(QString::fromStdString(folder)); tempDir.cd(QString::fromStdString(folder)); QUrl url((uri+"/"+folder+"/"+mask).c_str()); QFileInfo originalInfo(url.path()); QFile file(url.path()); QFile tempFile(tempDir.path()+"/"+originalInfo.fileName()); if(!file.open(QIODevice::ReadOnly)) { QString errMsg = QObject::tr("Can't open file: dataset %1.").arg(dataSet->id); TERRAMA2_LOG_ERROR() << errMsg; throw DataAccessException() << ErrorDescription(errMsg); } if(!tempFile.open(QIODevice::ReadWrite)) { QString errMsg = QObject::tr("Can't open temporary file: dataset %1.").arg(dataSet->id); TERRAMA2_LOG_ERROR() << errMsg; throw DataAccessException() << ErrorDescription(errMsg); } file.readLine();//ignore first line tempFile.write(file.readLine()); //headers line //ignore third and fourth lines file.readLine(); file.readLine(); //read all file tempFile.write(file.readAll()); //headers line //update file path std::string tempUri = "file://"+tempBaseDir.path().toStdString(); file.close(); tempFile.close(); auto dataSeries = terrama2::core::DataAccessorFile::getSeries(tempUri, filter, dataSet); return dataSeries; }
int main() { int n; char group[3]; std::vector<uint16_t> cards; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", &group); uint16_t card = 0; card = setMask(card, getMask(group[0])); card = setMask(card, getMask(group[1])); cards.push_back(card); } printf("%d\n", solve_442a(cards)); return 0; }
static uint64_t getValue(const ir::PTXOperand& operand) { uint64_t value = operand.imm_uint; uint64_t mask = getMask(operand); return value & mask; }
void terrama2::core::DataStoragerTiff::store(DataSetSeries series, DataSetPtr outputDataSet) const { if(!outputDataSet.get() || !series.syncDataSet.get()) { QString errMsg = QObject::tr("Mandatory parameters not provided."); TERRAMA2_LOG_ERROR() << errMsg; throw DataStoragerException() << ErrorDescription(errMsg); } QUrl uri(QString::fromStdString(dataProvider_->uri)); auto path = uri.path().toStdString(); try { std::string mask = getMask(outputDataSet); auto dataset = series.syncDataSet->dataset(); size_t rasterColumn = te::da::GetFirstPropertyPos(dataset.get(), te::dt::RASTER_TYPE); if(!isValidColumn(rasterColumn)) { QString errMsg = QObject::tr("No raster attribute."); TERRAMA2_LOG_ERROR() << errMsg; throw DataStoragerException() << ErrorDescription(errMsg); } size_t timestampColumn = te::da::GetFirstPropertyPos(dataset.get(), te::dt::DATETIME_TYPE); dataset->moveBeforeFirst(); while(dataset->moveNext()) { std::shared_ptr<te::rst::Raster> raster(dataset->isNull(rasterColumn) ? nullptr : dataset->getRaster(rasterColumn).release()); std::shared_ptr<te::dt::DateTime> timestamp; if(!isValidColumn(timestampColumn) || dataset->isNull(timestampColumn)) timestamp = nullptr; else timestamp.reset(dataset->getDateTime(timestampColumn).release()); if(!raster.get()) { QString errMsg = QObject::tr("Null raster found."); TERRAMA2_LOG_ERROR() << errMsg; continue; } std::string filename = replaceMask(mask, timestamp, outputDataSet); std::string output = path + "/" + filename; te::rp::Copy2DiskRaster(*raster, output); } } catch(const DataStoragerException&) { throw; } catch(...) { //TODO: fix DataStoragerTiff catch } }
static int hop_removeEvent(lua_State *L) { snHopLoop *hloop = checkLoop(L); int fd = luaL_checknumber(L, 2); const char *chFilter = luaL_checkstring(L, 3); int mask = getMask(chFilter); if (mask == -1) return luaL_error(L, "Invalid event mask."); return _removeEvent(L, fd, mask, hloop); }
PNM* BlurGaussian::transform() { emit message("Blurring..."); int size = getParameter("size").toInt(); radius = (size/2)+1; sigma = getParameter("sigma").toDouble(); return convolute(getMask(size, Normalize), RepeatEdge); }
void FillTool::fillInfluence(){ Mask const * mask = getMask(); float** influence = mask -> getInfluence(); int width = mask -> getWidth(); int height = mask -> getHeight(); for(int i = 0; i < width; i++){ for(int j = 0; j < height; j++){ influence[i][j] = 1.0; } } }
void Gui_DisplayBaseClass::redraw(){ DEV_INFOS("redrawing"); cv::Mat tmp_img; cv::Point2f offset; drawBackground(); if(!m_processor_hand.getSourceImgAsRGB(tmp_img)){ if(!m_banner_pixbuf) m_banner_pixbuf = Gui_PixbufOpener::pixbufOpen(BANNER_IMG); offset = m_ROI.scaleToFitAllocation(m_banner_pixbuf, m_pixbuf); } else{ m_banner_pixbuf.clear(); cv::Point2f raw_img_dim(tmp_img.cols,tmp_img.rows); m_ROI.update(raw_img_dim); tmp_img(m_ROI).copyTo(tmp_img); offset = m_ROI.scaleToFitAllocation(tmp_img, m_img_to_display); m_pixbuf = Gdk::Pixbuf::create_from_data((guint8*)m_img_to_display.data,Gdk::COLORSPACE_RGB,false, 8,m_img_to_display.cols,m_img_to_display.rows,m_img_to_display.step); //show mask if(getMask(tmp_img) && m_show_mask){ DEV_INFOS("drawing mask "<<cv::Point2f(tmp_img.rows,tmp_img.cols)<<" vs "<<raw_img_dim); tmp_img(m_ROI).copyTo(tmp_img); cv::LUT(tmp_img,m_LUT,tmp_img); m_ROI.scaleToFitAllocation(tmp_img, tmp_img,true); m_mask_pixbuf = Gdk::Pixbuf::create_from_data((guint8*)tmp_img.data,Gdk::COLORSPACE_RGB,false, 8,tmp_img.cols,tmp_img.rows,tmp_img.step); m_mask_pixbuf = m_mask_pixbuf->add_alpha(true,0,0,0); m_mask_pixbuf->composite ( m_pixbuf,0,0, m_mask_pixbuf->get_width(),m_mask_pixbuf->get_height(), 0,0,1,1,Gdk::INTERP_NEAREST, m_alph_mask//int overall_alpha ); } } m_pixbuf->render_to_drawable(get_window(), get_style()->get_black_gc(),0, 0, offset.x, offset.y, m_pixbuf->get_width(), m_pixbuf->get_height(),Gdk::RGB_DITHER_NONE, 0, 0); if(m_draw_result) m_deco.decorate(); }
/** * @param: address of a memory block * @return: 0 on success, non-zero otherwise */ int s_release_memory_block( void* addr) { int i = ((char*)addr - heap) / BLOCK_SIZE; int r = ((char*)addr - heap) % BLOCK_SIZE; if (i >= 0 && i < NUM_BLOCKS && r == 0) { free_memory |= getMask(i); // Set the i-th bit to 0 return 0; } // Cannot free something that is not on the heap. return -1; }
void IPV6Cidr::set(const char *cp) { char cbuf[INET_IPV6_ADDRESS_SIZE]; char *ep; memset(&netmask, 0, sizeof(netmask)); bitset((bit_t *)&netmask, getMask(cp)); setString(cbuf, sizeof(cbuf), cp); ep = (char *)strchr(cp, '/'); if(ep) *ep = 0; inet_pton(AF_INET6, cbuf, &network); bitmask((bit_t *)&network, (bit_t *)&netmask, sizeof(network)); }
///Apply to the entire buffer, the mask should be equivalent to the buffer void FillTool::applyInfluence(int x, int y, PixelBuffer* buffer){ Mask const * mask = getMask(); int height = mask -> getHeight(); int width = mask -> getWidth(); ColorData backgroundColor = buffer -> getBackgroundColor(); ColorData currentPixelColor; for(int i = 0; i < width; i++){ for(int j = 0; j < height; j++){ currentPixelColor = buffer -> getPixel(i,j); if(compareColorData(backgroundColor, currentPixelColor)) { buffer -> setPixel(i, j, *m_toolColor); } } } }
std::string terrama2::core::getFolderMask(DataSetPtr dataSet) { std::string mask = getMask(dataSet); std::string folderMask = ""; auto pos = mask.find_last_of("\\/"); if(pos != std::string::npos) { for(size_t i = 0; i < pos; ++i) folderMask +=mask.at(i); } return folderMask; }
void Model::setModel(ModelAsset * assets) { if (assets != nullptr && mesh == nullptr) { auto meshes = assets->getMeshes(); mesh = new GPU_Transfer(); mesh->setTextureCords(assets->getUvs()); mesh->setVertices(assets->getVertices()); mesh->setNormals(assets->getNormals()); mesh->setIndices(assets->getIndices()); mesh->send(); auto textures = assets->getTextures(); for (auto i = 0; i < textures.size(); i++) { const auto texture_asset = textures[i]; if (texture_asset != nullptr) { const auto texture = new GPU_Sampler(SINGLE_SAMPLER); texture->setTransferQuality(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR); texture->setBitmapWrapping(GL_REPEAT, GL_REPEAT); texture->setBitmapData(texture_asset->getPixels(), texture_asset->getWidth(), texture_asset->getHeight(), texture_asset->getBPP(), texture_asset->getMask() ); texture->send(); samplers.push_back(texture); } else { samplers.push_back(nullptr); } } file = assets; } }
void gkLogicController::link(gkLogicActuator* v) { UT_ASSERT(v && m_actuators.find(v) == UT_NPOS); m_actuators.push_back(v); v->setPriority(getPriority()); gkLogicLink* olink = v->getLink(); // append state bits m_object->setState(m_link->getState()); v->setMask(v->getMask() | getMask()); v->setDebugMask(getDebugMask()); olink->setState(m_link->getState()); m_link->notifyLink(olink); olink->notifyLink(m_link); }
std::string terrama2::core::getFileMask(DataSetPtr dataSet) { std::string mask = getMask(dataSet); std::string fileMask = ""; auto pos = mask.find_last_of("\\/"); if(pos != std::string::npos) { fileMask = mask.substr(pos+1); } else { fileMask = mask; } return fileMask; }
void SwakSetValue<T>::setValue ( fvMatrix<T>& eqn, const label fieldI ) { this->driver().clearVariables(); this->driver().parse(this->expressions_[fieldI]); if( !this->driver(). FieldValueExpressionDriver::resultIsTyp<typename SwakSetValue<T>::resultField>() ) { FatalErrorIn("SwakSetValue<"+word(pTraits<T>::typeName)+">::setValue()") << "Result of " << this->expressions_[fieldI] << " is not a " << pTraits<T>::typeName << endl << exit(FatalError); } typename SwakSetValue<T>::resultField result( this->driver(). FieldValueExpressionDriver::getResult<typename SwakSetValue<T>::resultField>() ); DynamicList<label> cellIDs; if(useMaskExpression_) { if(!getMask(cellIDs,eqn.psi().name())) { return; } } else { cellIDs=this->cells_; } List<T> values(cellIDs.size()); // UIndirectList<Type>(values, cells_) = injectionRate_[fieldI]; forAll(cellIDs,i) { label cellI=cellIDs[i]; values[i]=result[cellI]; }
cv::Mat filterMedian(cv::Mat& I) { CV_Assert(I.depth() != sizeof(uchar)); cv::Mat res(I.rows, I.cols, CV_8UC3); unsigned int N = 3; unsigned int R = N/2; cv::Mat_<cv::Vec3b> _I = I; cv::Mat_<cv::Vec3b> _R = res; for (unsigned int i = N / 2; i < I.rows - N / 2; i++) { for (unsigned int j = N / 2; j < I.cols - N / 2; j++) { auto mask = getMask(_I, i, j, N); std::sort(mask.begin(), mask.end(), [](const cv::Vec3b &p, const cv::Vec3b &r) { return gray(p) < gray(r); }); auto rank_pix = mask[R >= mask.size() ? mask.size() - 1 : R]; _R(i, j) = rank_pix; } } return res; }
/* ** This routine walks (recursively) an expression tree and generates ** a bitmask indicating which tables are used in that expression ** tree. ** ** In order for this routine to work, the calling function must have ** previously invoked sqliteExprResolveIds() on the expression. See ** the header comment on that routine for additional information. ** The sqliteExprResolveIds() routines looks for column names and ** sets their opcodes to TK_COLUMN and their Expr.iTable fields to ** the VDBE cursor number of the table. */ static int exprTableUsage(ExprMaskSet *pMaskSet, Expr *p) { unsigned int mask = 0; if( p==0 ) return 0; if( p->op==TK_COLUMN ) { return getMask(pMaskSet, p->iTable); } if( p->pRight ) { mask = exprTableUsage(pMaskSet, p->pRight); } if( p->pLeft ) { mask |= exprTableUsage(pMaskSet, p->pLeft); } if( p->pList ) { int i; for(i=0; i<p->pList->nExpr; i++) { mask |= exprTableUsage(pMaskSet, p->pList->a[i].pExpr); } } return mask; }
void IPV6Cidr::set(const char *cp) { char cbuf[INET_IPV6_ADDRESS_SIZE]; char *ep; memset(&netmask, 0, sizeof(netmask)); bitset((bit_t *)&netmask, getMask(cp)); setString(cbuf, sizeof(cbuf), cp); ep = (char *)strchr(cp, '/'); if(ep) *ep = 0; #ifdef _MSWINDOWS_ int slen = sizeof(network); WSAStringToAddressA(cbuf, AF_INET6, NULL, (struct sockaddr*)&network, &slen); #else inet_pton(AF_INET6, cbuf, &network); #endif bitmask((bit_t *)&network, (bit_t *)&netmask, sizeof(network)); }
void RayStreamLogger::logRay8Occluded(const void* valid_i, void* scene, RTCRay8& start, RTCRay8& end) { mutex.lock(); LogRay8 logRay8; logRay8.type = RAY_OCCLUDED; logRay8.m_valid = getMask((int*)valid_i,8); logRay8.numRays = numActive((int*)valid_i,8); /* ray8 before intersect */ logRay8.ray8 = start; ray8->write((char*)&logRay8 ,sizeof(logRay8)); /* ray8 after intersect */ logRay8.ray8 = end; ray8_verify->write((char*)&logRay8 ,sizeof(logRay8)); mutex.unlock(); }
void RayStreamLogger::logRay4Occluded(const void* valid_i, void* scene, RTCRay4& start, RTCRay4& end) { mutex.lock(); LogRay4 logRay4; logRay4.type = RAY_OCCLUDED; logRay4.m_valid = getMask((int*)valid_i,4); logRay4.numRays = numActive((int*)valid_i,4); /* ray4 before intersect */ logRay4.ray4 = start; ray4->write((char*)&logRay4 ,sizeof(logRay4)); /* ray4 after intersect */ logRay4.ray4 = end; ray4_verify->write((char*)&logRay4 ,sizeof(logRay4)); mutex.unlock(); }