void ImageFilterExampleWidget::open() {
//    this->objPath=QFileDialog::getOpenFileName(this,"Open Image File",QDir::homePath(),"Image files (*.png *.jpg *.jpeg)");

    this->objPath = "";
    QStringList filenames;
    QFileDialog* fileDialog= new QFileDialog(this,"Open Image File",QDir::homePath(),"Image files (*.png *.jpg *.jpeg)");
    if(fileDialog->exec())
    {
        filenames = fileDialog->selectedFiles();
        fileDialog->hide();
        fileDialog->setHidden(true);
        delete fileDialog;
    }
    if(!filenames.isEmpty())
    {
        this->objPath = filenames[0];
    }
    if(!isFileValid())
        this->objPath="";
    if(isFileValid())
    {
        QImage* image = new QImage(objPath);
        beforeW->setFixedSize(400,image->height()*400/image->width());
        beforeW->setImage(image);
        beforeW->repaint(); //call repaint event so that the widget redraws
        processImages();
    }
}
Beispiel #2
0
void Toerstein::open(const QString &path)
{
    ToolArea* toolArea;
    ToolAreaSide side;

    if (!isFileValid(path))
    {
        return;
    }

    for ( int i = 0; i < tabView->count(); i++ )
    {
        toolArea = qobject_cast<ToolArea *>(tabView->widget(i));

        side = toolArea->isFileOpen(path);

        if ( side != ToolAreaNone )
        {
            tabView->setCurrentIndex(i);
            toolArea->setFocusToCodeEditor(side);
            return;
        }
    }

    toolArea = qobject_cast<ToolArea *>(tabView->currentWidget());

    if ( !toolArea->open(path) )
    {
        createNewTab();
    }

    toolArea = qobject_cast<ToolArea *>(tabView->currentWidget());
    toolArea->open(path);
}
void ImageFilterExampleWidget::processImages() {
    if(isFileValid()) {
//        setWindowTitle(QString::fromStdString(this->imageFilter->testHelloWorld()));

        QImage* image = nullptr;
        switch(curFilter)
        {
            case BLUR:
                image=imageFilter->blurImage(new QImage(objPath));
                break;
            case SHARPING:
                image=imageFilter->sharpingImage(new QImage(objPath));
                break;
            case EMBOSSING:
                image=imageFilter->embossingImage(new QImage(objPath));
                break;
            default:
                break;
        }

        if(image!= nullptr)
        {
            afterW->setFixedSize(400,image->height()*400/image->width());
            afterW->setImage(image);
            afterW->repaint();}
//    }
    }
}
        void TextureResourceLoader::loadFileIntoBuffer(Core::File const& file, std::vector<unsigned char>& buffer, Endianness fileEndianness)
        {
            if(isFileValid(file))
            {
                if(!buffer.empty())
                {
                    OcularLogger->warning("Provided buffer is not empty; Emptying it", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadBuffer"));
                    buffer.clear();
                }

                std::ifstream inputStream(file.getFullPath(), std::ios_base::binary);

                if(inputStream.is_open())
                {
                    buffer = std::vector<unsigned char>(std::istreambuf_iterator<char>(inputStream), std::istreambuf_iterator<char>());
                    inputStream.close();

                    // Ensure all the retrieved data is in the proper endianness

                    for(unsigned i = 0; i < buffer.size(); i++)
                    {
                        Utils::EndianOps::convert(fileEndianness, Endianness::Native, buffer[i]);
                    }
                }
                else
                {
                    OcularEngine.Logger()->error("Failed to open file for reading '", file.getFullPath(), "'", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadBuffer"));
                }
            }
            else 
            {
                OcularEngine.Logger()->error("Resource '", file.getFullPath(), "' is not a valid file", OCULAR_INTERNAL_LOG("TextureResourceLoader_BMP", "readFile"));
            }
        }
Beispiel #5
0
void Toerstein::open(const QString &path1, const QString &path2)
{
    if (!isFileValid(path1) || !isFileValid(path2))
    {
        return;
    }

    ToolArea* toolArea = qobject_cast<ToolArea *>(tabView->currentWidget());

    if ( !toolArea->open(path1, path2) )
    {
        createNewTab();
    }

    toolArea = qobject_cast<ToolArea *>(tabView->currentWidget());
    toolArea->open(path1, path2);
}
        bool TextureResourceLoader::loadResource(Core::Resource* &resource, Core::File const& file, std::string const& mappingName)
        {
            bool result = false;

            if(isFileValid(file))
            {
                std::vector<Core::Color> pixels;

                unsigned width = 0;
                unsigned height = 0;

                if(readFile(file, pixels, width, height))
                {
                    if((width > 0) && (height > 0))
                    {
                        unsigned totalSize = width * height;

                        if(createResource(resource, file, pixels, width, height))
                        {
                            result = true;
                        }
                        else
                        {
                            OcularLogger->error("Failed to create Resource", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadResource"));
                        }
                    }
                    else
                    {
                        OcularLogger->error("Invalid image dimensions of (", width, ", ", height, ")", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadResource"));
                    }
                }
                else
                {
                    OcularLogger->error("Failed to parse the Resource file at '", file.getFullPath(), "'", OCULAR_INTERNAL_LOG("TextureResourceLoader", "loadResource"));
                }
            }

            return result;
        }
        bool MaterialResourceLoader::loadResource(Core::Resource* &resource, Core::File const& file, std::string const& mappingName)
        {
            bool result = false;

            if(isFileValid(file))
            {
                pugi::xml_document document;
                pugi::xml_parse_result parseResult = document.load_file(file.getFullPath().c_str());

                if(parseResult)
                {
                    pugi::xml_node rootNode = document.child("OcularMaterial");

                    if(rootNode)
                    {
                        Ocular::Core::BuilderNode builderNode(nullptr, "OcularMaterial", "", "");

                        //------------------------------------------------
                        // Parse generic variable nodes
                        //------------------------------------------------

                        for(auto child : rootNode.children())
                        {
                            if(Ocular::Utils::String::IsEqual(child.name(), "var"))
                            {
                                ParseVarNode(&builderNode, child);
                            }
                        }

                        //------------------------------------------------
                        // Parse Material specific nodes
                        //------------------------------------------------

                        ParseMaterialTree(&builderNode, rootNode);
                        
                        //------------------------------------------------
                        // Create and load the Material
                        //------------------------------------------------

                        Material* material = OcularGraphics->createMaterial();
                        material->setSourceFile(file);
                        material->onLoad(&builderNode);

                        resource = material;
                        result = true;
                    }
                    else
                    {
                        OcularLogger->error("Failed to find root node 'OcularMaterial' in Material '", file.getFullPath(), "'", OCULAR_INTERNAL_LOG("MaterialResourceLoader", "loadResource"));
                    }
                }
                else
                {
                    OcularLogger->error("Failed to parse Material file at '", file.getFullPath(), "' with error: ", parseResult.description(), OCULAR_INTERNAL_LOG("MaterialResourceLoader", "loadResource"));
                }
            }
            else
            {
                OcularLogger->error("Resource file at '", file.getFullPath(), "' is invalid", OCULAR_INTERNAL_LOG("MaterialResourceLoader", "loadResource"));
            }

            return result;
        }