// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ bool Image::testImage(const unsigned w0, const unsigned h0) { unsigned int d0 = 1; unsigned char* image = new unsigned char[w0*h0*d0]; for (unsigned int h = 0; h < h0; h++) { for (unsigned int w = 0; w < w0; w++) { // Edges unsigned char c = 0x00; if (h < 64 || h >= (h0 - 32)) c = 0x7f; if (w < 32 || w >= (w0 - 16)) c += 0x7f; // Cross hair if (h == (h0/2) || w == (w0/2)) c = 0xff; // Store the color unsigned int os = (h * (w0 * d0)) + (w * d0); image[os] = c; } } bool ok = setImageData(image, w0, h0, d0); delete [] image; return ok; }
osgToy::MipmapTestImage::MipmapTestImage( unsigned int sizeS, unsigned int sizeT ) : _bytesPerTexel(4), _numTexels(0), _checkerSize(8) { // compute mipmap sizes & buffer offset MipmapDataType mipmapOffset; for( unsigned int s=sizeS, t=sizeT; s||t; s>>=1, t>>=1 ) { if( s==0 ) s=1; if( t==0 ) t=1; _numTexels += s * t; _mipmapS.push_back(s); _mipmapT.push_back(t); mipmapOffset.push_back( _bytesPerTexel * _numTexels ); } setImage( sizeS, sizeT, 1, 4, GL_RGBA, GL_UNSIGNED_BYTE, new unsigned char[ _bytesPerTexel * _numTexels ], USE_NEW_DELETE); setMipmapLevels( mipmapOffset ); // populate mipmap level colors for( unsigned int lvl = 0; lvl < mipmapOffset.size(); ++lvl ) { unsigned char* data = getMipmapData(lvl); for( unsigned int t = 0; t < _mipmapT[lvl]; ++t ) { for( unsigned int s = 0; s < _mipmapS[lvl]; ++s, data+=_bytesPerTexel ) { setImageData( data, lvl, s, t ); } } } }
void ImageEditor::btnLoad_clicked() { QString fn = QFileDialog::getOpenFileName(this, tr("Choose a file"), QString::null, tr("Images(*.png *.jpg *.xpm)")); if(!fn.isEmpty()) { QFile file(fn); setImageData(QUUEncode(file)); } }
void SE_ColorEffectImage::setImageData(SE_RectPrimitive* primitive) { SE_ResourceManager* resourceManager = SE_Application::getInstance()->getResourceManager(); setImageData(primitive, SE_TEXTURE0, mBackgroundImageData, mBackground); setImageData(primitive, SE_TEXTURE1, mChannelImageData, mChannel); SE_TEXUNIT_TYPE start = SE_TEXTURE2; for(int i = 0 ; i < TEX_SIZE ; i++) { SE_Image* image = mTexture[i]; SE_ImageData* imageData = mTextureImageData[i]; if(image) { setImageData(primitive, start, imageData, image); start = (SE_TEXUNIT_TYPE)((int)start + 1); } } }
SVG::SVG(const QString uri) : uri_(uri) , width_(0) , height_(0) { QFile file(uri); if(!file.open(QIODevice::ReadOnly)) { put_flog(LOG_WARN, "could not open file %s", uri.toLocal8Bit().constData()); return; } if(!setImageData(file.readAll())) { put_flog(LOG_WARN, "could not setImageData %s", uri.toLocal8Bit().constData()); return; } }
void DImg::putImageData(uint width, uint height, bool sixteenBit, bool alpha, uchar* const data, bool copyData) { // set image data, metadata is untouched bool null = (width == 0) || (height == 0); // allocateData, or code below will set null to false setImageData(true, width, height, sixteenBit, alpha); // replace data delete [] m_priv->data; if (null) { // image is null - no data m_priv->data = nullptr; } else if (copyData) { size_t size = allocateData(); if (data) { memcpy(m_priv->data, data, size); } } else { if (data) { m_priv->data = data; m_priv->null = false; } else { allocateData(); } } }
QMimeData* createMimeData(const QVariantMap &data) { QStringList copyFormats = data.keys(); copyFormats.removeOne(mimeClipboardMode); std::unique_ptr<QMimeData> newClipboardData(new QMimeData); for ( const auto &format : copyFormats ) newClipboardData->setData( format, data[format].toByteArray() ); if ( !copyFormats.contains(mimeOwner) ) newClipboardData->setData( mimeOwner, makeClipboardOwnerData() ); // Set image data. const QStringList formats = QStringList() << "image/png" << "image/bmp" << "application/x-qt-image" << data.keys(); for (const auto &imageFormat : formats) { if ( setImageData(data, imageFormat, newClipboardData.get()) ) break; } return newClipboardData.release(); }
void DImg::copyImageData(const Private* const src) { setImageData(src->null, src->width, src->height, src->sixteenBit, src->alpha); }
bool UserScript::toolOperations() { QString script = settings()[QLatin1String("Script")].toString(); if (script.isEmpty()) { setErrorDescription(i18n("User Script: No script.")); return false; } // Replace all occurences of $INPUT and $OUTPUT in script to file names. Case sensitive. script.replace(QLatin1String("$INPUT"), QLatin1Char('"') + inputUrl().toLocalFile() + QLatin1Char('"')); script.replace(QLatin1String("$OUTPUT"), QLatin1Char('"') + outputUrl().toLocalFile() + QLatin1Char('"')); QString shellScript; #ifndef WIN32 QString envCmd = QLatin1String("export "); #else QString envCmd = QLatin1String("set "); #endif // WIN32 QString tagPath = TagsCache::instance()->tagPaths(imageInfo().tagIds(), TagsCache::NoLeadingSlash, TagsCache::NoHiddenTags).join(QLatin1Char(';')); // Populate env variables from metadata shellScript.append(envCmd + QString::fromUtf8("COLORLABEL=\"%1\"\n").arg(imageInfo().colorLabel())); shellScript.append(envCmd + QString::fromUtf8("PICKLABEL=\"%1\"\n") .arg(imageInfo().pickLabel())); shellScript.append(envCmd + QString::fromUtf8("COMMENTS=\"%1\"\n") .arg(imageInfo().comment())); shellScript.append(envCmd + QString::fromUtf8("RATING=\"%1\"\n") .arg(imageInfo().rating())); shellScript.append(envCmd + QString::fromUtf8("TITLE=\"%1\"\n") .arg(imageInfo().title())); shellScript.append(envCmd + QString::fromUtf8("TAGSPATH=\"%1\"\n") .arg(tagPath)); shellScript.append(script); // Empties d->image, not to pass it to the next tool in chain setImageData(DImg()); QProcess process(this); // call the shell script #ifndef WIN32 int returncode = process.execute(QLatin1String("/bin/sh"), QStringList() << QLatin1String("-c") << shellScript); #else int returncode = process.execute(QLatin1String("cmd.exe"), QStringList() << QLatin1String("/c") << shellScript); #endif // WIN32 if (returncode == -2) { setErrorDescription(i18n("User Script: Failed to start script.")); return false; } if (returncode == -1) { setErrorDescription(i18n("User Script: Script process crashed.")); return false; } if (returncode == 127) { setErrorDescription(i18n("User Script: Command not found.")); return false; } return true; }
void gpuVolumeRayCast::setDeviceMemroy (vtkVolumeRayCastDynamicInfo * _dInfo, vtkVolumeRayCastStaticInfo * _sInfo, float _centerScale, float *_bounds, float _sampleDist, float *_offset, double _ImageSampleDistance, int *_ZBufferSize, float *_ZBuffer, long long _scalarDataSize) { #ifdef _USE_TIMER timer->onTimer (t_dMemSet); timer->onTimer (t_total); #endif releaseDeviceMemory (); vtkVolume * _vol = _sInfo->Volume; hStaticInfo.ColorChannels = _sInfo->ColorChannels; hStaticInfo.arraySize = _vol->GetArraySize (); setTransferFunctions (_vol); hStaticInfo.gradient_opacity_constant = _vol->GetGradientOpacityConstant (); memcpy (hStaticInfo.DataIncrement, _sInfo->DataIncrement, sizeof (long long) * 3); // shaded memcpy (hStaticInfo.ViewToVoxelsMatrix, _sInfo->ViewToVoxelsMatrix, sizeof (float) * 16); setImageData (_sInfo); memcpy (hStaticInfo.offset, _offset, sizeof (float) * 2); hStaticInfo.ImageSampleDistance = _ImageSampleDistance; if (_ZBuffer != NULL) { LOOP_K (2) hStaticInfo.ZBufferSize[k] = _ZBufferSize[k]; dMemAlloc < float > (&hStaticInfo.ZBuffer, hStaticInfo.ZBufferSize[0] * hStaticInfo.ZBufferSize[1], &dMemUsage, gpuID); MEMCPY_H_to_D (hStaticInfo.ZBuffer, _ZBuffer, hStaticInfo.ZBufferSize[0] * hStaticInfo.ZBufferSize[1]); } memcpy (hStaticInfo.bounds, _bounds, sizeof (float) * 6); hStaticInfo.centerScale = _centerScale; hStaticInfo.sampleDistance = _sampleDist; // scalar data hStaticInfo.scalarDataType = _sInfo->ScalarDataType; hStaticInfo.scalarDataSize = _scalarDataSize; //hStaticInfo.dataPtr = _sInfo->ScalarDataPointer; CUDA_SAFECALL (cudaMalloc (&hStaticInfo.scalarDataPtr, sizeof (unsigned char) * hStaticInfo.scalarDataSize)); dMemUsage += hStaticInfo.scalarDataSize; MEMCPY_H_to_D (hStaticInfo.scalarDataPtr, _sInfo->ScalarDataPointer, sizeof (unsigned char) * hStaticInfo.scalarDataSize); dMemAlloc < gStaticInfo > (&dStaticInfo, 1, &dMemUsage, gpuID); MEMCPY_H_to_D (dStaticInfo, &hStaticInfo, sizeof (gStaticInfo)); #ifdef _USE_TIMER timer->offTimer (t_dMemSet); timer->offTimer (t_total); printf ("Used device memory = %.2f MB\n", dMemUsage / (_MB_)); #endif }
int main(/*int argc, char* argv[]*/) { // Create OpenGL window in single line pangolin::CreateWindowAndBind("Main",640,480); // 3D Mouse handler requires depth testing to be enabled glEnable(GL_DEPTH_TEST); // Issue specific OpenGl we might need glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Define Camera Render Object (for view / scene browsing) pangolin::OpenGlMatrix proj = pangolin::ProjectionMatrix(640,480,420,420,320,240,0.1,1000); pangolin::OpenGlRenderState s_cam(proj, pangolin::ModelViewLookAt(1,0.5,-2,0,0,0, pangolin::AxisY) ); pangolin::OpenGlRenderState s_cam2(proj, pangolin::ModelViewLookAt(0,0,-2,0,0,0, pangolin::AxisY) ); // Add named OpenGL viewport to window and provide 3D Handler pangolin::View& d_cam1 = pangolin::Display("cam1") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam)); pangolin::View& d_cam2 = pangolin::Display("cam2") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam2)); pangolin::View& d_cam3 = pangolin::Display("cam3") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam)); pangolin::View& d_cam4 = pangolin::Display("cam4") .SetAspect(640.0f/480.0f) .SetHandler(new pangolin::Handler3D(s_cam2)); pangolin::View& d_img1 = pangolin::Display("img1") .SetAspect(640.0f/480.0f); pangolin::View& d_img2 = pangolin::Display("img2") .SetAspect(640.0f/480.0f); // LayoutEqual is an EXPERIMENTAL feature - it requires that all sub-displays // share the same aspect ratio, placing them in a raster fasion in the // viewport so as to maximise display size. pangolin::Display("multi") .SetBounds(0.0, 1.0, 0.0, 1.0) .SetLayout(pangolin::LayoutEqual) .AddDisplay(d_cam1) .AddDisplay(d_img1) .AddDisplay(d_cam2) .AddDisplay(d_img2) .AddDisplay(d_cam3) .AddDisplay(d_cam4); const int width = 64; const int height = 48; unsigned char* imageArray = new unsigned char[3*width*height]; pangolin::GlTexture imageTexture(width,height,GL_RGB,false,0,GL_RGB,GL_UNSIGNED_BYTE); // Default hooks for exiting (Esc) and fullscreen (tab). while( !pangolin::ShouldQuit() ) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Generate random image and place in texture memory for display setImageData(imageArray,3*width*height); imageTexture.Upload(imageArray,GL_RGB,GL_UNSIGNED_BYTE); glColor3f(1.0,1.0,1.0); d_cam1.Activate(s_cam); pangolin::glDrawColouredCube(); d_cam2.Activate(s_cam2); pangolin::glDrawColouredCube(); d_cam3.Activate(s_cam); pangolin::glDrawColouredCube(); d_cam4.Activate(s_cam2); pangolin::glDrawColouredCube(); d_img1.Activate(); glColor4f(1.0f,1.0f,1.0f,1.0f); imageTexture.RenderToViewport(); d_img2.Activate(); glColor4f(1.0f,1.0f,1.0f,1.0f); imageTexture.RenderToViewport(); // Swap frames and Process Events pangolin::FinishFrame(); } delete[] imageArray; return 0; }
ossimImageDataHelper::ossimImageDataHelper(ossimImageData* imageData) { setImageData(imageData); }