void StorageSystemFunctions::fillData(MutableColumns & res_columns, const Context &, const SelectQueryInfo &) const
{
    const auto & functions_factory = FunctionFactory::instance();
    const auto & function_names = functions_factory.getAllRegisteredNames();
    for (const auto & name : function_names)
    {
        fillRow(res_columns, name, UInt64(0), functions_factory);
    }

    const auto & aggregate_functions_factory = AggregateFunctionFactory::instance();
    const auto & aggregate_function_names = aggregate_functions_factory.getAllRegisteredNames();
    for (const auto & name : aggregate_function_names)
    {
        fillRow(res_columns, name, UInt64(1), aggregate_functions_factory);
    }
}
int StockTable::addStock(Stock *stock)
{
    int row = rowCount();
    insertRow(row);
    fillRow(row, stock);
    return row;
}
Exemple #3
0
void storeMats(int** A, int **B){
	
	char *line = NULL;
	size_t s = 0;
	int r = 0;
	int firstMat = 1;
    while( getline(&line, &s, stdin) != -1 ){
		if(strcmp(line,"\n") == 0){
			r = 0;
			firstMat = 0;
		}else{
	
			if(firstMat){
				fillRow(A[r], line);
			}else{
				fillRow(B[r], line);
			}
			r++;
		}
	}
	free(line);

}
Exemple #4
0
int main(int argc, char *argv[]) {
    arrXLen=sizeof(workField[0])/sizeof(char);
    arrYLen=(sizeof(workField)/sizeof(char))/arrXLen;

    fillRow();

    while(main) {
        system("clear");
        gen++;
        printf("Generation %d\n",gen);
        printField();
        copyField();
        calcField();
        sleep(1);
    }
}
Exemple #5
0
u32 CGUIProfiler::addDataToTable(u32 rowIndex, u32 dataIndex, u32 groupIndex)
{
	const SProfileData& data = Profiler->getProfileDataByIndex(dataIndex);
	if ( data.getGroupIndex() == groupIndex
		&& data.getCallsCounter() >= MinCalls
		&& ( data.getCallsCounter() == 0 ||
			(data.getTimeSum() >= MinTimeSum &&
			 (f32)data.getTimeSum()/(f32)data.getCallsCounter() >= MinTimeAverage &&
			 data.getLongestTime() >= MinTimeMax))
		 )
	{
		rowIndex = DisplayTable->addRow(rowIndex);
		fillRow(rowIndex, data, false, false);
		++rowIndex;
	}
	return rowIndex;
}
sudokuBoardReader::sudokuBoardReader(std::string fileName){
        try{
                std::ifstream sudokuFile;
                std::string line;
                sudokuFile.open(fileName);
                if (!sudokuFile) throw (BadFileException());
                std::getline(sudokuFile, line);
                parseHeader(line);
                int i = 0;
                while (i < this-> n && std::getline(sudokuFile, line)) {
			fillRow(i, line);
                        i++;
                }
                sudokuFile.close();
        } catch(std::ifstream::failure e) {
                std::cout << "Failed to read board file\n"; 
        }

}
Exemple #7
0
static void
outputNewBorderNonPbm(unsigned int const height,
                      unsigned int const width,
                      xel          const color,
                      FILE *       const ofP,
                      xelval       const maxval,
                      int          const format) {
/*----------------------------------------------------------------------------
   Output to 'ofP' a horizontal border (i.e. top or bottom)
   of color 'backgroundColor', height 'height', width 'width'.
-----------------------------------------------------------------------------*/
    xel * xelrow;
    unsigned int i;

    xelrow = pnm_allocrow(width);

    fillRow(xelrow, width, color);

    for (i = 0; i < height; ++i)
        pnm_writepnmrow(ofP, xelrow, width, maxval, format, 0);
    
    pnm_freerow(xelrow);
}
Status getTLSCertificate(std::string hostname, QueryData& results) {
  SSL_library_init();

  const auto method = TLSv1_method();
  if (method == nullptr) {
    return Status(1, "Failed to create OpenSSL method object");
  }

  auto delCTX = [](SSL_CTX* ctx) { SSL_CTX_free(ctx); };
  auto ctx =
      std::unique_ptr<SSL_CTX, decltype(delCTX)>(SSL_CTX_new(method), delCTX);
  if (ctx == nullptr) {
    return Status(1, "Failed to create OpenSSL CTX object");
  }

  auto delBIO = [](BIO* bio) { BIO_free_all(bio); };
  auto server = std::unique_ptr<BIO, decltype(delBIO)>(
      BIO_new_ssl_connect(ctx.get()), delBIO);
  if (server == nullptr) {
    return Status(1, "Failed to create OpenSSL BIO object");
  }

  std::string port = ":443";
  auto ext_hostname = hostname;
  auto conn_hostname = hostname;
  auto delim = hostname.find(":");
  if (delim == std::string::npos) {
    conn_hostname += ":443";
  } else {
    ext_hostname = hostname.substr(0, delim);
  }

  auto ret = BIO_set_conn_hostname(server.get(), conn_hostname.c_str());
  if (ret != 1) {
    return Status(1, "Failed to set OpenSSL hostname: " + std::to_string(ret));
  }

  SSL* ssl = nullptr;
  BIO_get_ssl(server.get(), &ssl);
  if (ssl == nullptr) {
    return Status(1, "Failed to retrieve OpenSSL object");
  }

  ret = SSL_set_tlsext_host_name(ssl, ext_hostname.c_str());
  if (ret != 1) {
    return Status(1,
                  "Failed to set OpenSSL server name: " + std::to_string(ret));
  }

  ret = BIO_do_connect(server.get());
  if (ret != 1) {
    return Status(1,
                  "Failed to establish TLS connection: " + std::to_string(ret));
  }

  ret = BIO_do_handshake(server.get());
  if (ret != 1) {
    return Status(1,
                  "Failed to complete TLS handshake: " + std::to_string(ret));
  }

  auto delX509 = [](X509* cert) { X509_free(cert); };
  auto cert = std::unique_ptr<X509, decltype(delX509)>(
      SSL_get_peer_certificate(ssl), delX509);
  if (cert == nullptr) {
    return Status(1, "No certificate");
  }

  Row r;
  r["hostname"] = hostname;
  fillRow(r, cert.get());
  results.push_back(r);
  return Status();
}
Exemple #9
0
/// main.
int main(int argc, char** argv) {
    uint32_t maxrow=0, nrpd=0;
    int nparts, ndigits, ierr;

    // must have the output directory name
    if (argc < 2) {
	std::cerr << "\nUsage:\n" << *argv
		  << " <output-dir> [#rows [#rows-per-dir [conf-file]]]\n"
		  << "If the 4th argument is not provided, the number of "
	    "rows per directory will be determined by the memory cache size, "
	    "which is by default 1/2 of the physical memory size.\n"
		  << std::endl;
	return -1;
    }

    //ibis::gVerbose = 8;
    // initialize the file manage with the 5th argument
    ibis::init(argc>4 ? argv[4] : (const char*)0);
    ibis::util::timer mytimer(*argv, 0);
    if (argc > 2) // user specified maxrow
	maxrow = (uint32_t)atof(argv[2]);
    if (maxrow <= 0) {
	double tmp = ibis::fileManager::currentCacheSize();
	maxrow = (uint32_t)
	    ibis::util::compactValue(tmp / 120.0, tmp / 80.0);
	nrpd = maxrow;
    }
    if (maxrow < 10)
	maxrow = 10;
    if (argc > 3) // user specified nrpd
	nrpd = (uint32_t) atof(argv[3]);
    if (nrpd <= 0) {
	double tmp = ibis::fileManager::currentCacheSize();
	nrpd = (uint32_t)
	    ibis::util::compactValue(tmp / 120.0, tmp / 80.0);
    }
    if (nrpd > maxrow) nrpd = maxrow;

    ibis::table::row val;
    std::auto_ptr<ibis::tablex> tab(ibis::tablex::create());
    initColumns(*tab, val);
    ierr = tab->reserveBuffer(nrpd);
    if (ierr > 0 && (unsigned)ierr < nrpd)
	nrpd = ierr;
    LOGGER(1) << *argv << ' ' << argv[1] << ' ' << maxrow << ' ' << nrpd
	      << std::endl;
    nparts = maxrow / nrpd;
    nparts += (maxrow > nparts*nrpd);
    ierr = nparts;
    for (ndigits = 1, ierr >>= 4; ierr > 0; ierr >>= 4, ++ ndigits);
    for (uint32_t irow = 1; irow <= maxrow;) {
	const uint32_t end = irow - 1 + nrpd;
	TDList tdl;
	std::string dir = argv[1];
	if (nparts > 1) { // figure out the directory name
	    const char* str = strrchr(argv[1], FASTBIT_DIRSEP);
	    if (str != 0) {
		if (str[1] == 0) {
		    while (str-1 > argv[1]) {
			if (*(str-1) == FASTBIT_DIRSEP) break;
			else -- str;
		    }
		}
		else {
		    ++ str;
		}
	    }
	    std::ostringstream oss;
	    oss << FASTBIT_DIRSEP << (str ? str : "_") << std::hex
		<< std::setprecision(ndigits) << std::setw(ndigits)
		<< std::setfill('0') << irow / nrpd;
	    dir += oss.str();
	}

	for (; irow <= end; ++ irow) {
	    fillRow(irow, val, tdl);
	    ierr = tab->appendRow(val);
	    LOGGER(ierr != 6)
		<< "Warning -- " << *argv << " failed to append row " << irow
		<< " to the in-memory table, appendRow returned " << ierr;
	    LOGGER(irow % 100000 == 0) << " . " << irow;
	}
	LOGGER(1) << "\n";
	ierr = tab->write(dir.c_str());
	LOGGER(ierr < 0)
	    << "Warning -- " << *argv << " failed to write " << tab->mRows()
	    << " rows to " << dir << ", ibis::tablex::write returned " << ierr;
	writeTDList(tdl, dir.c_str());
	tab->clearData();
	tdl.clear();
    }
    return 0;
} // main
Exemple #10
0
/*
	\param filename the name of the file
*/
struct linearProgram* createLPFromFile(const char* filename) {
	assert(NULL != filename);
	
	mode = READ_COL;
	
	FILE* fp;
	char buffer[BUF_SIZE];
	char* s;
	int lines = 0;
	
	struct linearProgram* binaryLP;
	int numOfCols = 0;
	int numOfRows = 0;
	int currentConstraint = 0;
	char* type;
	
	if (NULL == (fp = fopen(filename, "r"))) {
		fprintf(stderr, "Can't open file %s\n",filename);
		printf(USAGE);
		exit(EXIT_FAILURE);
	}
	// need a helpful string for strtok
	char* help_me = allocate(BUF_SIZE, sizeof(*help_me));
	char* end_pos;
	char* test;
	char* brks;
	while(NULL != (s = fgets(buffer, sizeof(buffer), fp))) {
		end_pos = strpbrk(s, "#\n\r");
		if (NULL != end_pos) {
			*end_pos = '\0'; // terminate string here, now we can process this line		
		}
		
		/* Skip over leading space
		*/
		while(isspace(*s)) 
			s++;
		
		/* Skip over empty lines
		*/
		if (!*s) /* <=> (*s == '\0') */
			continue;
		
		if (mode == READ_COL) {
			lines++;
			numOfCols = parseDecimal(s);
			mode++;
		}
		else if (mode == READ_ROW) {
			lines++;
			numOfRows = parseDecimal(s);
			
			/* ready to allocate memory for binaryLP.coeffs, rhs-vector and types-enum */
			binaryLP = initializeLP(numOfCols, numOfRows);
			// ready to parse constraint matrix
			mode++;
		}
		else {
			assert(mode == READ_CONSTR);
			lines++;
			if (currentConstraint + 1 > binaryLP->row) {
				printf("Second decimal must correspond to number of constraints!\n");
				exit(EXIT_FAILURE);
			}
			if (NULL == (type = strpbrk(s, "<>="))) {
				printf("Constraint in line %d has wrong shape (<,> or = missing)!\n", lines);
				exit(EXIT_FAILURE);
			} // check which type of constraint
			setType(*type, currentConstraint, binaryLP->types);
			
			// TODO WTF
			strcpy(help_me, s);
			if (-1 == fillRow(binaryLP->coeffs[currentConstraint], binaryLP->col, strtok_r(s,"><=",&brks), " ")) {
				// free pointer:
				deleteLinearProgram(binaryLP);
				deallocate(help_me);
				printf("Incorrect number or format of coefficients in line %d.\n", lines);
				printf(USAGE);
				exit(EXIT_FAILURE);
			}
			//test = strtok(help_me, "><=");
			if(NULL == (test = strtok_r(NULL, " ><=", &brks))) {
				printf("No rhs in line %d.\n", lines);
				printf(USAGE);
				exit(EXIT_FAILURE);
			}
			if (!validateNumber(test)) {
				printf("No number on right-hand-side of line %d.\n", lines);
				exit(EXIT_FAILURE);
			}
			binaryLP->rhs[currentConstraint] = atof(test);
			if (NULL != (test = strtok(NULL, " "))) {
				printf("More than one value on right-hand-side of line %d!\n", lines);
				exit(EXIT_FAILURE);
			}
			currentConstraint++;
		}
	}
	if (currentConstraint < numOfRows) {
		printf("Too few rows!\n");
		exit(EXIT_FAILURE);
	}
	if (lines == 0) {
		printf("The file was empty! Nice try...\n");
		exit(EXIT_FAILURE);
	}
	free(help_me);
	
	fclose(fp);
	return binaryLP;
}
Exemple #11
0
static int writePNG(const QRcode *qrcode, const char *outfile, enum imageType type)
{
#if HAVE_PNG
	static FILE *fp; // avoid clobbering by setjmp.
	png_structp png_ptr;
	png_infop info_ptr;
	png_colorp palette = NULL;
	png_byte alpha_values[2];
	unsigned char *row, *p, *q;
	int x, y, xx, yy, bit;
	int realwidth;

	realwidth = (qrcode->width + margin * 2) * size;
	if(type == PNG_TYPE) {
		row = (unsigned char *)malloc((realwidth + 7) / 8);
	} else if(type == PNG32_TYPE) {
		row = (unsigned char *)malloc(realwidth * 4);
	} else {
		fprintf(stderr, "Internal error.\n");
		exit(EXIT_FAILURE);
	}
	if(row == NULL) {
		fprintf(stderr, "Failed to allocate memory.\n");
		exit(EXIT_FAILURE);
	}

	if(outfile[0] == '-' && outfile[1] == '\0') {
		fp = stdout;
	} else {
		fp = fopen(outfile, "wb");
		if(fp == NULL) {
			fprintf(stderr, "Failed to create file: %s\n", outfile);
			perror(NULL);
			exit(EXIT_FAILURE);
		}
	}

	png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if(png_ptr == NULL) {
		fprintf(stderr, "Failed to initialize PNG writer.\n");
		exit(EXIT_FAILURE);
	}

	info_ptr = png_create_info_struct(png_ptr);
	if(info_ptr == NULL) {
		fprintf(stderr, "Failed to initialize PNG write.\n");
		exit(EXIT_FAILURE);
	}

	if(setjmp(png_jmpbuf(png_ptr))) {
		png_destroy_write_struct(&png_ptr, &info_ptr);
		fprintf(stderr, "Failed to write PNG image.\n");
		exit(EXIT_FAILURE);
	}

	if(type == PNG_TYPE) {
		palette = (png_colorp) malloc(sizeof(png_color) * 2);
		if(palette == NULL) {
			fprintf(stderr, "Failed to allocate memory.\n");
			exit(EXIT_FAILURE);
		}
		palette[0].red   = fg_color[0];
		palette[0].green = fg_color[1];
		palette[0].blue  = fg_color[2];
		palette[1].red   = bg_color[0];
		palette[1].green = bg_color[1];
		palette[1].blue  = bg_color[2];
		alpha_values[0] = fg_color[3];
		alpha_values[1] = bg_color[3];
		png_set_PLTE(png_ptr, info_ptr, palette, 2);
		png_set_tRNS(png_ptr, info_ptr, alpha_values, 2, NULL);
	}

	png_init_io(png_ptr, fp);
	if(type == PNG_TYPE) {
		png_set_IHDR(png_ptr, info_ptr,
				realwidth, realwidth,
				1,
				PNG_COLOR_TYPE_PALETTE,
				PNG_INTERLACE_NONE,
				PNG_COMPRESSION_TYPE_DEFAULT,
				PNG_FILTER_TYPE_DEFAULT);
	} else {
		png_set_IHDR(png_ptr, info_ptr,
				realwidth, realwidth,
				8,
				PNG_COLOR_TYPE_RGB_ALPHA,
				PNG_INTERLACE_NONE,
				PNG_COMPRESSION_TYPE_DEFAULT,
				PNG_FILTER_TYPE_DEFAULT);
	}
	png_set_pHYs(png_ptr, info_ptr,
			dpi * INCHES_PER_METER,
			dpi * INCHES_PER_METER,
			PNG_RESOLUTION_METER);
	png_write_info(png_ptr, info_ptr);

	if(type == PNG_TYPE) {
	/* top margin */
		memset(row, 0xff, (realwidth + 7) / 8);
		for(y = 0; y < margin * size; y++) {
			png_write_row(png_ptr, row);
		}

		/* data */
		p = qrcode->data;
		for(y = 0; y < qrcode->width; y++) {
			memset(row, 0xff, (realwidth + 7) / 8);
			q = row;
			q += margin * size / 8;
			bit = 7 - (margin * size % 8);
			for(x = 0; x < qrcode->width; x++) {
				for(xx = 0; xx < size; xx++) {
					*q ^= (*p & 1) << bit;
					bit--;
					if(bit < 0) {
						q++;
						bit = 7;
					}
				}
				p++;
			}
			for(yy = 0; yy < size; yy++) {
				png_write_row(png_ptr, row);
			}
		}
		/* bottom margin */
		memset(row, 0xff, (realwidth + 7) / 8);
		for(y = 0; y < margin * size; y++) {
			png_write_row(png_ptr, row);
		}
	} else {
	/* top margin */
		fillRow(row, realwidth, bg_color);
		for(y = 0; y < margin * size; y++) {
			png_write_row(png_ptr, row);
		}

		/* data */
		p = qrcode->data;
		for(y = 0; y < qrcode->width; y++) {
			fillRow(row, realwidth, bg_color);
			for(x = 0; x < qrcode->width; x++) {
				for(xx = 0; xx < size; xx++) {
					if(*p & 1) {
						memcpy(&row[((margin + x) * size + xx) * 4], fg_color, 4);
					}
				}
				p++;
			}
			for(yy = 0; yy < size; yy++) {
				png_write_row(png_ptr, row);
			}
		}
		/* bottom margin */
		fillRow(row, realwidth, bg_color);
		for(y = 0; y < margin * size; y++) {
			png_write_row(png_ptr, row);
		}
	}

	png_write_end(png_ptr, info_ptr);
	png_destroy_write_struct(&png_ptr, &info_ptr);

	fclose(fp);
	free(row);
	free(palette);

	return 0;
#else
	fputs("PNG output is disabled at compile time. No output generated.\n", stderr);
	return 0;
#endif
}
Exemple #12
0
static void
writeCroppedNonPbm(FILE *       const ifP,
                   unsigned int const cols,
                   unsigned int const rows,
                   xelval       const maxval,
                   int          const format,
                   cropSet      const crop,
                   xel          const backgroundColor,
                   FILE *       const ofP) {

    /* In order to do cropping, padding or both at the same time, we have
       a rather complicated row buffer:

       xelrow[] is both the input and the output buffer.  So it contains
       the foreground pixels, the original border pixels, and the new
       border pixels.

       We're calling foreground everything that isn't being cropped out
       or padded in.  So the "foreground" may include some of what is really
       a background border in the original image -- because the user can
       choose to retain part of that border as a margin.

       The foreground pixels are in the center of the
       buffer, starting at Column 'foregroundLeft' and going to
       'foregroundRight'.

       There is space to the left of that for the larger of the input
       left border and the output left border.

       Similarly, there is space to the right of the foreground pixels
       for the larger of the input right border and the output right
       border.

       We have to read an entire row, including the pixels we'll be
       leaving out of the output, so we pick a starting location in
       the buffer that lines up the first foreground pixel at
       'foregroundLeft'.

       When we output the row, we pick a starting location in the 
       buffer that includes the proper number of left border pixels
       before 'foregroundLeft'.

       That's for the middle rows.  For the top and bottom, we just use
       the left portion of xelrow[], starting at 0.

       This is the general case.  Enhancement for PBM appears below.
       (Logic works for PBM).
    */

    unsigned int const foregroundCols =
        cols - crop.op[LEFT].removeSize - crop.op[RIGHT].removeSize;
    unsigned int const outputCols     = 
        foregroundCols + crop.op[LEFT].padSize + crop.op[RIGHT].padSize;
    unsigned int const foregroundRows =
        rows - crop.op[TOP].removeSize - crop.op[BOTTOM].removeSize;
    unsigned int const outputRows     =
        foregroundRows + crop.op[TOP].padSize + crop.op[BOTTOM].padSize;

    unsigned int const foregroundLeft  =
        MAX(crop.op[LEFT].removeSize, crop.op[LEFT].padSize);
        /* Index into xelrow[] of leftmost pixel of foreground */
    unsigned int const foregroundRight = foregroundLeft + foregroundCols;
        /* Index into xelrow[] just past rightmost pixel of foreground */

    unsigned int const allocCols =
        foregroundRight + MAX(crop.op[RIGHT].removeSize,
                              crop.op[RIGHT].padSize);

    xel * xelrow;
    unsigned int i;

    pnm_writepnminit(ofP, outputCols, outputRows, maxval, format, 0);

    xelrow = pnm_allocrow(allocCols);

    readOffBorderNonPbm(crop.op[TOP].removeSize, ifP, cols, maxval, format);

    outputNewBorderNonPbm(crop.op[TOP].padSize, outputCols, backgroundColor,
                          ofP, maxval, format);

    /* Set left border pixels */
    fillRow(&xelrow[foregroundLeft - crop.op[LEFT].padSize],
            crop.op[LEFT].padSize,
            backgroundColor);

    /* Set right border pixels */
    fillRow(&xelrow[foregroundRight], crop.op[RIGHT].padSize, backgroundColor);

    /* Read and output foreground rows */
    for (i = 0; i < foregroundRows; ++i) {
 
        /* Read foreground pixels */
        pnm_readpnmrow(ifP,
                       &(xelrow[foregroundLeft - crop.op[LEFT].removeSize]),
                       cols, maxval, format);
        
        pnm_writepnmrow(ofP,
                        &(xelrow[foregroundLeft - crop.op[LEFT].padSize]),
                        outputCols, maxval, format, 0);
    }

    readOffBorderNonPbm(crop.op[BOTTOM].removeSize, ifP, cols, maxval, format);
    
    outputNewBorderNonPbm(crop.op[BOTTOM].padSize, outputCols,
                          backgroundColor,
                          ofP, maxval, format);

    pnm_freerow(xelrow);
}
Exemple #13
0
/*-- 戻り値はsaveBoxが更新されたかどうか --*/
bool fill(const TRasterCM32P &r, const FillParameters &params,
          TTileSaverCM32 *saver) {
  TPixelCM32 *pix, *limit, *pix0, *oldpix;
  int oldy, xa, xb, xc, xd, dy;
  int oldxc, oldxd;
  int tone, oldtone;
  TPoint p = params.m_p;
  int x = p.x, y = p.y;
  int paint = params.m_styleId;
  int fillDepth =
      params.m_shiftFill ? params.m_maxFillDepth : params.m_minFillDepth;

  /*-- getBoundsは画像全面 --*/
  TRect bbbox = r->getBounds();

  /*- 画面外のクリックの場合はreturn -*/
  if (!bbbox.contains(p)) return false;
  /*- 既に同じ色が塗られている場合はreturn -*/
  if ((r->pixels(p.y) + p.x)->getPaint() == paint) return false;
  /*- 「透明部分だけを塗る」オプションが有効で、既に色が付いている場合はreturn
   * -*/
  if (params.m_emptyOnly && (r->pixels(p.y) + p.x)->getPaint() != 0)
    return false;

  assert(fillDepth >= 0 && fillDepth < 16);

  switch (TPixelCM32::getMaxTone()) {
  case 15:
    fillDepth = (15 - fillDepth);
    break;
  case 255:
    fillDepth = ((15 - fillDepth) << 4) | (15 - fillDepth);
    break;
  default:
    assert(false);
  }

  /*-- 四隅の色を見て、一つでも変わったらsaveBoxを更新する --*/
  TPixelCM32 borderIndex[4];
  TPixelCM32 *borderPix[4];
  pix            = r->pixels(0);
  borderPix[0]   = pix;
  borderIndex[0] = *pix;
  pix += r->getLx() - 1;
  borderPix[1]   = pix;
  borderIndex[1] = *pix;
  pix            = r->pixels(r->getLy() - 1);
  borderPix[2]   = pix;
  borderIndex[2] = *pix;
  pix += r->getLx() - 1;
  borderPix[3]   = pix;
  borderIndex[3] = *pix;

  std::stack<FillSeed> seeds;

  fillRow(r, p, xa, xb, paint, params.m_palette, saver);
  seeds.push(FillSeed(xa, xb, y, 1));
  seeds.push(FillSeed(xa, xb, y, -1));

  while (!seeds.empty()) {
    FillSeed fs = seeds.top();
    seeds.pop();

    xa   = fs.m_xa;
    xb   = fs.m_xb;
    oldy = fs.m_y;
    dy   = fs.m_dy;
    y    = oldy + dy;
    if (y > bbbox.y1 || y < bbbox.y0) continue;
    pix = pix0 = r->pixels(y) + xa;
    limit      = r->pixels(y) + xb;
    oldpix     = r->pixels(oldy) + xa;
    x          = xa;
    oldxd      = (std::numeric_limits<int>::min)();
    oldxc      = (std::numeric_limits<int>::max)();
    while (pix <= limit) {
      oldtone = threshTone(*oldpix, fillDepth);
      tone    = threshTone(*pix, fillDepth);
      if (pix->getPaint() != paint && tone <= oldtone && tone != 0) {
        fillRow(r, TPoint(x, y), xc, xd, paint, params.m_palette, saver);
        if (xc < xa) seeds.push(FillSeed(xc, xa - 1, y, -dy));
        if (xd > xb) seeds.push(FillSeed(xb + 1, xd, y, -dy));
        if (oldxd >= xc - 1)
          oldxd = xd;
        else {
          if (oldxd >= 0) seeds.push(FillSeed(oldxc, oldxd, y, dy));
          oldxc = xc;
          oldxd = xd;
        }
        pix += xd - x + 1;
        oldpix += xd - x + 1;
        x += xd - x + 1;
      } else {
        pix++;
        oldpix++, x++;
      }
    }
    if (oldxd > 0) seeds.push(FillSeed(oldxc, oldxd, y, dy));
  }

  bool saveBoxChanged = false;
  for (int i = 0; i < 4; i++) {
    if (!((*borderPix[i]) == borderIndex[i])) {
      saveBoxChanged = true;
      break;
    }
  }
  return saveBoxChanged;
}
Exemple #14
0
void CGUIProfiler::updateDisplay()
{
	if ( DisplayTable )
	{
		DisplayTable->clearRows();

		if ( CurrentGroupIdx < Profiler->getGroupCount() )
		{
			bool overview = CurrentGroupIdx == 0;
			u32 rowIndex = 0;

			// show description row (overview or name of the following group)
			const SProfileData& groupData = Profiler->getGroupData(CurrentGroupIdx);
			if ( !ShowGroupsTogether && (overview || groupData.getCallsCounter() >= MinCalls) )
			{
				rowIndex = DisplayTable->addRow(rowIndex);
				fillRow(rowIndex, groupData, overview, true);
				++rowIndex;
			}

			// show overview over all groups?
			if ( overview )
			{
				for ( u32 i=1; i<Profiler->getGroupCount(); ++i )
				{
					const SProfileData& groupData = Profiler->getGroupData(i);
					if ( groupData.getCallsCounter() >= MinCalls )
					{
						rowIndex = DisplayTable->addRow(rowIndex);
						fillRow(rowIndex, groupData, false, false);
						++rowIndex;
					}
				}
			}
			// show data for all elements in current group
			else
			{
				for ( u32 i=0; i < Profiler->getProfileDataCount(); ++i )
				{
					rowIndex = addDataToTable(rowIndex, i, CurrentGroupIdx);
				}
			}
			// Show the rest of the groups
			if (ShowGroupsTogether)
			{
				for ( u32 groupIdx = CurrentGroupIdx+1; groupIdx < Profiler->getGroupCount(); ++groupIdx)
				{
					for ( u32 i=0; i < Profiler->getProfileDataCount(); ++i )
					{
						rowIndex = addDataToTable(rowIndex, i, groupIdx);
					}
				}
			}
		}

		// IGUITable has no page-wise scrolling yet. The following code can be replaced when we add that.
		// For now we use some CGUITable implementation info to figure this out.
		// (If you wonder why I didn't code page-scrolling directly in CGUITable ... because then it needs to be a
		// public interface and I don't have enough time currently to design & implement that well)
		s32 itemsTotalHeight = DisplayTable->getRowCount() * DisplayTable->getItemHeight();
		s32 tableHeight = DisplayTable->getAbsolutePosition().getHeight();
		s32 heightTitleRow = DisplayTable->getItemHeight()+1;
		if ( itemsTotalHeight+heightTitleRow < tableHeight )
		{
			NumGroupPages = 1;
		}
		else
		{
			s32 heightHScrollBar = DisplayTable->getHorizontalScrollBar() ? DisplayTable->getHorizontalScrollBar()->getAbsolutePosition().getHeight() : 0;
			s32 pageHeight = tableHeight - (heightTitleRow+heightHScrollBar);
			if ( pageHeight > 0 )
			{
				NumGroupPages = (itemsTotalHeight/pageHeight);
				if ( itemsTotalHeight % pageHeight )
					++NumGroupPages;
			}
			else // won't see anything, but that's up to the user
			{
				NumGroupPages = DisplayTable->getRowCount();
			}
			if ( NumGroupPages < 1 )
				NumGroupPages = 1;
		}
		if ( CurrentGroupPage < 0 )
			CurrentGroupPage = (s32)NumGroupPages-1;

		IGUIScrollBar* vScrollBar = DisplayTable->getVerticalScrollBar();
		if ( vScrollBar )
		{
			if ( NumGroupPages < 2 )
				vScrollBar->setPos(0);
			else
			{
				f32 factor = (f32)CurrentGroupPage/(f32)(NumGroupPages-1);
				vScrollBar->setPos( s32(factor * (f32)vScrollBar->getMax()) );
			}
		}
	}
}
void QSGNinePatchNode::update()
{
    if (!m_dirtyGeometry)
        return;

    // For stretch this algorithm could be simplified to use less vertices
    // as more vertices could be reused then, but I doubt its where our main
    // problem will lie. This way, we at least share the algorithm between all

    Q_ASSERT(m_material.texture());

    float tw = m_material.texture()->textureSize().width();
    float th = m_material.texture()->textureSize().height();

    float rightBorder = tw - m_innerRect.right();
    float bottomBorder = th - m_innerRect.bottom();

//    qDebug() << m_innerRect << m_targetRect << m_horizontalTileMode << m_verticalTileMode;

    int xChunkCount = 0; // Number of chunks
    float xChunkSize = 0; // Size of chunk in pixels
    float xTexSize = m_innerRect.width(); // Size of the texture to stretch/tile
    float xSize = m_targetRect.width() - m_innerRect.left() - rightBorder; // Size of area to fill with chunks

    if (m_horizontalTileMode == QSGBorderImage::Repeat) {
        xChunkCount = qCeil(xSize / xTexSize);
        xChunkSize = xTexSize;
    } else if (m_horizontalTileMode == QSGBorderImage::Round) {
        xChunkCount = qCeil(xSize / xTexSize);
        qreal fullWidth = xChunkCount * xTexSize;
        xChunkSize = xTexSize * xSize / fullWidth;
    } else {
        xChunkCount = 1;
        xChunkSize = xSize;
    }

    int yChunkCount = 0;
    float yChunkSize = 0; // Relative to target rect.
    float yTexSize = m_innerRect.height(); // Size of the texture to stretch/tile
    float ySize = m_targetRect.height() - m_innerRect.top() - bottomBorder;

    if (m_verticalTileMode == QSGBorderImage::Repeat) {
        yChunkCount = qCeil(ySize / yTexSize);
        yChunkSize = yTexSize;
    } else if (m_verticalTileMode == QSGBorderImage::Round) {
        yChunkCount = qCeil(ySize / yTexSize);
        qreal fullHeight = yChunkCount * yTexSize;
        yChunkSize = yTexSize * ySize / fullHeight;
    } else {
        yChunkCount = 1;
        yChunkSize = ySize;
    }

    int xTotalChunkCount = xChunkCount + 2;
    int yTotalChunkCount = yChunkCount + 2;

    int totalChunkCount = xTotalChunkCount * yTotalChunkCount;
    int vertexCount = totalChunkCount * 4;
    int indexCount = totalChunkCount * 6;

    if (vertexCount != m_geometry.vertexCount() || indexCount != m_geometry.indexCount())
        m_geometry.allocate(vertexCount, indexCount);

    QSGGeometry::TexturedPoint2D *v = m_geometry.vertexDataAsTexturedPoint2D();


    // Fill in the vertices.. The loop below is pretty much an exact replica
    // of the one inside fillRow.
    float yTexChunk1 = m_innerRect.top() / th;
    float yTexChunk2 = m_innerRect.bottom() / th;

    fillRow(v, 0, 0, xChunkCount, xChunkSize);
    fillRow(v, m_innerRect.y(), yTexChunk1, xChunkCount, xChunkSize);

    for (int yc=0; yc<yChunkCount; ++yc) {
        float yy = m_innerRect.y() + yChunkSize * yc;
        fillRow(v, yy, yTexChunk1, xChunkCount, xChunkSize);

        // Special case the last one
        if (yc == yChunkCount - 1) {
            float t = m_verticalTileMode == QSGBorderImage::Repeat
                      ? yTexChunk1 + (yTexChunk2 - yTexChunk1) * (m_targetRect.height() - bottomBorder - yy) / yChunkSize
                      : yTexChunk2;
            fillRow(v, m_targetRect.height() - bottomBorder, t, xChunkCount, xChunkSize);
        } else {
            fillRow(v, yy + yChunkSize, yTexChunk2, xChunkCount, xChunkSize);
        }
    }

    fillRow(v, m_targetRect.height() - bottomBorder, yTexChunk2, xChunkCount, xChunkSize);
    fillRow(v, m_targetRect.height(), 1, xChunkCount, xChunkSize);

    if (m_mirror) {
        v = m_geometry.vertexDataAsTexturedPoint2D();
        for (int i=0; i<m_geometry.vertexCount(); ++i) {
            v->x = m_targetRect.width() - v->x;
            ++v;
        }
    }

//    v = m_geometry.vertexDataAsTexturedPoint2D();
//    for (int i=0; i<m_geometry.vertexCount(); ++i) {
//        printf("Vertex: %d:  (%.3f, %.3f) - (%.3f, %.3f)\n",
//               i,
//               v->x, v->y, v->tx, v->ty);
//        ++v;
//    }

    quint16 *i = m_geometry.indexDataAsUShort();
    int row = xTotalChunkCount * 2;
    for (int r=0; r<yTotalChunkCount; ++r) {
        int offset = r * row * 2;
        for (int c=0; c<xTotalChunkCount; ++c) {
            *i++ = offset + c * 2;
            *i++ = offset + c * 2 + 1;
            *i++ = offset + c * 2 + row;
            *i++ = offset + c * 2 + 1;
            *i++ = offset + c * 2 + row + 1;
            *i++ = offset + c * 2 + row;
        }
    }

//    i = m_geometry.indexDataAsUShort();
//    for (int idx=0; idx<m_geometry.indexCount(); idx+=6) {
//        printf("%2d: ", idx / 6);
//        for (int s=0; s<6; ++s)
//            printf(" %d", i[idx + s]);
//        printf("\n");
//    }

    markDirty(QSGNode::DirtyGeometry);
}