void Sound::replyFinished(QNetworkReply* reply) { // replace our byte array with the downloaded data QByteArray rawAudioByteArray = reply->readAll(); // foreach(QByteArray b, reply->rawHeaderList()) // qDebug() << b.constData() << ": " << reply->rawHeader(b).constData(); if (reply->hasRawHeader("Content-Type")) { QByteArray headerContentType = reply->rawHeader("Content-Type"); // WAV audio file encountered if (headerContentType == "audio/x-wav" || headerContentType == "audio/wav" || headerContentType == "audio/wave") { QByteArray outputAudioByteArray; interpretAsWav(rawAudioByteArray, outputAudioByteArray); downSample(outputAudioByteArray); } else { // Process as RAW file downSample(rawAudioByteArray); } } else { qDebug() << "Network reply without 'Content-Type'."; } }
void Sound::downloadFinished(const QByteArray& data) { // replace our byte array with the downloaded data QByteArray rawAudioByteArray = QByteArray(data); QString fileName = getURL().fileName().toLower(); static const QString WAV_EXTENSION = ".wav"; static const QString RAW_EXTENSION = ".raw"; if (fileName.endsWith(WAV_EXTENSION)) { QByteArray outputAudioByteArray; interpretAsWav(rawAudioByteArray, outputAudioByteArray); downSample(outputAudioByteArray); } else if (fileName.endsWith(RAW_EXTENSION)) { // check if this was a stereo raw file // since it's raw the only way for us to know that is if the file was called .stereo.raw if (fileName.toLower().endsWith("stereo.raw")) { _isStereo = true; qCDebug(audio) << "Processing sound of" << rawAudioByteArray.size() << "bytes from" << getURL() << "as stereo audio file."; } // Process as RAW file downSample(rawAudioByteArray); } else { qCDebug(audio) << "Unknown sound file type"; } finishedLoading(true); _isReady = true; emit ready(); }
void BloomEffect::apply(const sf::RenderTexture& input, sf::RenderTarget& output){ prepareTexture(input.getSize()); filterBright(input, mBrightnessTexture); downSample(mBrightnessTexture, mFirstPassTextures[0]); blurMultipass(mFirstPassTextures); downSample(mFirstPassTextures[0], mSecondPassTextures[0]); blurMultipass(mSecondPassTextures); add(mFirstPassTextures[0], mSecondPassTextures[0], mFirstPassTextures[1]); mFirstPassTextures[1].display(); add(input, mFirstPassTextures[1], output); }
/*! * \brief sub-sample a mono image by a certain factor * \param img mono image data (one byte per pixel) * \param img_width width of the image * \param img_height height of the image * \param bytes_per_pixel number of bytes per pixel * \param buffer temporary buffer used for downsampling * \param factor downsampling factor * \param result downsampled result */ void processimage::downSample( unsigned char* img, int img_width, int img_height, int bytes_per_pixel, int factor, int *buffer0, int *buffer1, unsigned char *result) { if (factor <= 2) { if (factor == 2) { // do a single downsample (half original image size) downSample(img, img_width, img_height, bytes_per_pixel, result); } } else { // do multiple downsamples // note here that we sum pixels and then divide at // the end for greater accuracy int pixels = img_width * img_height; int *img2 = buffer0; //new int[pixels]; for (int i = pixels - 1; i >= 0; i--) img2[i] = img[i]; int target_img_width = img_width / factor; int* img3 = buffer1; int *temp_img = NULL; int grouped_pixels = 2; while (img_width > target_img_width) { if (temp_img != NULL) delete[] temp_img; //img3 = buffer1; //new int[(img_width/2)*(img_height/2)]; downSampleSum(img2, img_width, img_height, bytes_per_pixel, img3); img_width /= 2; img_height /= 2; temp_img = img2; img2 = img3; img3 = temp_img; grouped_pixels *= grouped_pixels; } // divide the summed pixel values float divisor = 1.0f / grouped_pixels; for (int i = (img_width * img_height) - 1; i >= 0; i--) result[i] = (unsigned char)((float)img2[i] * divisor); //if (temp_img != NULL) // delete[] temp_img; //else // delete[] img2; //if (img3 != NULL) delete[] img3; } }
//public void PostBloom::apply(const sf::RenderTexture& src, sf::RenderTarget& dest) { initTextures(src.getSize()); filterBright(src, m_brightnessTexture); downSample(m_brightnessTexture, m_firstPassTextures[0]); blurMultipass(m_firstPassTextures); downSample(m_firstPassTextures[0], m_secondPassTextures[0]); blurMultipass(m_secondPassTextures); add(m_firstPassTextures[0], m_secondPassTextures[0], m_firstPassTextures[1]); m_firstPassTextures[1].display(); add(src, m_firstPassTextures[1], dest); }
void SoundProcessor::run() { qCDebug(audio) << "Processing sound file" << _url.toDisplayString(); // replace our byte array with the downloaded data QByteArray rawAudioByteArray = QByteArray(_data); QString fileName = _url.fileName().toLower(); static const QString WAV_EXTENSION = ".wav"; static const QString RAW_EXTENSION = ".raw"; if (fileName.endsWith(WAV_EXTENSION)) { QByteArray outputAudioByteArray; int sampleRate = interpretAsWav(rawAudioByteArray, outputAudioByteArray); if (sampleRate == 0) { qCDebug(audio) << "Unsupported WAV file type"; emit onError(300, "Failed to load sound file, reason: unsupported WAV file type"); return; } downSample(outputAudioByteArray, sampleRate); } else if (fileName.endsWith(RAW_EXTENSION)) { // check if this was a stereo raw file // since it's raw the only way for us to know that is if the file was called .stereo.raw if (fileName.toLower().endsWith("stereo.raw")) { _isStereo = true; qCDebug(audio) << "Processing sound of" << rawAudioByteArray.size() << "bytes from" << _url << "as stereo audio file."; } // Process as 48khz RAW file downSample(rawAudioByteArray, 48000); } else { qCDebug(audio) << "Unknown sound file type"; emit onError(300, "Failed to load sound file, reason: unknown sound file type"); return; } emit onSuccess(_data, _isStereo, _isAmbisonic, _duration); }
void Sound::downloadFinished(QNetworkReply* reply) { // replace our byte array with the downloaded data QByteArray rawAudioByteArray = reply->readAll(); if (reply->hasRawHeader("Content-Type")) { QByteArray headerContentType = reply->rawHeader("Content-Type"); // WAV audio file encountered if (headerContentType == "audio/x-wav" || headerContentType == "audio/wav" || headerContentType == "audio/wave") { QByteArray outputAudioByteArray; interpretAsWav(rawAudioByteArray, outputAudioByteArray); downSample(outputAudioByteArray); } else { // check if this was a stereo raw file // since it's raw the only way for us to know that is if the file was called .stereo.raw if (reply->url().fileName().toLower().endsWith("stereo.raw")) { _isStereo = true; qCDebug(audio) << "Processing sound of" << rawAudioByteArray.size() << "bytes from" << reply->url() << "as stereo audio file."; } // Process as RAW file downSample(rawAudioByteArray); } trimFrames(); } else { qCDebug(audio) << "Network reply without 'Content-Type'."; } _isReady = true; reply->deleteLater(); }
void kpoAnalyzerThread::operator ()() { std::cout << "cloud has " << scene_cloud_->size() << " points" << std::endl; Cloud cleanCloud; removeNoise(scene_cloud_, cleanCloud); pcl::copyPointCloud(cleanCloud, *scene_cloud_); std::cout << "filtered cloud has " << scene_cloud_->size() << " points" << std::endl; /* if (scene_cloud_->size() < 25) { std::cout << "cloud too small" << std::endl; return; } /* if (scene_cloud_->size() > 40000) { std::cout << "cloud too large" << std::endl; return; } */ NormalCloud::Ptr scene_normals_(new NormalCloud()); estimateNormals(scene_cloud_, scene_normals_); Cloud::Ptr scene_keypoints_(new Cloud()); downSample(scene_cloud_, scene_keypoints_); DescriptorCloud::Ptr scene_descriptors_(new DescriptorCloud()); computeShotDescriptors(scene_cloud_, scene_keypoints_, scene_normals_, scene_descriptors_); RFCloud::Ptr scene_refs_(new RFCloud()); estimateReferenceFrames(scene_cloud_, scene_normals_, scene_keypoints_, scene_refs_); kpoCloudDescription od; od.cloud = *scene_cloud_; od.keypoints = *scene_keypoints_; od.normals = *scene_normals_; od.descriptors = *scene_descriptors_; od.reference_frames = *scene_refs_; od.filename = filename; od.object_id = object_id; callback_(od); }
void CDVDongleThread::processEncode() { wxFloat32 audioIn[DSTAR_RADIO_BLOCK_SIZE]; ::memset(audioIn, 0x00, DSTAR_RADIO_BLOCK_SIZE * sizeof(wxFloat32)); m_encodeAudio.getData(audioIn, DSTAR_RADIO_BLOCK_SIZE); wxFloat32 audioOut[DSTAR_AUDIO_BLOCK_SIZE]; downSample(audioIn, audioOut); // Convert the audio into AMBE data m_dongle->encodeIn(audioOut, DSTAR_AUDIO_BLOCK_SIZE); unsigned char ambe[VOICE_FRAME_LENGTH_BYTES]; bool res = m_dongle->encodeOut(ambe, VOICE_FRAME_LENGTH_BYTES); if (!res) wxLogError(wxT("An error occurred in encodeOut")); m_encodeCallback->encodeCallback(ambe, VOICE_FRAME_LENGTH_BYTES, PS_NONE); }
int xDistanceFontGenerator::gen(wchar_t _char , FILE* file , int Offset , xDFFCharDesc& desc) { FT_Face pFT_Face = (FT_Face)m_FT_Face; FT_Int32 load_flags = FT_LOAD_RENDER|FT_LOAD_FORCE_AUTOHINT ; bool bAntilias = true; if(bAntilias) load_flags |= ( FT_LOAD_TARGET_NORMAL| FT_LOAD_TARGET_LIGHT); else load_flags |= ( FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO ); //得到字模 FT_UInt glyph_index; /* retrieve glyph index from character code */ glyph_index = FT_Get_Char_Index( pFT_Face, _char ); /* load glyph image into the slot (erase previous one) */ int error = FT_Load_Glyph( pFT_Face, glyph_index, FT_LOAD_DEFAULT ); error = FT_Render_Glyph( pFT_Face->glyph, FT_RENDER_MODE_NORMAL ); memset(&desc , 0 , sizeof(desc) ) ; FT_Glyph glyph; if(FT_Get_Glyph( pFT_Face->glyph, &glyph )) { XEVOL_LOG(eXL_DEBUG_HIGH,"FT_Load_Glyph failed\n"); return false; } FT_BitmapGlyph bitmap_glyph = (FT_BitmapGlyph)glyph; //取道位图数据 FT_Bitmap& bitmap = bitmap_glyph->bitmap; //把位图数据拷贝自己定义的数据区里.这样旧可以画到需要的东西上面了。 int width = bitmap.width; int height = bitmap.rows; if(width == 0 || height == 0 ) { FT_Done_Glyph(glyph); return 0; } pFT_Face->size->metrics.y_ppem; pFT_Face->glyph->metrics.horiAdvance; desc.m_adv_x = pFT_Face->glyph->advance.x / 64.0f; desc.m_adv_y = pFT_Face->size->metrics.y_ppem; //m_FT_Face->glyph->metrics.horiBearingY / 64.0f; desc.m_left = (float)bitmap_glyph->left; desc.m_top = (float)bitmap_glyph->top; desc.m_w = width; desc.m_h = height; if(bitmap.pixel_mode == FT_PIXEL_MODE_GRAY) { for(int y=0; y < height ; y++) { for(int x=0; x < width; x++) { int _y = y; unsigned char _vl = 0; if(x < bitmap.width && y < bitmap.rows) { _vl = (x>=bitmap.width || y>=bitmap.rows) ? 0 : bitmap.buffer[x + bitmap.width*y]; } if(_vl >= 0x40) _vl = 255; else _vl = 0; m_ttfBuffer[(1*x + _y * width)+0] = _vl; } } } else if(bitmap.pixel_mode == FT_PIXEL_MODE_MONO) //单色图 { for(int y=0; y < height ; y++) { for(int x=0; x < width; x++) { int _y = y; unsigned char _vl = 0; if(x < bitmap.width && y < bitmap.rows) { _vl = ((bitmap.buffer[(y * bitmap.pitch) + x / 8] << (x % 8)) & 0x80) ? 0xFFFFFFFF : 0x00000000; } if(_vl > 0x7f) _vl = 255; else _vl = 0; m_ttfBuffer[(1*x + _y * width)+0] = _vl; } } } FT_Done_Glyph(glyph); wchar_t name[]=L" .bmp"; name[0] = _char; ds_wstring fullName = _XEVOL_ABSPATH_(name); //saveBitMap(fullName.c_str() , width , height , m_ttfBuffer); //从Freetype里取出来了。 //现在开始降采样和计算. float advx = desc.m_adv_x * (m_fontSize/(float)m_ttfSize); float advy = desc.m_adv_y * (m_fontSize/(float)m_ttfSize); desc.m_adv_x *= (m_fontSize/(float)m_ttfSize); desc.m_adv_y *= (m_fontSize/(float)m_ttfSize); desc.m_left *= (m_fontSize/(float)m_ttfSize); desc.m_top *= (m_fontSize/(float)m_ttfSize); desc.m_w *= (m_fontSize/(float)m_ttfSize); desc.m_h *= (m_fontSize/(float)m_ttfSize); if(desc.m_adv_x > 0 && advx == 0) desc.m_adv_x = 1; else desc.m_adv_x = advx; if(desc.m_adv_y > 0 && advy == 0) desc.m_adv_y = 1; else desc.m_adv_y = advy; if(desc.m_w == 0) desc.m_w = 1; if(desc.m_h == 0) desc.m_h = 1; int ow = desc.m_w * UPSAMPLES; int oh = desc.m_h * UPSAMPLES; float* tBuffer = new float[ow * oh]; float dw = ((float)width) /ow; float dh = ((float)height)/oh; for(int y = 0 ; y < oh ; y ++) { for(int x = 0 ; x < ow ; x ++) { int bx = (float)(x * dw + dw/2.0f); int by = (float)(y * dh + dh/2.0f); unsigned char* cl = getPixel(bx , by , width , height , m_ttfBuffer); float d = 0; if( *cl > 200) { d = GetNearest(bx , by , 0x00 , width , height , m_ttfBuffer); } else { d = -1.0f * GetNearest(bx , by , 0x00 , width , height , m_ttfBuffer); } tBuffer[y * ow + x] = d ; } } float _min = 0.0f; float _max = 0.0f; for(int y = 0 ; y < oh ; y ++) { for(int x = 0 ; x < ow ; x ++) { if(tBuffer[y * ow + x] > _max) _max = tBuffer[y * ow + x]; if(tBuffer[y * ow + x] < _min) _min = tBuffer[y * ow + x]; } } //归一化 for(int y = 0 ; y < oh ; y ++) { for(int x = 0 ; x < ow ; x ++) { float v = 0.0f; if( tBuffer[y * ow + x] > 0 ) { v = tBuffer[y * ow + x] / _max; tBuffer[y * ow + x] = v ; } else { v = -tBuffer[y * ow + x] / _min; tBuffer[y * ow + x] = v ; } } } //开始输出 int nByte = sizeof(float16) * desc.m_w * desc.m_h; float16* outBuffer = new float16[desc.m_w * desc.m_h]; downSample(tBuffer , outBuffer , desc.m_w , desc.m_h); fwrite(outBuffer , 1 , nByte , file); delete [] tBuffer; delete [] outBuffer; return nByte; }
int run(int argc, char **argv) { if(argc != 7 && argc != 9) { cout << "Down-sample grid volume data by a scale" << endl; cout << "Syntax: mtsutil downSampleVolume 0 <grid_volume> <scale x> <scale y> <scale z> <target_volume>" << endl; cout << "Syntax: mtsutil downSampleVolume 1 <hgrid_volume_dict> <scale x> <scale y> <scale z> <prefix> <origin_suffix> <target_suffix>" << endl; return -1; } if (strcmp(argv[1], "0") == 0) { char *end_ptr = NULL; scale.x = strtol(argv[3], &end_ptr, 10); if (*end_ptr != '\0') SLog(EError, "Could not parse integer value"); scale.y = strtol(argv[4], &end_ptr, 10); if (*end_ptr != '\0') SLog(EError, "Could not parse integer value"); scale.z = strtol(argv[5], &end_ptr, 10); if (*end_ptr != '\0') SLog(EError, "Could not parse integer value"); Properties props("gridvolume"); props.setString("filename", argv[2]); props.setBoolean("sendData", false); VolumeDataSource *originVol = static_cast<VolumeDataSource *> (PluginManager::getInstance()-> createObject(MTS_CLASS(VolumeDataSource), props)); originVol->configure(); Log(EInfo, "%s", originVol->getClass()->getName().c_str()); Log(EInfo, "res = (%d, %d, %d)", originVol->getResolution().x, originVol->getResolution().y, originVol->getResolution().z); Log(EInfo, "channels = %d", originVol->getChannels()); Log(EInfo, "min = (%.6f, %.6f, %.6f)", originVol->getAABB().min.x, originVol->getAABB().min.y, originVol->getAABB().min.z); Log(EInfo, "max = (%.6f, %.6f, %.6f)", originVol->getAABB().max.x, originVol->getAABB().max.y, originVol->getAABB().max.z); AABB bbox = originVol->getAABB(); GridData s; downSample(originVol, s); Log(EInfo, "finish down-sampling, save volume data to file"); ref<FileStream> outFile = new FileStream(argv[6], FileStream::ETruncReadWrite); writeVolume(s, bbox, originVol->getChannels(), outFile); } else if (strcmp(argv[1], "1") == 0) { char *end_ptr = NULL; scale.x = strtol(argv[3], &end_ptr, 10); if (*end_ptr != '\0') SLog(EError, "Could not parse integer value"); scale.y = strtol(argv[4], &end_ptr, 10); if (*end_ptr != '\0') SLog(EError, "Could not parse integer value"); scale.z = strtol(argv[5], &end_ptr, 10); if (*end_ptr != '\0') SLog(EError, "Could not parse integer value"); fs::path resolved = Thread::getThread()->getFileResolver()->resolve(argv[2]); Log(EInfo, "Loading hierarchical grid dictrionary \"%s\"", argv[2]); ref<FileStream> stream = new FileStream(resolved, FileStream::EReadOnly); stream->setByteOrder(Stream::ELittleEndian); Float xmin = stream->readSingle(), ymin = stream->readSingle(), zmin = stream->readSingle(); Float xmax = stream->readSingle(), ymax = stream->readSingle(), zmax = stream->readSingle(); AABB aabb = AABB(Point(xmin, ymin, zmin), Point(xmax, ymax, zmax)); Vector3i res = Vector3i(stream); int nCells = res.x * res.y * res.z; int numBlocks = 0; while (!stream->isEOF()) { Vector3i block = Vector3i(stream); Assert(block.x >= 0 && block.y >= 0 && block.z >= 0 && block.x < res.x && block.y < res.y && block.z < res.z); Properties props("gridvolume"); props.setString("filename", formatString("%s%03i_%03i_%03i%s", argv[6], block.x, block.y, block.z, argv[7])); props.setBoolean("sendData", false); VolumeDataSource *ori = static_cast<VolumeDataSource *> (PluginManager::getInstance()-> createObject(MTS_CLASS(VolumeDataSource), props)); ori->configure(); //Log(EInfo, "Loading grid %03i_%03i_%03i", block.x, block.y, block.z); AABB bbox = ori->getAABB(); GridData s; downSample(ori, s); std::string filename(formatString("%s%03i_%03i_%03i%s", argv[6], block.x, block.y, block.z, argv[8])); ref<FileStream> outFile = new FileStream(filename.c_str(), FileStream::ETruncReadWrite); writeVolume(s, bbox, ori->getChannels(), outFile); ++numBlocks; } Log(EInfo, "%i blocks total, %s, resolution=%s", numBlocks, aabb.toString().c_str(), res.toString().c_str()); } return 0; }