Ejemplo n.º 1
0
void UpdateDialog::setAvailableReleases(const QList<AvailableRelease *> & availableReleases) 
{
	AvailableRelease * interimRelease = NULL;
	AvailableRelease * mainRelease = NULL;

	foreach (AvailableRelease * availableRelease, availableReleases) {
		if (availableRelease->interim && (interimRelease == NULL)) {
			interimRelease = availableRelease;
			continue;
		}
		if (!availableRelease->interim && (mainRelease == NULL)) {
			mainRelease = availableRelease;
			continue;
		}

		if (mainRelease != NULL && interimRelease != NULL) break;
	}

	if (mainRelease == NULL && interimRelease == NULL) {
		if (m_atUserRequest) {
			m_feedbackLabel->setText(tr("No new versions found."));
		}
		return;
	}

	QSettings settings;
	QString style;
	QFile css(":/resources/styles/updatedialog.css");
	if (css.open(QIODevice::ReadOnly)) {
		style = css.readAll();
		css.close();
	}

	QString text = QString("<html><head><style type='text/css'>%1</style></head><body>").arg(style);
			
	if (mainRelease) {
		text += genTable(tr("A new main release is available for downloading:"), mainRelease);
		settings.setValue("lastMainVersionChecked", mainRelease->versionString);
	}
	if (interimRelease) {
		text += genTable(tr("A new interim release is available for downloading:"), interimRelease);
		settings.setValue("lastInterimVersionChecked", interimRelease->versionString);
	}

	text += "</body></html>";

	m_feedbackLabel->setText(text);

	this->show();

}
Ejemplo n.º 2
0
TEST_F(EventsDatabaseTests, test_gentable) {
  auto sub = std::make_shared<DBFakeEventSubscriber>();
  // Lie about the tool type to enable optimizations.
  auto default_type = kToolType;
  kToolType = OSQUERY_TOOL_DAEMON;
  ASSERT_EQ(sub->optimize_time_, 0U);
  ASSERT_EQ(sub->expire_time_, 0U);

  sub->testAdd(getUnixTime() - 1);
  sub->testAdd(getUnixTime());
  sub->testAdd(getUnixTime() + 1);

  // Test the expire workflow by creating a short expiration time.
  FLAGS_events_expiry = 10;

  std::vector<std::string> keys;
  scanDatabaseKeys("events", keys);
  EXPECT_GT(keys.size(), 10U);

  // Perform a "select" equivalent.
  QueryContext context;
  auto results = sub->genTable(context);

  // Expect all non-expired results: 11, +
  EXPECT_EQ(results.size(), 9U);
  // The expiration time is now - events_expiry.
  EXPECT_GT(sub->expire_time_, getUnixTime() - (FLAGS_events_expiry * 2));
  EXPECT_LT(sub->expire_time_, getUnixTime());
  // The optimize time will be changed too.
  ASSERT_GT(sub->optimize_time_, 0U);
  // Restore the tool type.
  kToolType = default_type;

  results = sub->genTable(context);
  EXPECT_EQ(results.size(), 3U);

  results = sub->genTable(context);
  EXPECT_EQ(results.size(), 3U);

  // The optimize time should have been written to the database.
  // It should be the same as the current (relative) optimize time.
  std::string content;
  getDatabaseValue("events", "optimize.DBFakePublisher.DBFakeSubscriber",
                   content);
  EXPECT_EQ(std::to_string(sub->optimize_time_), content);

  keys.clear();
  scanDatabaseKeys("events", keys);
  EXPECT_LT(keys.size(), 30U);
}
table & result::curTable()
{
	if(resultTables.size() == 0)
		genTable();

	return resultTables[resultTables.size() - 1];
}
Ejemplo n.º 4
0
QImage combine(QList<QImage> images) {
    if (images.length() == 1) return images.first();
    genTable();
    QSize size = images[0].size();
    const int width = size.width();
    const int height = size.height();
    QImage ret(size, QImage::Format_ARGB32_Premultiplied);
    for (int y = 0; y < height; ++y) {
        uchar* __restrict q = ret.scanLine(y);
        for (int x = 0; x < width; ++x) {
            u32 sum[4] = {0};
            foreach (const QImage& img, images) {
                QRgb rgb = img.pixel(x, y);
                sum[0] += rgb & 0xFFu;
                sum[1] += (rgb >> 8u) & 0xFFu;
                sum[2] += (rgb >> 16u) & 0xFFu;
                sum[3] += (rgb >> 24u) & 0xFFu;
            }
            const u32 multiplier = table[std::max(sum[3], u32(255u))];
#define PROCESS_PIXEL(i) *q++ = (uchar) ((u64(sum[i] * 255u) * multiplier) >> 32);
            PROCESS_PIXEL(0) PROCESS_PIXEL(1) PROCESS_PIXEL(2)
#undef PROCESS_PIXEL
            *q++ = (u8) std::min(sum[3], u32(255u));
        }
    }
Ejemplo n.º 5
0
TEST_F(EventsDatabaseTests, test_expire_check) {
  auto sub = std::make_shared<DBFakeEventSubscriber>();
  // Set the max number of buffered events to something reasonably small.
  FLAGS_events_max = 10;
  auto t = 10000;

  // We are still at the mercy of the opaque EVENTS_CHECKPOINT define.
  for (size_t x = 0; x < 3; x++) {
    size_t num_events = 256 * x;
    for (size_t i = 0; i < num_events; i++) {
      sub->testAdd(t++);
    }

    // Since events tests are dependent, expect 257 + 3 events.
    QueryContext context;
    auto results = sub->genTable(context);
    if (x == 0) {
      // The first iteration is dependent on previous test state.
      continue;
    }

    // The number of events should remain constant.
    // In practice there may be an event still in the write queue.
    EXPECT_LT(results.size(), 60U);
  }

  // Try again, this time with a scan
  for (size_t k = 0; k < 3; k++) {
    for (size_t x = 0; x < 3; x++) {
      size_t num_events = 256 * x;
      for (size_t i = 0; i < num_events; i++) {
        sub->testAdd(t++);
      }

      // Records hold the event_id + time indexes.
      // Data hosts the event_id + JSON content.
      auto record_key = "records." + sub->dbNamespace();
      auto data_key = "data." + sub->dbNamespace();

      std::vector<std::string> records, datas;
      scanDatabaseKeys(kEvents, records, record_key);
      scanDatabaseKeys(kEvents, datas, data_key);

      EXPECT_LT(records.size(), 20U);
      EXPECT_LT(datas.size(), 60U);
    }
  }
}
Ejemplo n.º 6
0
/// generation of 
int main(int argc, const char ** argv)
{
    if ( argc<2 ) {
	printf("USAGE: gammagen <filename>\n");
	return -1;
    }
    const char * filename = argv[1];
    FILE * out = fopen(filename, "wt");
    if ( !out ) {
	printf("Cannot create file %s\n", filename);
	return -1;
    }
    fprintf(out, "// Gamma tables for using with freetype\n");
    fprintf(out, "// don't edit: this file is generated by crengine/Tools/GammaGen/gammagen.cpp\n");
    fprintf(out, "// to rebuild, run crengine/Tools/GammaGen/gen.sh\n");
    fprintf(out, "// \n");
    fprintf(out, "#define GAMMA_LEVELS %d\n", GAMMA_LEVELS);
    fprintf(out, "\n\n");
    
    fprintf(out, "// gamma correction tables, 0..%d\n", GAMMA_LEVELS-1);
    fprintf(out, "extern const unsigned char * cr_gamma_tables[GAMMA_LEVELS];\n");
    fprintf(out, "// gamma correction levels table 0..%d\n", GAMMA_LEVELS-1);
    fprintf(out, "extern const double cr_gamma_levels[GAMMA_LEVELS];\n");
    fprintf(out, "// corrects gamma for value 0..255, gamma_index must be 0..%d (%d means no correction)\n", GAMMA_LEVELS-1, GAMMA_LEVELS/2);
    fprintf(out, "inline unsigned char cr_correct_gamma( unsigned char value, int gamma_index ) { return cr_gamma_tables[gamma_index][value]; } \n");
    fprintf(out, "// corrects gamma for byte buffer; gamma_index must be 0..%d (%d means no correction)\n", GAMMA_LEVELS-1, GAMMA_LEVELS/2);
    fprintf(out, "void cr_correct_gamma_buf( unsigned char * buf, int size, int gamma_index );\n");
    fprintf(out, "\n\n");
         
    fprintf(out, "#ifdef GAMMA_TABLES_IMPL\n");
    
    int i;
    for ( i=0; i<GAMMA_LEVELS; i++ ) {
	genTable(out, gamma_levels[i], i);
    }
    fprintf(out, "\n");
    fprintf(out, "const unsigned char * cr_gamma_tables[GAMMA_LEVELS] = {\n");
    for ( i=0; i<GAMMA_LEVELS; i++ ) {
        fprintf(out, "    gamma_table_%d, // %f \n", i, gamma_levels[i]);
    }
    fprintf(out, "};\n\n");
    fprintf(out, "\n");
    fprintf(out, "const double cr_gamma_levels[GAMMA_LEVELS] = {\n");
    for ( i=0; i<GAMMA_LEVELS; i++ ) {
        fprintf(out, "    %f,\n", gamma_levels[i]);
    }
    fprintf(out, "};\n\n");

    fprintf(out, "// corrects gamma for byte buffer; gamma_index must be 0..%d (%d means no correction)\n", GAMMA_LEVELS-1, GAMMA_LEVELS/2);
    fprintf(out, "void cr_correct_gamma_buf( unsigned char * buf, int size, int gamma_index ) {\n"
                 "    const unsigned char * table = cr_gamma_tables[gamma_index];\n"
                 "    for ( int i=0; i<size; i++ )\n"
                 "        buf[i] = table[buf[i]];\n"
                 "}\n");
 
    fprintf(out, "\n#endif\n");
    

    fclose(out);
    return 0;
}
Ejemplo n.º 7
0
	0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,
	0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
	};

/* Declare a table for performing 90 degree bitmap rotations */

#define	genTable(n)															\
	{	0x00000000UL<<n,0x00000001UL<<n,0x00000100UL<<n,0x00000101UL<<n,	\
		0x00010000UL<<n,0x00010001UL<<n,0x00010100UL<<n,0x00010101UL<<n,	\
		0x01000000UL<<n,0x01000001UL<<n,0x01000100UL<<n,0x01000101UL<<n,	\
		0x01010000UL<<n,0x01010001UL<<n,0x01010100UL<<n,0x01010101UL<<n,	\
	}

/* {secret} */
ulong _MGL_rotTable[8][16] = {
	genTable(0),
	genTable(1),
	genTable(2),
	genTable(3),
	genTable(4),
	genTable(5),
	genTable(6),
	genTable(7),
	};

/* Define macros to extract part of the 32 bit result from the tables */

#define	extract(n)						\
	lo |= _MGL_rotTable[n][*src & 0xF];	\
	hi |= _MGL_rotTable[n][*src >> 4];	\
	src += srcStep