void*
		Java_java_awt_Toolkit_imgCreateFromFile ( JNIEnv* env, jclass clazz, jstring fileName )
	{
		Image *img = 0;
		int   infile;
		char  *fn = java2CString( env, X, fileName);
		unsigned char  sig[SIG_LENGTH];
		
		if ( (infile = AWT_OPEN( fn)) >= 0 ) {
			if ( AWT_READ( infile, sig, sizeof(sig)) == sizeof(sig) ) {
				AWT_REWIND( infile);  /* some native converters can't skip the signature read */
				
				switch ( imageFormat( sig) ) {
				case SIG_GIF:
					img = readGifFile( infile);
					break;
				case SIG_JPEG:
					img = readJpegFile( infile);
					break;
				case SIG_PNG:
					//img = readPngFile( infile);
					break;
				default:
					img = unknownImage;
				}
			}
			AWT_CLOSE( infile);
		}
		
		return img;
	}
	void*
		Java_java_awt_Toolkit_imgCreateFromData ( JNIEnv* env, jclass clazz,
		jbyteArray jbuffer, jint off, jint len )
	{
		Image *img = 0;
		jboolean isCopy;
		jint   length = env->GetArrayLength( jbuffer);
		jbyte  *jb = env->GetByteArrayElements( jbuffer, &isCopy);
		unsigned char *buf = (unsigned char*) jb + off;
		
		/* in case of a buffer overrun, we probably have a JPEG read error, anyway */
		if ( (off + len) <= length ) {
			switch ( imageFormat( buf) ) {
			case SIG_GIF:
				img = readGifData( buf, len);
				break;
			case SIG_JPEG:
				img = readJpegData( buf, len);
				break;
			case SIG_PNG:
				//	  img = readPngData( buf, len);
				break;
			default:
				img = unknownImage;
			}
		}
		
		env->ReleaseByteArrayElements( jbuffer, jb, JNI_ABORT);
		return img;  
	}
Ejemplo n.º 3
0
void ImageDocument::setContents(const ImageContents &contents)
{
    Q_D(ImageDocument);

    if (contents.isNull()) {
        clear();
        return;
    }

    const auto header = contents.header();
    d->type = header.type();
    d->size = header.size();
    d->imageFormat = header.imageFormat();
    d->imageCount = header.imageCount();
    d->mipmapCount = header.mipmapCount();
    d->frameDelay = header.frameDelay();
    d->loopCount = header.loopCount();
    for (int index = 0; index < d->imageCount; ++index) {
        for (int level = 0; level < d->mipmapCount; ++level) {
            auto image = contents.image(index, level);
            std::unique_ptr<ImageDocumentItem> item(new ImageDocumentItem(this));
            item->setSize(image.size());
            item->setImage(image);
            d->items[ImageDocumentPrivate::ImageIndex(index, level)] = std::move(item);
        }
    }

    emit contentsChanged();
}
Ejemplo n.º 4
0
// Browse Image
void ScreenshotDialog::BrowseBackgroundImage()
{
	// Set Image filter
	QList<QByteArray> imageFormat(QImageReader::supportedImageFormats());
	const int numberOfFormat= imageFormat.size();
	QString filter(tr("All Images ("));
	for (int i= 0; i < numberOfFormat; ++i)
	{
		filter.append(QString(" *.") + QString(imageFormat[i]));
	}
	filter.append(")");

	QString imageFileName= QFileDialog::getOpenFileName(this, tr("Image File Name"), m_CurrentBackgroundImageName, filter);
	if (!imageFileName.isEmpty() && QFile(imageFileName).exists())
	{
		// Test if the Image is Loadable
		QImage testBackgroundLoading(imageFileName);
		if (!testBackgroundLoading.isNull())
		{
			m_CurrentBackgroundImageName= imageFileName;
			m_BackGroundMode= BackGroundImage;
			// Take the ScreenShot
			takeScreenshot();

			// Update the preview image
			updatePreviewImage();
		}
		else
		{
			QString message(tr("Unable to load image :") + QString("\n"));
			message+= imageFileName;
			QMessageBox::critical(this->parentWidget(), tr("Backround Image"), message);
		}
	}
}
Ejemplo n.º 5
0
/*!
    If supported, this function returns the image format of the file
    \a fileName. Otherwise, an empty string is returned.
*/
QByteArray QImageReader::imageFormat(const QString &fileName)
{
    QFile file(fileName);
    if (!file.open(QFile::ReadOnly))
        return QByteArray();

    return imageFormat(&file);
}
Ejemplo n.º 6
0
bool QgsRasterBlock::reset( QGis::DataType theDataType, int theWidth, int theHeight, double theNoDataValue )
{
  QgsDebugMsg( QString( "theWidth= %1 theHeight = %2 theDataType = %3 theNoDataValue = %4" ).arg( theWidth ).arg( theHeight ).arg( theDataType ).arg( theNoDataValue ) );

  qgsFree( mData );
  mData = nullptr;
  delete mImage;
  mImage = nullptr;
  qgsFree( mNoDataBitmap );
  mNoDataBitmap = nullptr;
  mDataType = QGis::UnknownDataType;
  mTypeSize = 0;
  mWidth = 0;
  mHeight = 0;
  mHasNoDataValue = false;
  mNoDataValue = std::numeric_limits<double>::quiet_NaN();
  mValid = false;

  if ( typeIsNumeric( theDataType ) )
  {
    QgsDebugMsg( "Numeric type" );
    qgssize tSize = typeSize( theDataType );
    QgsDebugMsg( QString( "allocate %1 bytes" ).arg( tSize * theWidth * theHeight ) );
    mData = qgsMalloc( tSize * theWidth * theHeight );
    if ( !mData )
    {
      QgsDebugMsg( QString( "Couldn't allocate data memory of %1 bytes" ).arg( tSize * theWidth * theHeight ) );
      return false;
    }
  }
  else if ( typeIsColor( theDataType ) )
  {
    QgsDebugMsg( "Color type" );
    QImage::Format format = imageFormat( theDataType );
    mImage = new QImage( theWidth, theHeight, format );
  }
  else
  {
    QgsDebugMsg( "Wrong data type" );
    return false;
  }

  mValid = true;
  mDataType = theDataType;
  mTypeSize = QgsRasterBlock::typeSize( mDataType );
  mWidth = theWidth;
  mHeight = theHeight;
  mHasNoDataValue = true;
  mNoDataValue = theNoDataValue;
  QgsDebugMsg( QString( "mWidth= %1 mHeight = %2 mDataType = %3 mData = %4 mImage = %5" ).arg( mWidth ).arg( mHeight ).arg( mDataType )
               .arg( reinterpret_cast< ulong >( mData ) ).arg( reinterpret_cast< ulong >( mImage ) ) );
  return true;
}
Ejemplo n.º 7
0
int SobelFilterImage::setupCL()
{
    cl_int err = CL_SUCCESS;
    cl_device_type dType;

    if(sampleArgs.deviceType.compare("cpu") == 0)
    {
        dType = CL_DEVICE_TYPE_CPU;
    }
    else //deviceType = "gpu"
    {
        dType = CL_DEVICE_TYPE_GPU;
        if(sampleArgs.isThereGPU)
        {
            std::cout << "GPU not found. Falling back to CPU device" << std::endl;
            dType = CL_DEVICE_TYPE_CPU;
        }
    }

    err = cl::Platform::get(&platforms);
    CHECK_OPENCL_ERROR(err, "Platform::get() failed.");

    std::vector<cl::Platform>::iterator i;

    int deviceId = -1;

    for (i=platforms.begin(); i!=platforms.end(); i++)
    {
        //std::cout << "Platform :" << (*i).getInfo<CL_PLATFORM_VENDOR>().c_str() << "\n";


        devices.clear();
        i->getDevices(dType, &devices);

        if (devices.size() < 0)
            break;

        deviceId = 0;
#if 0
        for (std::vector<cl::Device>::iterator i = devices.begin(); i != devices.end(); ++i)
        {
            std::cout << "Device " << " : ";
            std::string deviceName = (*i).getInfo<CL_DEVICE_NAME>();
            std::cout << deviceName.c_str() << "\n";
        }
#endif
        std::cout << "\n";

    }

    if (deviceId == -1) {
        std::cerr << "Cant find CL device" << std::endl;
        exit(-5);
    }

    device.push_back(devices[deviceId]);

    context = cl::Context( device );
    commandQueue = cl::CommandQueue(context, devices[deviceId], 0,
                                    &err);
    CHECK_OPENCL_ERROR(err, "CommandQueue::CommandQueue() failed.");

    cl::ImageFormat imageFormat(CL_RGBA, CL_UNSIGNED_INT8);
    /*
    * Create and initialize memory objects
    */
    inputImage2D = cl::Image2D(context,
                               CL_MEM_READ_ONLY,
                               imageFormat,
                               width,
                               height,
                               0,
                               NULL,
                               &err);
    CHECK_OPENCL_ERROR(err, "Image2D::Image2D() failed. (inputImage2D)");


    // Create memory objects for output Image
    outputImage2D = cl::Image2D(context,
                                CL_MEM_WRITE_ONLY,
                                imageFormat,
                                width,
                                height,
                                0,
                                0,
                                &err);
    CHECK_OPENCL_ERROR(err, "Image2D::Image2D() failed. (outputImage2D)");

    // create a CL program using the kernel source


    std::string clSourceData = readFile(sampleArgs.clKernelPath.c_str());

    // create program source
    cl::Program::Sources programSource(1, std::make_pair(clSourceData.c_str(), clSourceData.length()));

    // Create program object
    program = cl::Program(context, programSource, &err);
    CHECK_OPENCL_ERROR(err, "Program::Program() failed.");



    std::string flagsStr = std::string("");

    if(flagsStr.size() != 0)
    {
        std::cout << "Build Options are : " << flagsStr.c_str() << std::endl;
    }

    err = program.build( { device }, flagsStr.c_str());

    if(err != CL_SUCCESS)
    {
        if(err == CL_BUILD_PROGRAM_FAILURE)
        {
            std::string str = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(devices[deviceId]);

            std::cout << " \n\t\t\tBUILD LOG\n";
            std::cout << " ************************************************\n";
            std::cout << str << std::endl;
            std::cout << " ************************************************\n";
        }
    }
    CHECK_OPENCL_ERROR(err, "Program::build() failed.");

    // Create kernel
    kernel = cl::Kernel(program, "sobel_filter",  &err);
    CHECK_OPENCL_ERROR(err, "Kernel::Kernel() failed.");

    // Check group size against group size returned by kernel
    kernelWorkGroupSize = kernel.getWorkGroupInfo<CL_KERNEL_WORK_GROUP_SIZE>
            (devices[deviceId], &err);
    CHECK_OPENCL_ERROR(err, "Kernel::getWorkGroupInfo()  failed.");

    if((blockSizeX * blockSizeY) > kernelWorkGroupSize)
    {
        std::cout << "Out of Resources!" << std::endl;
        std::cout << "Group Size specified : "
                  << blockSizeX * blockSizeY << std::endl;
        std::cout << "Max Group Size supported on the kernel : "
                  << kernelWorkGroupSize << std::endl;
        std::cout << "Falling back to " << kernelWorkGroupSize << std::endl;

        if(blockSizeX > kernelWorkGroupSize)
        {
            blockSizeX = kernelWorkGroupSize;
            blockSizeY = 1;
        }
    }

    return 0;
}