コード例 #1
1
ファイル: font.cpp プロジェクト: jnwatts/FontImageToHeaders
Font::Font(QString image_path, QString xml_path)
{
    QFile f(xml_path);
    QString errorStr("");
    int errorLine(0);
    int errorColumn(0);
    QDomDocument doc;
    QDomElement root;
    
    if (!f.open(QFile::ReadOnly | QFile::Text)) {
        qCritical("ERROR: Failed to open config file \"%s\": %s",
                  xml_path.toUtf8().constData(),
                  f.errorString().toUtf8().constData()
                  );
        return;
    }
    
    if (!doc.setContent(&f, false, &errorStr, &errorLine, &errorColumn)) {
        qCritical("ERROR: Failed to parse config file \"%s\" at line %d, column %d:\n%s",
                  xml_path.toUtf8().constData(),
                  errorLine,
                  errorColumn,
                  errorStr.toUtf8().constData()
                  );
        return;
    }
    
    root = doc.documentElement();
    if (root.tagName() != "Font") {
        qCritical("ERROR: Unexpected root element \"%s\" at line %d, column %d",
                  root.tagName().toUtf8().constData(),
                  root.lineNumber(),
                  root.columnNumber());
        return;
    }
    
    this->size = root.attribute("size").toInt();
    this->family = root.attribute("family");
    this->height = root.attribute("height").toInt();
    this->style = root.attribute("style");
    
//    qDebug("Font: %d, %s, %d, %s", this->size, this->family.toUtf8().constData(), this->height, this->style.toUtf8().constData());
    
    _minChar = 127;
    _maxChar = 0;
    QDomElement childElement = root.firstChildElement();
    while (!childElement.isNull()) {
        QString tagName = childElement.tagName();
        if (tagName == "Char") {
            Char *c = new Char(childElement);
            this->_chars[c->code] = c;
            if (c->code > _maxChar)
                _maxChar = c->code;
            if (c->code < _minChar)
                _minChar = c->code;
        }
        childElement = childElement.nextSiblingElement();
    }
    
    QImageReader image_reader(image_path);
    this->_image = image_reader.read();
}
コード例 #2
0
ファイル: ReaderQt.cpp プロジェクト: spillerrec/imgviewer
AReader::Error ReaderQt::read( imageCache &cache, const uint8_t* data, unsigned length, QString format ) const{
	QByteArray byte_data = fromData( data, length );
	QBuffer buffer( &byte_data );
	QImageReader image_reader( &buffer, format.toLocal8Bit() );
	
	if( image_reader.canRead() ){
		//Read first image
		QImage frame;
		if( !image_reader.read( &frame ) )
			return ERROR_TYPE_UNKNOWN;
		
		int frame_amount = image_reader.imageCount();
		auto isAnim = image_reader.supportsAnimation();
		cache.set_info( frame_amount, isAnim, isAnim ? image_reader.loopCount() : -1 );
		
		int current_frame = 1;
		do{
			cache.add_frame( frame, image_reader.nextImageDelay() );
			if( frame_amount > 0 && current_frame >= frame_amount )
				break;
			current_frame++;
			image_reader.jumpToNextImage();
		}
		while( image_reader.read( &frame ) );
		
		cache.set_fully_loaded();
		//TODO: What to do on fail?
	}
	else
		return ERROR_TYPE_UNKNOWN;
	
	return ERROR_NONE;
}
コード例 #3
0
ファイル: mainwindow.cpp プロジェクト: Flomeni/acquisition
void MainWindow::OnImageFetched(QNetworkReply *reply) {
    std::string url = reply->url().toString().toStdString();
    if (reply->error()) {
        QLOG_WARN() << "Failed to download item image," << url.c_str();
        return;
    }
    QImageReader image_reader(reply);
    QImage image = image_reader.read();

    image_cache_->Set(url, image);

    if (current_item_ && (url == current_item_->icon() || url == POE_WEBCDN + current_item_->icon()))
        UpdateCurrentItemIcon(image);
}
コード例 #4
0
ファイル: ReaderQt.cpp プロジェクト: spillerrec/imgviewer
bool ReaderQt::can_read( const uint8_t* data, unsigned length, QString format ) const{
	QByteArray byte_data = fromData( data, length );
	QBuffer buffer( &byte_data );
	QImageReader image_reader( &buffer, format.toLocal8Bit() );
	return image_reader.canRead();
}
コード例 #5
0
ファイル: envtool.cpp プロジェクト: VirtuosoChris/envtools
int main(int argc, char **argv)
{
try{
    /* Set some default behaviors. */
    
    const char *i = "latlong";
    const char *o = "latlong";
    const char *p = "rgss";
    const char *f = "linear";
    
    float rot[3] = { 0.f, 0.f, 0.f };
    
    int n = 1024;
    int c;
    
    /* Parse the command line options. */
    
    const char* convtype=NULL;
    double convparameter = 0.0;
    
    
    while ((c = getopt(argc, argv, "i:o:p:n:f:c:x:y:z:")) != -1)
        switch (c)
    {
        case 'i': i      = optarg;               break;
        case 'o': o      = optarg;               break;
        case 'p': p      = optarg;               break;
        case 'f': f      = optarg;               break;
        case 'x': rot[0] = strtod(optarg, 0);    break;
        case 'y': rot[1] = strtod(optarg, 0);    break;
        case 'z': rot[2] = strtod(optarg, 0);    break;
        case 'n': n      = strtol(optarg, 0, 0); break;
        case 'c':
        {
            convtype = optarg;
            
            if(!strcmp(convtype, "phong") || !strcmp(convtype, "gauss") || !strcmp(convtype, "hanning") || !strcmp(convtype, "lanczos"))
            {
                try {
                    convparameter = std::stod(argv[optind], 0);
                }
                catch (const std::exception& e)
                {
                    return usage(argv[0]);
                }

            }
            else
            {
                return usage(argv[0]);
            }
            
            break;
        }
            
        default: return usage(argv[0]);
    }
    
    int      num = 1;
    image   *src = 0;
    image   *dst = 0;
    image   *tmp = 0;
    to_img   img;
    to_env   env;
    filter   fil;
    
    /* Select the sampler. */
    
    if      (!strcmp(f, "linear"))  fil = filter_linear;
    else if (!strcmp(f, "nearest")) fil = filter_nearest;
    else return usage(argv[0]);
    
    /* Read the input image. */
    
    const int fileArgCt = 2;
    
    std::vector<const char*> inputFiles;
    inputFiles.insert(inputFiles.begin(), &argv[optind], &argv[argc-1]);
    
    if (optind + fileArgCt <= argc)
    {
        if (!strcmp(i, "cube"))
        {
            tmp = image_reader(inputFiles, 6);
            src = image_border(tmp);
            img = cube_to_img;
        }
        else if (!strcmp(i, "dome"))
        {
            src = image_reader(inputFiles, 1);
            img = dome_to_img;
        }
        else if (!strcmp(i, "hemi"))
        {
            src = image_reader(inputFiles, 1);
            img = hemi_to_img;
        }
        else if (!strcmp(i, "ball"))
        {
            src = image_reader(inputFiles, 1);
            img = ball_to_img;
        }
        else if (!strcmp(i, "latlong") || !strcmp(i, "llsquare"))
        {
            src = image_reader(inputFiles, 1);
            img = rect_to_img;
        }
        else return usage(argv[0]);
    }
    else return usage(argv[0]);
    
    /* Prepare the output image. */
    
    if (src)
    {
        if (!strcmp(o, "cube"))
        {
            dst = image_alloc((num = 6), n, n, src->c);
            env = cube_to_env;
        }
        else if (!strcmp(o, "dome"))
        {
            dst = image_alloc((num = 1), n, n, src->c);
            env = dome_to_env;
        }
        else if (!strcmp(o, "hemi"))
        {
            dst = image_alloc((num = 1), n, n, src->c);
            env = hemi_to_env;
        }
        else if (!strcmp(o, "ball"))
        {
            dst = image_alloc((num = 1), n, n, src->c);
            env = ball_to_env;
        }
        else if (!strcmp(o, "latlong"))
        {
            dst = image_alloc((num = 1), n, 2 * n, src->c);
            env = rect_to_env;
        }
        else if (!strcmp(o, "llsquare"))
        {
            dst = image_alloc((num = 1), n, n, src->c);
            env = rect_to_env;
        }
        else return usage(argv[0]);
    }
    else
    {
        throw std::runtime_error("Failed to load file");
    }
    
    /* Perform the remapping using the selected pattern. */
    
    if (src && dst)
    {
        if (!strcmp(p, "cent"))
            process(src, dst, &cent_pattern, rot, fil, img, env, num);
        
        else if (!strcmp(p, "rgss"))
            process(src, dst, &rgss_pattern, rot, fil, img, env, num);
        
        else if (!strcmp(p, "box2"))
            process(src, dst, &box2_pattern, rot, fil, img, env, num);
        
        else if (!strcmp(p, "box3"))
            process(src, dst, &box3_pattern, rot, fil, img, env, num);
        
        else if (!strcmp(p, "box4"))
            process(src, dst, &box4_pattern, rot, fil, img, env, num);
        
        else return usage(argv[0]);
    
        /* Write the output. */
        
        //image_writer(argv[optind + 1], dst, num);
        image_writer(argv[argc - 1], dst, num);
    }
    
}catch (const std::runtime_error& e)
{
    std::clog<<e.what()<<std::endl;
}
    return 0;
}
コード例 #6
0
ファイル: envremap.c プロジェクト: FH-Potsdam/envtools
int main(int argc, char **argv)
{
    /* Set some default behaviors. */

    const char *i = "rect";
    const char *o = "rect";
    const char *p = "rgss";
    const char *f = "linear";

    float rot[3] = { 0.f, 0.f, 0.f };

    int n = 1024;
    int c;

    /* Parse the command line options. */

    while ((c = getopt(argc, argv, "i:o:p:n:f:x:y:z:")) != -1)
        switch (c)
        {
            case 'i': i      = optarg;               break;
            case 'o': o      = optarg;               break;
            case 'p': p      = optarg;               break;
            case 'f': f      = optarg;               break;
            case 'x': rot[0] = strtod(optarg, 0);    break;
            case 'y': rot[1] = strtod(optarg, 0);    break;
            case 'z': rot[2] = strtod(optarg, 0);    break;
            case 'n': n      = strtol(optarg, 0, 0); break;

            default: return usage(argv[0]);
        }

    int      num = 1;
    image   *src = 0;
    image   *dst = 0;
    image   *tmp = 0;
    to_img   img;
    to_env   env;
    filter   fil;

    /* Select the sampler. */

    if      (!strcmp(f, "linear"))  fil = filter_linear;
    else if (!strcmp(f, "nearest")) fil = filter_nearest;
    else return usage(argv[0]);

    /* Read the input image. */

    if (optind + 2 <= argc)
    {
        if      (!strcmp(i, "cube"))
        {
            tmp = image_reader(argv[optind], 6);
            src = image_border(tmp);
            img = cube_to_img;
        }
        else if (!strcmp(i, "dome"))
        {
            src = image_reader(argv[optind], 1);
            img = dome_to_img;
        }
        else if (!strcmp(i, "hemi"))
        {
            src = image_reader(argv[optind], 1);
            img = hemi_to_img;
        }
        else if (!strcmp(i, "ball"))
        {
            src = image_reader(argv[optind], 1);
            img = ball_to_img;
        }
        else if (!strcmp(i, "rect"))
        {
            src = image_reader(argv[optind], 1);
            img = rect_to_img;
        }
        else return usage(argv[0]);
    }
    else return usage(argv[0]);

    /* Prepare the output image. */

    if (src)
    {
        if      (!strcmp(o, "cube"))
        {
            dst = image_alloc((num = 6), n, n, src->c, src->b, src->s);
            env = cube_to_env;
        }
        else if (!strcmp(o, "dome"))
        {
            dst = image_alloc((num = 1), n, n, src->c, src->b, src->s);
            env = dome_to_env;
        }
        else if (!strcmp(o, "hemi"))
        {
            dst = image_alloc((num = 1), n, n, src->c, src->b, src->s);
            env = hemi_to_env;
        }
        else if (!strcmp(o, "ball"))
        {
            dst = image_alloc((num = 1), n, n, src->c, src->b, src->s);
            env = ball_to_env;
        }
        else if (!strcmp(o, "rect"))
        {
            dst = image_alloc((num = 1), n, 2 * n, src->c, src->b, src->s);
            env = rect_to_env;
        }
        else return usage(argv[0]);
    }

    /* Perform the remapping using the selected pattern. */

    if (src && dst)
    {
        if      (!strcmp(p, "cent"))
            process(src, dst, &cent_pattern, rot, fil, img, env, num);

        else if (!strcmp(p, "rgss"))
            process(src, dst, &rgss_pattern, rot, fil, img, env, num);

        else if (!strcmp(p, "box2"))
            process(src, dst, &box2_pattern, rot, fil, img, env, num);

        else if (!strcmp(p, "box3"))
            process(src, dst, &box3_pattern, rot, fil, img, env, num);

        else if (!strcmp(p, "box4"))
            process(src, dst, &box4_pattern, rot, fil, img, env, num);

        else return usage(argv[0]);

        /* Write the output. */

        image_writer(argv[optind + 1], dst, num);
    }

    return 0;
}