// this returns the Layer [1-3] int CFrameHeader::getLayer() { // when speaking of layers there is a // cute coincidence, the Layer always // eauals 4 - layerIndex, so that's what // we will return return ( 4 - getLayerIndex() ); }
// This function is a supplement to the loadHeader // function, the only purpose is to detect if the // header loaded by loadHeader is a valid header // or just four different chars BOOL CFrameHeader::isValidHeader() { return ( ((getFrameSync() & 2047)==2047) && ((getVersionIndex() & 3)!= 1) && ((getLayerIndex() & 3)!= 0) && ((getBitrateIndex() & 15)!= 0) && // due to lack of support of the .mp3 format // no "public" .mp3's should contain information // like this anyway... :) ((getBitrateIndex() & 15)!= 15) && ((getFrequencyIndex() & 3)!= 3) && ((getEmphasisIndex() & 3)!= 2) ); }
// this returns the current bitrate [8-448 kbps] int CFrameHeader::getBitrate() { // a table to convert the indexes into // something informative... const int table[2][3][16] = { { //MPEG 2 & 2.5 {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,0}, //Layer III {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160,0}, //Layer II {0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0} //Layer I },{ //MPEG 1 {0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,0}, //Layer III {0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384,0}, //Layer II {0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448,0} //Layer I } }; // the bitrate is not only dependent of the bitrate index, // the bitrate also varies with the MPEG version and Layer version return table[(getVersionIndex() & 1)][(getLayerIndex() -1)][getBitrateIndex()]; }
void Brush::applyLayerBrush(long int x, long int y, const Ogre::Vector3& position) { auto ter = m_group->getTerrain(x, y); if(!ter) return; auto indices = (position - ter->getPosition())/ter->getWorldSize(); indices += 0.5; auto cmd = dynamic_cast<undo::BlendmapEdit*>(m_currentCommand); assert(cmd != nullptr); cmd->monitorTerrain(x, y); size_t size = ter->getLayerBlendMapSize(); indices *= size; float brushSize = m_settings[m_mode].size/ter->getWorldSize() * size; float strength = m_settings[m_mode].strength * ((QApplication::queryKeyboardModifiers() & Qt::ShiftModifier)? -0.01f : 0.01f); auto layer = ter->getLayerBlendMap(cmd->getLayerIndex()); auto data = layer->getBlendPointer(); Ogre::Rect rect(Ogre::Math::Clamp<int>(indices.x-brushSize/2, 0, size), Ogre::Math::Clamp<int>(indices.z-brushSize/2, 0, size), Ogre::Math::Clamp<int>(indices.x+brushSize/2, 0, size), Ogre::Math::Clamp<int>(indices.z+brushSize/2, 0, size)); if(rect.bottom == rect.top || rect.left == rect.right) // brush does not reach this terrain return; for(int ix=rect.left; ix<rect.right; ix++) { for(int iy=rect.top; iy<rect.bottom; iy++) { float dist = std::sqrt(std::pow(ix-indices.x, 2) + std::pow(iy-indices.z, 2)); float distWeight = brushFunction(dist/brushSize*2, m_settings[m_mode].hardness); // std::cout << dist << " " << brushSize/2 << " " << distWeight << std::endl; data[iy*size+ix] += distWeight*strength; // data[iy*size+ix] -= 0.1; if(data[iy*size+ix] > 1.0) data[iy*size+ix] = 1.0; if(data[iy*size+ix] < 0.0) data[iy*size+ix] = 0.0; // std::cout << data[iy*size+ix] << " "; } } layer->dirtyRect(rect); layer->update(); }
shared_ptr<Patch> CachingPyramidFeatureExtractor::extract(int x, int y, int width, int height) const { int layerIndex = getLayerIndex(width, height); int index = layerIndex - firstCacheIndex; if (index < 0 || static_cast<unsigned int>(index) >= cache.size()) return shared_ptr<Patch>(); CacheLayer& layer = cache[index]; Size patchSize = getPatchSize(); int layerX = layer.getScaled(x - width / 2) + patchSize.width / 2; int layerY = layer.getScaled(y - height / 2) + patchSize.height / 2; switch (strategy) { case Strategy::SHARING: return extractSharing(layer, layerX, layerY); case Strategy::COPYING: return extractCopying(layer, layerX, layerY); case Strategy::INPUT_COPYING: return extractInputCopying(layer, layerX, layerY); case Strategy::OUTPUT_COPYING: return extractOutputCopying(layer, layerX, layerY); default: // should never be reached return extractor->extract(layerIndex, layerX, layerY); } }