Example #1
0
void DigestFilePair::calculate( const fs::path file ) {
	fs::ifstream file_stream( file );
	CryptoPP::FileSource fsource( file_stream, true );
	CryptoPP::SHA512 sha;
	byte digest[sha.DigestSize()];
	byte *data = new byte[ fsource.MaxRetrievable() ];
	size_t size = fsource.Get( data, fsource.MaxRetrievable() );
	sha.CalculateDigest( digest, data, size );
	std::stringstream ss;
	for(int i = 0; i < sha.DigestSize(); i++)
		ss << std::hex << std::setw(2) << std::setfill('0') << (int) digest[i];
	delete[] data;
	_digest = ss.str();
	_file = file;
}
Example #2
0
        GLImageShader2D::GLImageShader2D(QObject *parent):
          QOpenGLShaderProgram(parent),
          vshader(),
          fshader(),
          attr_coords(),
          attr_texcoords(),
          uniform_mvp(),
          uniform_texture(),
          uniform_lut(),
          uniform_min(),
          uniform_max()
        {
          initializeOpenGLFunctions();

          vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);

          std::string vsource("#version 110\n"
                              "\n"
                              "attribute vec2 coord2d;\n"
                              "attribute vec2 texcoord;\n"
                              "varying vec2 f_texcoord;\n"
                              "uniform mat4 mvp;\n"
                              "\n"
                              "void main(void) {\n"
                              "  gl_Position = mvp * vec4(coord2d, 0.0, 1.0);\n"
                              "  f_texcoord = texcoord;\n"
                              "}\n");

          vshader->compileSourceCode(vsource.c_str());
          if (!vshader->isCompiled())
            {
              std::cerr << "Failed to compile vertex shader\n" << vshader->log().toStdString() << std::endl;
            }

          fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
          std::string fsource("#version 110\n"
                              "#extension GL_EXT_texture_array : enable\n"
                              "\n"
                              "varying vec2 f_texcoord;\n"
                              "uniform sampler2D tex;\n"
                              "uniform sampler1DArray lut;\n"
                              "uniform vec3 texmin;\n"
                              "uniform vec3 texmax;\n"
                              "uniform vec3 correction;\n"
                              "\n"
                              "void main(void) {\n"
                              "  vec2 flipped_texcoord = vec2(f_texcoord.x, 1.0 - f_texcoord.y);\n"
                              "  vec4 texval = texture2D(tex, flipped_texcoord);\n"
                              "\n"
                              "  gl_FragColor = texture1DArray(lut, vec2(((((texval[0] * correction[0]) - texmin[0]) / (texmax[0] - texmin[0]))), 0.0));\n"
                              "}\n");

          fshader->compileSourceCode(fsource.c_str());
          if (!fshader->isCompiled())
            {
              std::cerr << "Failed to compile fragment shader\n" << fshader->log().toStdString() << std::endl;
            }

          addShader(vshader);
          addShader(fshader);
          link();

          if (!isLinked())
            {
              std::cerr << "Failed to link shader program\n" << log().toStdString() << std::endl;
            }

          attr_coords = attributeLocation("coord2d");
          if (attr_coords == -1)
            std::cerr << "Failed to bind coordinates" << std::endl;

          attr_texcoords = attributeLocation("texcoord");
          if (attr_texcoords == -1)
            std::cerr << "Failed to bind texture coordinates" << std::endl;

          uniform_mvp = uniformLocation("mvp");
          if (uniform_mvp == -1)
            std::cerr << "Failed to bind transform" << std::endl;

          uniform_texture = uniformLocation("tex");
          if (uniform_texture == -1)
            std::cerr << "Failed to bind texture uniform " << std::endl;

          uniform_lut = uniformLocation("lut");
          if (uniform_lut == -1)
            std::cerr << "Failed to bind lut uniform " << std::endl;

          uniform_min = uniformLocation("texmin");
          if (uniform_min == -1)
            std::cerr << "Failed to bind min uniform " << std::endl;

          uniform_max = uniformLocation("texmax");
          if (uniform_max == -1)
            std::cerr << "Failed to bind max uniform " << std::endl;

          uniform_corr = uniformLocation("correction");
          if (uniform_corr == -1)
            std::cerr << "Failed to bind correction uniform " << std::endl;
        }