Beispiel #1
0
static void TestObjectSerialization(T* testObj, skiatest::Reporter* reporter) {
    SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
    SerializationUtils<T>::Write(writer, testObj);
    size_t bytesWritten = writer.bytesWritten();
    REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);

    unsigned char dataWritten[1024];
    writer.writeToMemory(dataWritten);

    // Make sure this fails when it should (test with smaller size, but still multiple of 4)
    SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
    T obj;
    SerializationUtils<T>::Read(buffer, &obj);
    REPORTER_ASSERT(reporter, !buffer.isValid());

    // Make sure this succeeds when it should
    SkValidatingReadBuffer buffer2(dataWritten, bytesWritten);
    const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.skip(0));
    T obj2;
    SerializationUtils<T>::Read(buffer2, &obj2);
    const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.skip(0));
    // This should have succeeded, since there are enough bytes to read this
    REPORTER_ASSERT(reporter, buffer2.isValid());
    REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten);

    TestAlignment(testObj, reporter);
}
/**
* \par Implementation
* The center of the implementation is the <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa370134%28v=vs.85%29.aspx">MsiGetProperty function</a>.
*/
Property::operator std::wstring() const
{
  /*
  * The first call gets the size, but also the actual value if it's short enough.
  * A second call, if necessary, allocates a sufficiently-long buffer and then gets the full value.
  * We use only a modest fixed-size buffer for the first step, because we handle arbitrary-length property values in a second step.
  */
  // This buffer allocates on the stack, so we don't want it too large; 64 characters is enough for most properties anyway.
  WCHAR buffer1[64] = {L'\0'};
  DWORD length = sizeof(buffer1) / sizeof(WCHAR);
  UINT x = MsiGetPropertyW(handle, name.c_str(), buffer1, & length);
  switch (x)
  {
    case ERROR_SUCCESS:
      // This call might succeed, which means the return value was short enough to fit into the buffer.
      return std::wstring(buffer1, length);
    case ERROR_MORE_DATA:
      // Do nothing yet.
      break;
    default:
      throw WindowsApiError("MsiGetPropertyW", x, "fixed buffer");
  }
  // Assert we received ERROR_MORE_DATA
  // unique_ptr handles deallocation transparently
  std::unique_ptr<WCHAR[]> buffer2(new WCHAR[length]);
  x = MsiGetPropertyW(handle, name.c_str(), buffer2.get(), & length);
  switch (x)
  {
    case ERROR_SUCCESS:
      return std::wstring(buffer2.get(), length);
    default:
      throw WindowsApiError("MsiGetPropertyW", x, "allocated buffer");
  }
}
int hpx_main(boost::program_options::variables_map& vm)
{
    std::size_t size = 1;
    for (std::size_t i = 0; i != 20; ++i) {
        // create argument for action
        std::vector<double> data1;
        data1.resize(size << i);

        hpx::serialization::serialize_buffer<double> buffer1(data1.data(), data1.size(),
            hpx::serialization::serialize_buffer<double>::reference);

        test_normal_serialization<test_action1>(buffer1);
        test_zero_copy_serialization<test_action1>(buffer1);

        std::vector<int> data2;
        data2.resize(size << i);

        hpx::serialization::serialize_buffer<int> buffer2(data2.data(), data2.size(),
            hpx::serialization::serialize_buffer<int>::reference);

        test_normal_serialization(buffer1, buffer2);
        test_zero_copy_serialization(buffer1, buffer2);
        test_normal_serialization(42.0, buffer1, "42.0", 42, buffer2);
        test_zero_copy_serialization(42.0, buffer1, "42.0", 42, buffer2);

        data_buffer<double> buffer3(size << i);
        test_normal_serialization<test_action4>(buffer3);
        test_zero_copy_serialization<test_action4>(buffer3);
    }

    return hpx::finalize();
}
void AUD_FileWriter::writeReader(AUD_Reference<AUD_IReader> reader, std::vector<AUD_Reference<AUD_IWriter> >& writers, unsigned int length, unsigned int buffersize)
{
	AUD_Buffer buffer(buffersize * AUD_SAMPLE_SIZE(reader->getSpecs()));
	AUD_Buffer buffer2(buffersize * sizeof(sample_t));
	sample_t* buf = buffer.getBuffer();
	sample_t* buf2 = buffer2.getBuffer();

	int len;
	bool eos = false;
	int channels = reader->getSpecs().channels;

	for(unsigned int pos = 0; ((pos < length) || (length <= 0)) && !eos; pos += len)
	{
		len = buffersize;
		if((len > length - pos) && (length > 0))
			len = length - pos;
		reader->read(len, eos, buf);

		for(int channel = 0; channel < channels; channel++)
		{
			for(int i = 0; i < len; i++)
			{
				// clamping!
				if(buf[i * channels + channel] > 1)
					buf2[i] = 1;
				else if(buf[i * channels + channel] < -1)
					buf2[i] = -1;
				else
					buf2[i] = buf[i * channels + channel];
			}

			writers[channel]->write(len, buf2);
		}
	}
}
TEST(BigBufferTest, AppendAndMoveBlock) {
    BigBuffer buffer(16);

    uint32_t* b1 = buffer.nextBlock<uint32_t>();
    ASSERT_NE(nullptr, b1);
    *b1 = 33;

    {
        BigBuffer buffer2(16);
        b1 = buffer2.nextBlock<uint32_t>();
        ASSERT_NE(nullptr, b1);
        *b1 = 44;

        buffer.appendBuffer(std::move(buffer2));
        EXPECT_EQ(0u, buffer2.size());
        EXPECT_EQ(buffer2.begin(), buffer2.end());
    }

    EXPECT_EQ(2 * sizeof(uint32_t), buffer.size());

    auto b = buffer.begin();
    ASSERT_NE(b, buffer.end());
    ASSERT_EQ(sizeof(uint32_t), b->size);
    ASSERT_EQ(33u, *reinterpret_cast<uint32_t*>(b->buffer.get()));
    ++b;

    ASSERT_NE(b, buffer.end());
    ASSERT_EQ(sizeof(uint32_t), b->size);
    ASSERT_EQ(44u, *reinterpret_cast<uint32_t*>(b->buffer.get()));
    ++b;

    ASSERT_EQ(b, buffer.end());
}
Beispiel #6
0
static void TestObjectSerializationNoAlign(T* testObj, skiatest::Reporter* reporter) {
    SkBinaryWriteBuffer writer;
    SerializationUtils<T>::Write(writer, testObj);
    size_t bytesWritten = writer.bytesWritten();
    REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);

    unsigned char dataWritten[1024];
    writer.writeToMemory(dataWritten);

    SerializationTestUtils<T, testInvalid>::InvalidateData(dataWritten);

    // Make sure this fails when it should (test with smaller size, but still multiple of 4)
    SkReadBuffer buffer(dataWritten, bytesWritten - 4);
    T obj;
    SerializationUtils<T>::Read(buffer, &obj);
    REPORTER_ASSERT(reporter, !buffer.isValid());

    // Make sure this succeeds when it should
    SkReadBuffer buffer2(dataWritten, bytesWritten);
    size_t offsetBefore = buffer2.offset();
    T obj2;
    SerializationUtils<T>::Read(buffer2, &obj2);
    size_t offsetAfter = buffer2.offset();
    // This should have succeeded, since there are enough bytes to read this
    REPORTER_ASSERT(reporter, buffer2.isValid() == !testInvalid);
    // Note: This following test should always succeed, regardless of whether the buffer is valid,
    // since if it is invalid, it will simply skip to the end, as if it had read the whole buffer.
    REPORTER_ASSERT(reporter, offsetAfter - offsetBefore == bytesWritten);
}
Beispiel #7
0
int main() {

    Buffer buffer1(10);
    Buffer buffer2(10);
    LeftToRight l2r(&buffer1, &buffer2);
    RightToLeft r2l(&buffer1, &buffer2);

    pthread_t threads[2];
    
    pid_t pid = getpid();
    printf("main pid=%d\n", pid);
    int rc = pthread_create(&threads[0], 0, startThread, (void *)&l2r);
    if (rc) {
        printf("ERROR; return code from pthread_create() is %d\n", rc);
        exit(1);
    }
    rc = pthread_create(&threads[1], 0, startThread, (void *)&r2l);
    if (rc) {
        printf("ERROR; return code from pthread_create() is %d\n", rc);
        exit(1);
    }

    pthread_join(threads[0], 0);
    threads[0] = 0;
    pthread_join(threads[1], 0);
    threads[1] = 0;

    return 0;
}
Beispiel #8
0
UString UDES3::signData(const char* fmt, ...)
{
   U_TRACE(0, "UDES3::signData(%S)", fmt)

   uint32_t sz1;
   UString buffer1(U_CAPACITY), buffer2(U_CAPACITY), signed_data(U_CAPACITY);

   va_list argp;
   va_start(argp, fmt);

   buffer1.vsnprintf(fmt, argp);

   va_end(argp);

   sz1 = buffer1.size();

   if (sz1 <= 512) encode((const unsigned char*)buffer1.data(), sz1, buffer2);
   else
      {
      UString data = UStringExt::compress(buffer1.data(), sz1);
      uint32_t sz2 = data.size();

      if (sz2 < (sz1 - (sz1 / 4))) encode((const unsigned char*)   data.data(), sz2, buffer2);
      else                         encode((const unsigned char*)buffer1.data(), sz1, buffer2);
      }

   UBase64::encode(buffer2, signed_data);

   U_RETURN_STRING(signed_data);
}
Beispiel #9
0
String::String(double rhs)
{
	const int DIFF = '0' - 0;

	int neg = 0;
	if(rhs < 0)
	{
		neg = 1;
		rhs = -rhs;
	}

	Array<char> buffer(8);
	int intPart = (int)rhs;
	while(intPart > 0)
	{
		buffer.insert(intPart % 10);
		intPart = intPart / 10;
	}

	Array<char> buffer2(8);
	double floatPart = rhs - (int)rhs;
	while(floatPart > 0.00001f && floatPart < 1.0f)
	{
		floatPart *= 10.0f;
		// console << floatPart << newline;
		buffer2.insert((char)floatPart);
		floatPart = floatPart - (int)floatPart;
		// console << floatPart << newline;
	}

	this->size = buffer.size() + buffer2.size() + neg;
	if(buffer2.size() != 0)
	{
		this->size++;
	}
	this->array = new char[this->size + 1];

	for(int j = 0; j < buffer.size(); j++)
	{
		this->array[j + neg] = buffer[buffer.size() - j - 1] + DIFF;
	}
	if(buffer2.size() != 0)
	{
		this->array[buffer.size() + neg] = '.';
	}
	for(int j = buffer.size() + neg; j < buffer.size() + buffer2.size(); j++)
	{
		this->array[j + 1] = buffer2[j - buffer.size()] + DIFF;
	}

	if(neg == 1)
	{
		this->array[0] = '-';
	}

	this->array[this->size] = 0x0;
}
Beispiel #10
0
TEST(Channel, read_Buffers) {
  Buffer buffer2(Buffer::getpagesize());
  Buffer buffer1(Buffer::getpagesize());
  buffer1.set_next_buffer(buffer2.inc_ref());
  ssize_t read_ret = MockChannel().read(buffer1);
  ASSERT_EQ(read_ret, static_cast<ssize_t>(Buffer::getpagesize() / 2));
  ASSERT_EQ(buffer1.size(), Buffer::getpagesize() / 2);
  ASSERT_EQ(buffer2.size(), 0);
}
Beispiel #11
0
TEST(Channel, write_Buffers) {
  Buffer buffer2(Buffer::getpagesize());
  buffer2.put(NULL, Buffer::getpagesize() / 4);
  Buffer buffer1(Buffer::getpagesize());
  buffer1.put(NULL, Buffer::getpagesize() / 4);
  buffer1.set_next_buffer(buffer2.inc_ref());
  ssize_t write_ret = MockChannel().write(buffer1);
  ASSERT_EQ(write_ret, static_cast<ssize_t>(Buffer::getpagesize() / 2));
}
Beispiel #12
0
TEST(BufferTest, CopyConstruct) {
  std::string const value("this is a test string");
  Buffer<char> buffer;
  buffer.append(value.c_str(), value.size());

  Buffer<char> buffer2(buffer);
  ASSERT_EQ(value.size(), buffer2.size());
  ASSERT_EQ(buffer.size(), buffer2.size());
  ASSERT_EQ(value, std::string(buffer2.data(), buffer2.size()));
  ASSERT_NE(buffer.data(), buffer2.data());
}
Beispiel #13
0
TEST(BufferTest, MoveConstruct) {
  std::string const value("this is a test string");
  Buffer<char> buffer;
  buffer.append(value.c_str(), value.size());

  Buffer<char> buffer2(std::move(buffer));
  ASSERT_EQ(value.size(), buffer2.size());
  ASSERT_EQ(0UL, buffer.size()); // should be empty
  ASSERT_EQ(value, std::string(buffer2.data(), buffer2.size()));
  ASSERT_NE(buffer.data(), buffer2.data());
}
Beispiel #14
0
TEST(BufferTest, MoveConstructLongValue) {
  std::string const value("this is a test string");
  
  Buffer<char> buffer;
  for (size_t i = 0; i < 1000; ++i) {
    buffer.append(value.c_str(), value.size());
  }

  Buffer<char> buffer2(std::move(buffer));
  ASSERT_EQ(1000 * value.size(), buffer2.size());
  ASSERT_EQ(0UL, buffer.size()); // should be empty
  ASSERT_NE(buffer.data(), buffer2.data());
}
Beispiel #15
0
TEST(BufferTest, CopyConstructLongValue) {
  std::string const value("this is a test string");
  
  Buffer<char> buffer;
  for (size_t i = 0; i < 1000; ++i) {
    buffer.append(value.c_str(), value.size());
  }

  Buffer<char> buffer2(buffer);
  ASSERT_EQ(1000 * value.size(), buffer2.size());
  ASSERT_EQ(buffer.size(), buffer2.size());
  ASSERT_NE(buffer.data(), buffer2.data());
}
bool DataBlobVerify::verifyDeserialise() const {
    _serialise();
    static FactoryGeneric<DataBlob> factory(true);
    DataBlob* copy = factory.create( _blob->type() );
    QByteArray tmp( _buffer.data() );
    QBuffer buffer2( &tmp );
    buffer2.open( QBuffer::ReadOnly );
    copy->deserialise( buffer2, QSysInfo::ByteOrder );
    QBuffer copyBuffer;
    copyBuffer.open(QBuffer::WriteOnly);
    copy->serialise( copyBuffer );
    if( copyBuffer.buffer().size() == 0 ) return false;
    return copyBuffer.buffer() == _buffer.buffer();
}
Beispiel #17
0
bool LineSegment::colinear(const LineSegment& l) const   // lines are colinear if their slopes are the same AND if there is a point they both pass through
{
  if(l.slope() != slope()) return false;

  // assert: lines are the same slope
 
  LineSegment buffer1(l); // to preserve const
  LineSegment buffer2(*this);
  
  if( findIntersection(buffer1, buffer2, true) == noCoord) // check for a point lying on both lines
    return false;

  // assert: we found a point that lies on both lines  
  return true;
}
TEST(CBuffer2D, Arithmetic)
{
  const int64_t cols = 16;
  const int64_t rows = 8;

  CBuffer2D buffer1(cols, rows, Complex(3.0,  4.0));
  CBuffer2D buffer2(cols, rows, Complex(3.0, -4.0));

  CBuffer2D bufferSum1(cols, rows);
  bufferSum1.assign(buffer1 + buffer2);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(6.0, 0.0), bufferSum1.pixel(x, y));

  CBuffer2D bufferSum2(cols, rows);
  bufferSum2.assign(buffer1);
  bufferSum2 += buffer2;
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(6.0, 0.0), bufferSum2.pixel(x, y));

  CBuffer2D bufferProduct1(cols, rows);
  bufferProduct1.assign(buffer1 * buffer2);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(25.0, 0.0), bufferProduct1.pixel(x, y));

  CBuffer2D bufferProduct2(cols, rows);
  bufferProduct2.assign(buffer1);
  bufferProduct2 *= buffer2;
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(25.0, 0.0), bufferProduct2.pixel(x, y));

  CBuffer2D bufferScale1(cols, rows);
  bufferScale1.assign(2.0 * buffer1);
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(6.0, 8.0), bufferScale1.pixel(x, y));

  CBuffer2D bufferScale2(cols, rows);
  bufferScale2.assign(buffer1);
  bufferScale2 *= 0.5;
  for (int64_t y = 0; y < rows; ++y)
    for (int64_t x = 0; x < cols; ++x)
      EXPECT_EQ(Complex(1.5, 2.0), bufferScale2.pixel(x, y));
}
static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed,
                                       skiatest::Reporter* reporter) {
    SkOrderedWriteBuffer writer(1024);
    writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
    SerializationUtils<T>::Write(writer, testObj);
    size_t bytesWritten = writer.bytesWritten();
    REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);

    unsigned char dataWritten[1024];
    SkASSERT(bytesWritten <= sizeof(dataWritten));
    writer.writeToMemory(dataWritten);

    // Make sure this fails when it should (test with smaller size, but still multiple of 4)
    SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
    T* obj = NULL;
    SerializationUtils<T>::Read(buffer, &obj);
    REPORTER_ASSERT(reporter, !buffer.isValid());
    REPORTER_ASSERT(reporter, NULL == obj);

    // Make sure this succeeds when it should
    SkValidatingReadBuffer buffer2(dataWritten, bytesWritten);
    const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2.skip(0));
    T* obj2 = NULL;
    SerializationUtils<T>::Read(buffer2, &obj2);
    const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.skip(0));
    if (shouldSucceed) {
        // This should have succeeded, since there are enough bytes to read this
        REPORTER_ASSERT(reporter, buffer2.isValid());
        REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten);
        REPORTER_ASSERT(reporter, NULL != obj2);
    } else {
        // If the deserialization was supposed to fail, make sure it did
        REPORTER_ASSERT(reporter, !buffer.isValid());
        REPORTER_ASSERT(reporter, NULL == obj2);
    }

    return obj2; // Return object to perform further validity tests on it
}
Beispiel #20
0
QString WebPage::render(const QString &fileName, const QSize &minimumSize) {
  QFileInfo fileInfo(fileName);
  QDir dir;
  dir.mkpath(fileInfo.absolutePath());

  QSize viewportSize = this->viewportSize();
  this->setViewportSize(minimumSize);
  QSize pageSize = this->mainFrame()->contentsSize();
  if (pageSize.isEmpty()) {
    return false;
  }

  QImage buffer(pageSize, QImage::Format_ARGB32);
  buffer.fill(qRgba(255, 255, 255, 0));

  QPainter p(&buffer);
  p.setRenderHint( QPainter::Antialiasing,          true);
  p.setRenderHint( QPainter::TextAntialiasing,      true);
  p.setRenderHint( QPainter::SmoothPixmapTransform, true);

  this->setViewportSize(pageSize);
  this->mainFrame()->render(&p);

  //QImage pointer = QImage(":/pointer.png");
  //p.drawImage(m_mousePosition, pointer);

  p.end();
  this->setViewportSize(viewportSize);

  QByteArray byteArray;
  QBuffer buffer2(&byteArray);
  buffer.save(&buffer2, "PNG");
  QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data());

  buffer.save(fileName);

  return iconBase64;
}
Beispiel #21
0
static void TestArraySerialization(T* data, skiatest::Reporter* reporter) {
    SkBinaryWriteBuffer writer;
    SerializationUtils<T>::Write(writer, data, kArraySize);
    size_t bytesWritten = writer.bytesWritten();
    // This should write the length (in 4 bytes) and the array
    REPORTER_ASSERT(reporter, (4 + kArraySize * sizeof(T)) == bytesWritten);

    unsigned char dataWritten[2048];
    writer.writeToMemory(dataWritten);

    // Make sure this fails when it should
    SkReadBuffer buffer(dataWritten, bytesWritten);
    T dataRead[kArraySize];
    bool success = SerializationUtils<T>::Read(buffer, dataRead, kArraySize / 2);
    // This should have failed, since the provided size was too small
    REPORTER_ASSERT(reporter, !success);

    // Make sure this succeeds when it should
    SkReadBuffer buffer2(dataWritten, bytesWritten);
    success = SerializationUtils<T>::Read(buffer2, dataRead, kArraySize);
    // This should have succeeded, since there are enough bytes to read this
    REPORTER_ASSERT(reporter, success);
}
Beispiel #22
0
void tst_QZip::createArchive()
{
    QBuffer buffer;
    QZipWriter zip(&buffer);
    QByteArray fileContents("simple file contents\nline2\n");
    zip.addFile("My Filename", fileContents);
    zip.close();
    QByteArray zipFile = buffer.buffer();

    // QFile f("createArchiveTest.zip"); f.open(QIODevice::WriteOnly); f.write(zipFile); f.close();

    QBuffer buffer2(&zipFile);
    QZipReader zip2(&buffer2);
    QList<QZipReader::FileInfo> files = zip2.fileInfoList();
    QCOMPARE(files.count(), 1);
    QZipReader::FileInfo file = files.at(0);
    QCOMPARE(file.filePath, QString("My Filename"));
    QCOMPARE(uint(file.isDir), (uint) 0);
    QCOMPARE(uint(file.isFile), (uint) 1);
    QCOMPARE(uint(file.isSymLink), (uint) 0);
    QCOMPARE(file.permissions, QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser) );
    QCOMPARE(file.size, (long long) 27);
    QCOMPARE(zip2.fileData("My Filename"), fileContents);
}
void tableTemplateWidget::printPreview(QPrinter *prn)
{
  if (templateId == 0 && !isMaked)
    return;

  printDoc.clear();
  QTextCursor cursor(&printDoc);

  int pageW = prn->pageRect().width();
  int pageH = prn->pageRect().height();
  int gapH = 20, gapV = 20;

  qreal leftM, rightM, topM, bottomM;
  qreal leftPoint, topPoint;
  prn->getPageMargins(&leftM, &topM, &rightM, &bottomM, QPrinter::Millimeter);

  font.setPointSize(14);
  font.setBold(false);

  int countRecords;

  QPainter painter;
  QImage imagePreview;
  int imageW = 0, imageH = 0;
  QSqlQuery query;

  query.prepare("SELECT _preview FROM crossword.templates WHERE _id = ?;");
  query.addBindValue(QVariant(templateId));
  query.exec();

  painter.begin(prn);
  {
    QString text("Шаблон № %1");
    text = text.arg(templateId);

    painter.setFont(font);
    QFontMetrics fm = painter.fontMetrics();

    leftPoint = leftM;
    topPoint = fm.height() + topM;
    painter.drawText(leftPoint, topPoint, text);

    QSqlError le = query.lastError();
    if (le.type() == QSqlError::NoError)
      {
        if (query.isActive() && query.isSelect())
          countRecords = query.size();
        else
          countRecords = -1;

        if (countRecords > 0)
          {
            int previewNo = query.record().indexOf("_preview");

            QByteArray _ba2;
            QBuffer buffer2(&_ba2);

            query.first();
            _ba2 = query.value(previewNo).toByteArray();

            buffer2.setBuffer(&_ba2);
            buffer2.open(QIODevice::ReadWrite | QIODevice::Unbuffered);

            imagePreview.load(&buffer2, "PNG");
            imageW = imagePreview.width();
            imageH = imagePreview.height();

            if (imageW > pageW || imageH > pageH)
              {
                imagePreview = imagePreview.scaled(QSize(pageW, pageW), Qt::KeepAspectRatio);

                imageW = imagePreview.width();
                imageH = imagePreview.height();
              }

            topPoint += gapH;
            painter.drawImage(QPoint(leftPoint, topPoint), imagePreview);

            //  doc.addResource(QTextDocument::ImageResource, QUrl("image"), QVariant(imagePreview));
            //	cursor.insertImage("image");

            buffer2.close();
          }
      }

    int x = imageW + gapV + leftM;
    int y = topPoint;
    int w = pageW - imageW - gapV - leftM - rightM;
    int h = imageH;

    QRect wordsRect(x, y, w, h);
    painter.drawRect(wordsRect);

    QString res;
    text = "%1.%2; ";

    for (int i = 0; i < wi.count(); i++)
      {
        if (wi[i]->text != "")
          res += text.arg(wi[i]->numWord+1).arg(wi[i]->text);
      }

    painter.drawText(wordsRect, Qt::TextWordWrap, res);
    //	cursor.insertHtml(res);

    x = leftM;
    y = imageH + topPoint + gapH;
    w = pageW - leftM - rightM;
    h = (pageH - y) - (fm.height() + gapH);

    QRect questionsRect(x, y, w, h);
    painter.drawRect(questionsRect);

    text = "<b>%1.</b>%2; ";

    prepareQuestions();

    font.setPointSize(8);
    font.setBold(false);
    printDoc.setDefaultFont(font);

    QRectF clip(0, 0, w, h);
    printDoc.setTextWidth(w);
    cursor.insertHtml(questionsV);
    cursor.insertHtml(questionsH);

    painter.save();
    painter.translate(x, y);
    painter.setFont(font);
    printDoc.drawContents(&painter, clip);
    painter.restore();
  }
  painter.end();
}
void dng_image::GetEdge (dng_pixel_buffer &buffer,
					     edge_option edgeOption,
				         const dng_rect &srcArea,
				         const dng_rect &dstArea) const
	{
	
	switch (edgeOption)
		{
		
		case edge_zero:
			{
			
			buffer.SetZero (dstArea,
							buffer.fPlane,
							buffer.fPlanes);
							
			break;
			
			}
			
		case edge_repeat:
			{
			
			GetRepeat (buffer,
					   srcArea,
					   dstArea);
					   
			break;
						
			}
			
		case edge_repeat_zero_last:
			{
			
			if (buffer.fPlanes > 1)
				{
			
				dng_pixel_buffer buffer1 (buffer);
				
				buffer1.fPlanes--;
				
				GetEdge (buffer1,
						 edge_repeat,
						 srcArea,
						 dstArea);
						 
				}
				
			dng_pixel_buffer buffer2 (buffer);
			
			buffer2.fPlane  = buffer.fPlanes - 1;
			buffer2.fPlanes = 1;
			
			buffer2.fData = buffer.DirtyPixel (buffer2.fArea.t,
										  	   buffer2.fArea.l,
										  	   buffer2.fPlane);
										  
			GetEdge (buffer2,
					 edge_zero,
					 srcArea,
					 dstArea);
					 
			break;
			
			}
			
		default:
			{
			
			ThrowProgramError ();
			
			}
			
		}
	
	}
Beispiel #25
0
QByteArray AVDecoder::WriteJPEG(AVCodecContext *pCodecCtx, AVFrame *pFrame, int width, int height)
{
    AVCodecContext *pOCodecCtx;
    AVCodec        *pOCodec;

    QByteArray data;

    pOCodec = avcodec_find_encoder(AV_CODEC_ID_MJPEG);

    if (!pOCodec) {
        return data;
    }

    SwsContext *sws_ctx = sws_getContext(
                pCodecCtx->width, pCodecCtx->height,
                pCodecCtx->pix_fmt,
                width, height,
                PIX_FMT_YUVJ420P, SWS_BICUBIC,
                NULL, NULL, NULL);

    if(!sws_ctx) {
        return data;
    }

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
    AVFrame *pFrameRGB = av_frame_alloc();
#else
    AVFrame *pFrameRGB = avcodec_alloc_frame();
#endif

    if(pFrameRGB == NULL) {
        sws_freeContext(sws_ctx);
        return data;
    }

    int numBytes = avpicture_get_size(PIX_FMT_YUVJ420P, width, height);

    uint8_t *buffer = (uint8_t *)av_malloc(numBytes);

    if(!buffer) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
        av_frame_free(&pFrameRGB);
#else
        av_free(pFrameRGB);
#endif
        sws_freeContext(sws_ctx);
        return data;
    }

    avpicture_fill((AVPicture *)pFrameRGB, buffer, PIX_FMT_YUVJ420P, width, height);

    sws_scale(
        sws_ctx,
        pFrame->data,
        pFrame->linesize,
        0,
        pCodecCtx->height,
        pFrameRGB->data,
        pFrameRGB->linesize
    );

    pOCodecCtx = avcodec_alloc_context3(pOCodec);

    if(pOCodecCtx == NULL) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,52,0)
        avcodec_free_context(&pOCodecCtx);
#else
        avcodec_close(pOCodecCtx);
        av_free(pOCodecCtx);
#endif
        av_free(buffer);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
        av_frame_free(&pFrameRGB);
#else
        av_free(&pFrameRGB);
#endif
        sws_freeContext(sws_ctx);
        return  0;
    }

    pOCodecCtx->bit_rate      = pCodecCtx->bit_rate;
    pOCodecCtx->width         = width;
    pOCodecCtx->height        = height;
    pOCodecCtx->pix_fmt       = AV_PIX_FMT_YUVJ420P;
    pOCodecCtx->codec_id      = AV_CODEC_ID_MJPEG;
    pOCodecCtx->codec_type    = AVMEDIA_TYPE_VIDEO;
    pOCodecCtx->time_base.num = pCodecCtx->time_base.num;
    pOCodecCtx->time_base.den = pCodecCtx->time_base.den;

    AVDictionary *opts = NULL;
    if(avcodec_open2(pOCodecCtx, pOCodec, &opts) < 0) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,52,0)
        avcodec_free_context(&pOCodecCtx);
#else
        avcodec_close(pOCodecCtx);
        av_free(pOCodecCtx);
#endif
        av_free(buffer);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
        av_frame_free(&pFrameRGB);
#else
        av_free(&pFrameRGB);
#endif
        sws_freeContext(sws_ctx);
         return  0;
    }

    pOCodecCtx->mb_lmin        = pOCodecCtx->lmin = pOCodecCtx->qmin * FF_QP2LAMBDA;
    pOCodecCtx->mb_lmax        = pOCodecCtx->lmax = pOCodecCtx->qmax * FF_QP2LAMBDA;
    pOCodecCtx->flags          = CODEC_FLAG_QSCALE;
    pOCodecCtx->global_quality = pOCodecCtx->qmin * FF_QP2LAMBDA;

    pFrame->pts     = 1;
    pFrame->quality = pOCodecCtx->global_quality;

    AVPacket pkt;
    av_init_packet(&pkt);
    pkt.data = NULL;
    pkt.size = 0;

    int gotPacket;

    avcodec_encode_video2(pOCodecCtx, &pkt, pFrameRGB, &gotPacket);

    QByteArray buffer2(reinterpret_cast<char *>(pkt.data), pkt.size);

#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,52,0)
        avcodec_free_context(&pOCodecCtx);
#else
        avcodec_close(pOCodecCtx);
        av_free(pOCodecCtx);
#endif
    av_free(buffer);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
    av_frame_free(&pFrameRGB);
#else
    av_free(&pFrameRGB);
#endif
    avcodec_close(pOCodecCtx);
    sws_freeContext(sws_ctx);

    return buffer2;
}
Beispiel #26
0
void ApplicationManager::playFiles(const char* pfile,const char *lfile) {


	//setting properties
	const char* propfilename = g_pathForFile(pfile);
	FILE* fis_prop = fopen(propfilename, "rb");

	const char* luafilename = g_pathForFile(lfile);
	FILE* fis_lua = fopen(luafilename, "rb");

	if (fis_prop != NULL && fis_lua != NULL) {

		fseek(fis_prop, 0, SEEK_END);
		int len = ftell(fis_prop);
		fseek(fis_prop, 0, SEEK_SET);

		std::vector<char> buf_prop(len);
		fread(&buf_prop[0], 1, len, fis_prop);
		fclose(fis_prop);

		ProjectProperties properties;

		ByteBuffer buffer(&buf_prop[0], buf_prop.size());

		char chr;
		buffer >> chr;

		buffer >> properties.scaleMode;
		buffer >> properties.logicalWidth;
		buffer >> properties.logicalHeight;

		int scaleCount;
		buffer >> scaleCount;
		properties.imageScales.resize(scaleCount);
		for (int i = 0; i < scaleCount; ++i) {
			buffer >> properties.imageScales[i].first;
			buffer >> properties.imageScales[i].second;
		}

		buffer >> properties.orientation;
		buffer >> properties.fps;
		buffer >> properties.retinaDisplay;
		buffer >> properties.autorotation;
		buffer >> properties.mouseToTouch;
		buffer >> properties.touchToMouse;
		buffer >> properties.mouseTouchOrder;

		setProjectProperties(properties);

		//loading lua files
		std::vector<std::string> luafiles;

		const char* luafilename = g_pathForFile(lfile);
		FILE* fis_lua = fopen(luafilename, "rb");

		fseek(fis_lua, 0, SEEK_END);
		len = ftell(fis_lua);
		fseek(fis_lua, 0, SEEK_SET);

		std::vector<char> buf_lua(len);
		fread(&buf_lua[0], 1, len, fis_lua);
		fclose(fis_lua);

		ByteBuffer buffer2(&buf_lua[0], buf_lua.size());

		buffer2 >> chr;

		while (buffer2.eob() == false) {
			std::string str;
			buffer2 >> str;
			luafiles.push_back(str);
		}

		play(luafiles);
	}
Beispiel #27
0
//Lecture du fichier DIMAP
Dimap::Dimap(std::string const &filename)
{
    direct_samp_num_coef.clear();
    direct_samp_den_coef.clear();
    direct_line_num_coef.clear();
    direct_line_den_coef.clear();

    indirect_samp_num_coef.clear();
    indirect_samp_den_coef.clear();
    indirect_line_num_coef.clear();
    indirect_line_den_coef.clear();

    cElXMLTree tree(filename.c_str());

    {
        std::list<cElXMLTree*> noeuds=tree.GetAll(std::string("Direct_Model"));
        std::list<cElXMLTree*>::iterator it_grid,fin_grid=noeuds.end();


        std::string coefSampN="SAMP_NUM_COEFF";
        std::string coefSampD="SAMP_DEN_COEFF";
        std::string coefLineN="LINE_NUM_COEFF";
        std::string coefLineD="LINE_DEN_COEFF";

        for (int c=1; c<21;c++)
        {
            std::stringstream ss;
            ss<<"_"<<c;
            coefSampN.append(ss.str());
            coefSampD.append(ss.str());
            coefLineN.append(ss.str());
            coefLineD.append(ss.str());
            for(it_grid=noeuds.begin();it_grid!=fin_grid;++it_grid)
            {
                double value;
                std::istringstream buffer((*it_grid)->GetUnique(coefSampN.c_str())->GetUniqueVal());
                buffer >> value;
                direct_samp_num_coef.push_back(value);
                std::istringstream buffer2((*it_grid)->GetUnique(coefSampD.c_str())->GetUniqueVal());
                buffer2 >> value;
                direct_samp_den_coef.push_back(value);
                std::istringstream buffer3((*it_grid)->GetUnique(coefLineN.c_str())->GetUniqueVal());
                buffer3 >> value;
                direct_line_num_coef.push_back(value);
                std::istringstream buffer4((*it_grid)->GetUnique(coefLineD.c_str())->GetUniqueVal());
                buffer4 >> value;
                direct_line_den_coef.push_back(value);
            }
            coefSampN=coefSampN.substr(0,14);
            coefSampD=coefSampD.substr(0,14);
            coefLineN=coefLineN.substr(0,14);
            coefLineD=coefLineD.substr(0,14);
        }
        for(it_grid=noeuds.begin();it_grid!=fin_grid;++it_grid)
        {
            std::istringstream buffer((*it_grid)->GetUnique("ERR_BIAS_X")->GetUniqueVal());
            buffer >> dirErrBiasX;
            std::istringstream bufferb((*it_grid)->GetUnique("ERR_BIAS_Y")->GetUniqueVal());
            bufferb >> dirErrBiasY;
        }
    }

    {
        std::list<cElXMLTree*> noeudsInv=tree.GetAll(std::string("Inverse_Model"));
        std::list<cElXMLTree*>::iterator it_gridInd,fin_gridInd=noeudsInv.end();

        std::string coefSampN="SAMP_NUM_COEFF";
        std::string coefSampD="SAMP_DEN_COEFF";
        std::string coefLineN="LINE_NUM_COEFF";
        std::string coefLineD="LINE_DEN_COEFF";

        for (int c=1; c<21;c++)
        {
            double value;
            std::stringstream ss;
            ss<<"_"<<c;
            coefSampN.append(ss.str());
            coefSampD.append(ss.str());
            coefLineN.append(ss.str());
            coefLineD.append(ss.str());
            for(it_gridInd=noeudsInv.begin();it_gridInd!=fin_gridInd;++it_gridInd)
            {
                std::istringstream bufferInd((*it_gridInd)->GetUnique(coefSampN.c_str())->GetUniqueVal());
                bufferInd >> value;
                indirect_samp_num_coef.push_back(value);
                std::istringstream bufferInd2((*it_gridInd)->GetUnique(coefSampD.c_str())->GetUniqueVal());
                bufferInd2 >> value;
                indirect_samp_den_coef.push_back(value);
                std::istringstream bufferInd3((*it_gridInd)->GetUnique(coefLineN.c_str())->GetUniqueVal());
                bufferInd3 >> value;
                indirect_line_num_coef.push_back(value);
                std::istringstream bufferInd4((*it_gridInd)->GetUnique(coefLineD.c_str())->GetUniqueVal());
                bufferInd4 >> value;
                indirect_line_den_coef.push_back(value);
            }
            coefSampN=coefSampN.substr(0,14);
            coefSampD=coefSampD.substr(0,14);
            coefLineN=coefLineN.substr(0,14);
            coefLineD=coefLineD.substr(0,14);
        }
        for(it_gridInd=noeudsInv.begin();it_gridInd!=fin_gridInd;++it_gridInd)
        {
            std::istringstream buffer((*it_gridInd)->GetUnique("ERR_BIAS_ROW")->GetUniqueVal());
            buffer >> indirErrBiasRow;
            std::istringstream bufferb((*it_gridInd)->GetUnique("ERR_BIAS_COL")->GetUniqueVal());
            bufferb >> indirErrBiasCol;
        }
    }

    {
        std::list<cElXMLTree*> noeudsRFM=tree.GetAll(std::string("RFM_Validity"));
        std::list<cElXMLTree*>::iterator it_gridRFM,fin_gridRFM=noeudsRFM.end();

        {
            std::list<cElXMLTree*> noeudsInv=tree.GetAll(std::string("Direct_Model_Validity_Domain"));
            std::list<cElXMLTree*>::iterator it_gridInd,fin_gridInd=noeudsInv.end();


            for(it_gridInd=noeudsInv.begin();it_gridInd!=fin_gridInd;++it_gridInd)
            {
                std::istringstream bufferInd((*it_gridInd)->GetUnique("FIRST_ROW")->GetUniqueVal());
                bufferInd >> first_row;
                std::istringstream bufferInd2((*it_gridInd)->GetUnique("FIRST_COL")->GetUniqueVal());
                bufferInd2 >> first_col;
                std::istringstream bufferInd3((*it_gridInd)->GetUnique("LAST_ROW")->GetUniqueVal());
                bufferInd3 >> last_row;
                std::istringstream bufferInd4((*it_gridInd)->GetUnique("LAST_COL")->GetUniqueVal());
                bufferInd4 >> last_col;
            }
        }


        {
            std::list<cElXMLTree*> noeudsInv=tree.GetAll(std::string("Inverse_Model_Validity_Domain"));
            std::list<cElXMLTree*>::iterator it_gridInd,fin_gridInd=noeudsInv.end();

            for(it_gridInd=noeudsInv.begin();it_gridInd!=fin_gridInd;++it_gridInd)
            {
                std::istringstream bufferInd((*it_gridInd)->GetUnique("FIRST_LON")->GetUniqueVal());
                bufferInd >> first_lon;
                std::istringstream bufferInd2((*it_gridInd)->GetUnique("FIRST_LAT")->GetUniqueVal());
                bufferInd2 >> first_lat;
                std::istringstream bufferInd3((*it_gridInd)->GetUnique("LAST_LON")->GetUniqueVal());
                bufferInd3 >> last_lon;
                std::istringstream bufferInd4((*it_gridInd)->GetUnique("LAST_LAT")->GetUniqueVal());
                bufferInd4 >> last_lat;
            }
        }
        for(it_gridRFM=noeudsRFM.begin();it_gridRFM!=fin_gridRFM;++it_gridRFM)
        {
            std::istringstream buffer((*it_gridRFM)->GetUnique("LONG_SCALE")->GetUniqueVal());
            buffer>> long_scale;
            std::istringstream buffer2((*it_gridRFM)->GetUnique("LONG_OFF")->GetUniqueVal());
            buffer2 >> long_off;
            std::istringstream buffer3((*it_gridRFM)->GetUnique("LAT_SCALE")->GetUniqueVal());
            buffer3 >> lat_scale;
            std::istringstream buffer4((*it_gridRFM)->GetUnique("LAT_OFF")->GetUniqueVal());
            buffer4 >> lat_off;
            std::istringstream buffer5((*it_gridRFM)->GetUnique("HEIGHT_SCALE")->GetUniqueVal());
            buffer5 >> height_scale;
            std::istringstream buffer6((*it_gridRFM)->GetUnique("HEIGHT_OFF")->GetUniqueVal());
            buffer6 >> height_off;
            std::istringstream buffer7((*it_gridRFM)->GetUnique("SAMP_SCALE")->GetUniqueVal());
            buffer7 >> samp_scale;
            std::istringstream buffer8((*it_gridRFM)->GetUnique("SAMP_OFF")->GetUniqueVal());
            buffer8 >> samp_off;
            std::istringstream buffer9((*it_gridRFM)->GetUnique("LINE_SCALE")->GetUniqueVal());
            buffer9 >> line_scale;
            std::istringstream buffer10((*it_gridRFM)->GetUnique("LINE_OFF")->GetUniqueVal());
            buffer10 >> line_off;
        }
    }
}
Beispiel #28
0
void parseConfigFile (char * fname )
  // This functions reads in the configuration file to set up some run-time
  // parameters. The parameters are global variables that are defined in 
  // main.cc and used all over the place in the program
  // The format of the configuration file can be explained in the following way
  // FORMAT:
  // the character '\n' separates lines ..
  // lines that start with "//" (skipping over white spaces are considered 
  // as comments and will be ignored.
  // Any other line is considered as an attribute setting instruction and it 
  // is divided into haves (separated by a colon ":"). The first half is the
  // attribute value which consists of the concatenation of all non-white space
  // tokens before the colon. These tokens will have spaces eseparating them.
  // The attribute vlue is the first token after the colon (any thing after 
  // it will be ignored ;
  // For example :
  // if the configuration file has the following entry:
  //
  // NO.   ITERATIONS   MODEL 2 :	10
  //
  // then the attribute is "NO. ITERATIONS MODEL 2" , and the attribute value
  // is "10"  (these do not include the quotation marks).

{

  string line, word, attrib, attribval ;
  ifstream Config_File(fname);
  if(!Config_File){
    cerr << "ERROR:  Cannot open configuration file " << fname << "!\n" ;
    exit(1);
  }

  cout << "The following options are from the config file and will be overwritten by any command line options.\n";
  
  while(getline(Config_File, line)){

    istrstream buffer(line.c_str());
    word = attrib = attribval = "" ;
    buffer >> word  ;
    if (word != "//"){ // if line does not start with "//" (i.e. not a comment)
      attrib = word ;
      while((buffer >> word) && (word != ":")){
	attrib += " " + word ;
      }      
      if(!(buffer >> attribval))
	{
	  istrstream buffer2(line.c_str());
	  buffer2>>attrib;
	  buffer2>>attribval;
	}

      // This# is where (1) the configuration file is defined and
      //               (2) parsing of its attributes occurs.
      
      if(attrib == "t FILE"){
	t_Filename = attribval;
	cout << "\tt file:  " << t_Filename << '\n';
      }
      else if(attrib ==  "a FILE"){
	a_Filename = attribval;
	cout << "\ta file:  " << a_Filename << '\n';
      }
      else if(attrib == "d FILE"){
	d_Filename = attribval;
	cout << "\td file:  " << d_Filename << '\n';
      }
      else if(attrib == "n FILE"){
	n_Filename = attribval;
	cout << "\tn file:  " << n_Filename << '\n';
      }
      else if(attrib == "p0 FILE"){
	p0_Filename = attribval;
	cout << "\tp0 file:  " << p0_Filename << '\n';
      }
      else if ( line == ""){}
      else if(  !makeSetCommand(attrib,attribval,getGlobalParSet(),2) )
	cerr << "ERROR: Unrecognized attribute :" << attrib << '\n';
    }
  }
Beispiel #29
0
void MainWindow::loadListPreview(void)
{
  QListWidgetItem *lw;
  QImage *imagePreview;
  QImage scaledPreview;

  QSize s(200, 200); // = ui->listWidget->sizeHint();

  QSqlQuery query;
  query.prepare("SELECT _id, _preview FROM crossword.templates;");
  query.exec();

  int countRecord;
  QSqlError le = query.lastError();
  if (le.type() == QSqlError::NoError)
    {
      if (query.isActive() && query.isSelect())
        countRecord = query.size();
      else
        countRecord= -1;

      if (countRecord> 0)
        {
          int idNo = query.record().indexOf("_id");
          int previewNo = query.record().indexOf("_preview");

          int _id;
          QByteArray _ba2;
          QBuffer buffer2(&_ba2);

          while (query.next())
            {
              _id = query.value(idNo).toInt();
              _ba2 = query.value(previewNo).toByteArray();

              buffer2.setBuffer(&_ba2);
              buffer2.open(QIODevice::ReadWrite | QIODevice::Unbuffered);

              imagePreview = new QImage();
              imagePreview->load(&buffer2, "PNG");

              lw = new QListWidgetItem(ui->listWidget);

              if (lw)
                {
                  if (imagePreview)
                    {
                      scaledPreview = imagePreview->scaled(s, Qt::KeepAspectRatio, Qt::FastTransformation);

                      lw->setData(Qt::UserRole, QVariant(_id));
                      lw->setData(Qt::DecorationRole, QVariant(scaledPreview));

                      ui->listWidget->addItem(lw);
                    }
                }

              buffer2.close();
            }
        }
    }
  else
    qDebug() << "loadListPreview: " << le.text();
}
void ThemeCreationWizard::onFinished(int status)
{
    if (status == 0)
        return;
    try
    {
        StfsPackage *theme = new StfsPackage(ui->lblSavePath->text().toStdString(), StfsPackageCreate);

        // create a new file
        theme->metaData->magic = CON;
        theme->metaData->certificate.ownerConsoleType = consoleType;
        theme->metaData->certificate.consoleTypeFlags = (ConsoleTypeFlags)0;

        theme->metaData->contentType = Theme;
        theme->metaData->metaDataVersion = 2;
        theme->metaData->titleID = 0xFFFE07D1;

        // had to do some glitch hacks in order to get this to work. If I don't do this, the OS gives an 'Unknown Signal'
        std::wstring *w = new std::wstring(ui->txtName->text().toStdWString());
        memcpy(&theme->metaData->displayName, w, sizeof(std::wstring));

        theme->metaData->transferFlags = 0x40;

        // set gamerpicture
        QByteArray ba1;
        QBuffer buffer1(&ba1);
        buffer1.open(QIODevice::WriteOnly);
        ui->imgThumbnail->pixmap()->save(&buffer1, "PNG");
        theme->metaData->thumbnailImage = (BYTE*)ba1.data();
        theme->metaData->thumbnailImageSize = ba1.length();

        // set title thumbnail image
        QByteArray ba2;
        QBuffer buffer2(&ba2);
        buffer2.open(QIODevice::WriteOnly);
        QPixmap(":/Images/defaultTitleImage.png").save(&buffer2, "PNG");
        theme->metaData->titleThumbnailImage = (BYTE*)ba2.data();
        theme->metaData->titleThumbnailImageSize = ba2.length();

        theme->metaData->WriteMetaData();
        theme->Rehash();

        // inject the wallpapers
        injectImage(theme, &wallpaper1, "Wallpaper1");
        injectImage(theme, &wallpaper2, "Wallpaper2");
        injectImage(theme, &wallpaper3, "Wallpaper3");
        injectImage(theme, &wallpaper4, "Wallpaper4");

        // create the parameters.ini file
        QString paramsFilePath = QDir::tempPath() + "/" + QUuid::createUuid().toString().replace("{", "").replace("}", "").replace("-", "");
        QFile params(paramsFilePath);
        params.open(QIODevice::Truncate | QIODevice::WriteOnly);

        // Write the correct information to it
        QTextStream txtStream(&params);
        txtStream << "SphereColor=" << ui->cmbxSphereColor->currentIndex() << "\r\nAvatarLightingDirectional=0,0,0,0\r\nAvatarLightingAmbient=0\r\n";

        // close the file
        txtStream.flush();
        params.close();

        // inject the params file to the theme package
        theme->InjectFile(paramsFilePath.toStdString(), "parameters.ini");

        // create the dash style file
        QString dashStyleFilePath = QDir::tempPath() + "/" + QUuid::createUuid().toString().replace("{", "").replace("}", "").replace("-", "");
        FileIO ioD(dashStyleFilePath.toStdString(), true);
        ioD.Write((DWORD)0);
        ioD.Close();

        // inject the file
        theme->InjectFile(dashStyleFilePath.toStdString(), "DashStyle");

        // fix the package
        theme->Rehash();
        theme->Resign(QtHelpers::GetKVPath(theme->metaData->certificate.ownerConsoleType, this));

        // delete the temp files
        QFile::remove(paramsFilePath);
        QFile::remove(dashStyleFilePath);

        statusBar->showMessage("Theme created successfully", 3000);

        delete theme;
    }
    catch (string error)
    {
        QMessageBox::critical(this, "Error", "An error occured while creating the theme.\n\n" + QString::fromStdString(error));
    }
}