Exemple #1
0
void Image::pasteWithBlendMode(BlendMode mode, float opacity, const Image &image, const QPoint &offset, const QRect &imageRect)
{
	QRect r = rect() & imageRect.translated(offset);
	
	auto blendOp = mode.op();
	
	if (opacity == 1.0)
	{
		for (int y = r.top(); y <= r.bottom(); ++y)
		{
			auto dp = scanline(y);
			dp += r.left();
			
			auto sp = image.constScanline(y - offset.y());
			sp += (r.left() - offset.x());
			
			blendOp->blend(r.width(), dp, sp);
		}
	}
	else
	{
		for (int y = r.top(); y <= r.bottom(); ++y)
		{
			auto dp = scanline(y);
			dp += r.left();
			
			auto sp = image.constScanline(y - offset.y());
			sp += (r.left() - offset.x());
			
			blendOp->blend(r.width(), dp, sp, opacity);
		}
	}
}
Exemple #2
0
void scan_convert( const poly_t& p, const Imath::Box2i& window, PixelFun f)
{
	if( p.empty())
		return;

    int li = p.topmost_vertex(), ri = li;
    int rem = p.size();
	int y = Imath::Math<float>::ceil( p[li].screen.y - 0.5f);
    int ly = y - 1, ry = ly;
	int i;

	vertex_t l, r, dl, dr;

    while( rem > 0)
	{
		while( ly <= y && rem > 0)
		{
			--rem;
			i = li - 1;

			if( i < 0)
				i = p.size() - 1;

			incrementalize_y( y, p[li], p[i], l, dl);
			ly = Imath::Math<float>::floor( p[i].screen.y + 0.5f);
			li = i;
		}

		while( ry <= y && rem > 0)
		{
		    --rem;
		    i = ri + 1;

		    if( i >= p.size())
				i = 0;

			incrementalize_y( y, p[ri], p[i], r, dr);
		    ry = Imath::Math<float>::floor( p[i].screen.y + 0.5f);
		    ri = i;
		}

		while( y < ly && y < ry)
	    {
			if( y >= window.min.y && y <= window.max.y)
			{
				if( l.screen.x <= r.screen.x)
					scanline( y, l, r, dl, dr, window, f);
				else
					scanline( y, r, l, dr, dl, window, f);
			}

		    y++;

			l.increment( dl);
			r.increment( dr);
		}
    }
}
Exemple #3
0
static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) {
    if (!bitmap.getPixels()) {
        fill_stream(out, '\xFF', pixel_count(bitmap));
        return;
    }
    SkBitmap copy;
    const SkBitmap& bm = not4444(bitmap, &copy);
    SkAutoLockPixels autoLockPixels(bm);
    SkColorType colorType = bm.colorType();
    switch (colorType) {
        case kRGBA_8888_SkColorType:
        case kBGRA_8888_SkColorType: {
            SkAutoTMalloc<uint8_t> scanline(bm.width());
            for (int y = 0; y < bm.height(); ++y) {
                uint8_t* dst = scanline.get();
                const SkPMColor* src = bm.getAddr32(0, y);
                for (int x = 0; x < bm.width(); ++x) {
                    *dst++ = SkGetA32Component(*src++, colorType);
                }
                out->write(scanline.get(), bm.width());
            }
            return;
        }
        case kAlpha_8_SkColorType:
            for (int y = 0; y < bm.height(); ++y) {
                out->write(bm.getAddr8(0, y), bm.width());
            }
            return;
        case kIndex_8_SkColorType: {
            SkColorTable* ct = bm.getColorTable();
            SkASSERT(ct);
            SkAutoTMalloc<uint8_t> scanline(bm.width());
            for (int y = 0; y < bm.height(); ++y) {
                uint8_t* dst = scanline.get();
                const uint8_t* src = bm.getAddr8(0, y);
                for (int x = 0; x < bm.width(); ++x) {
                    *dst++ = SkGetPackedA32((*ct)[*src++]);
                }
                out->write(scanline.get(), bm.width());
            }
            return;
        }
        case kRGB_565_SkColorType:
        case kGray_8_SkColorType:
            SkDEBUGFAIL("color type has no alpha");
            return;
        case kARGB_4444_SkColorType:
            SkDEBUGFAIL("4444 color type should have been converted to N32");
            return;
        case kUnknown_SkColorType:
        default:
            SkDEBUGFAIL("unexpected color type");
    }
}
Exemple #4
0
void scanline(int x, int y, int fill_color, int border)
{
putpixel(x,y,fill_color);
if(getpixel(x+1,y) != border && getpixel(x+1,y) != fill_color)
scanline(x+1,y,fill_color,border);
if(getpixel(x,y+1) != border && getpixel(x,y+1) != fill_color)
scanline(x,y+1,fill_color,border);
if(getpixel(x-1,y) != border && getpixel(x-1,y) != fill_color)
scanline(x-1,y,fill_color,border);
if(getpixel(x,y-1) != border && getpixel(x,y-1) != fill_color)
scanline(x,y-1,fill_color,border);
return;
}
Exemple #5
0
int main(){
	Point P[5];
	P[0].x = 50;
	P[0].y = 50;
	P[1].x = 100;
	P[1].y = 100;
	P[2].x = 150;
	P[2].y = 50;
	P[3].x = 140;
	P[3].y = 150;
	P[4].x = 60;
	P[4].y = 150;
	
	set_mode(VGA_256_COLOR_MODE);
	line_bresenham(P[0],P[1],2);
	line_bresenham(P[1],P[2],2);
	line_bresenham(P[2],P[3],2);
	line_bresenham(P[3],P[4],2);
	line_bresenham(P[4],P[0],2);
	scanline(P,5,100);
	getch();

	set_mode(TEXT_MODE);
	
	return 0;
}
Exemple #6
0
Image load(string filename) {
    FILE *f = fopen(filename.c_str(), "rb");

    assert(f, "Could not open file\n");

    // Skip hdr header
    char thisChar = fgetc(f), lastChar;
    do {
        lastChar = thisChar;
        thisChar = fgetc(f);
    } while (lastChar != '\n' || thisChar != '\n');

    int height, width;
    assert(2 == fscanf(f, "-Y %20d +X %20d\n", &height, &width),
           "Could not parse HDR header\n");
    Image im(width, height, 1, 3);

    // Read image
    vector<float> scanline(width*3);
    for (int y = 0; y < height; y++) {
        FileHDR::freadscan((COLOR *)(&scanline[0]), width, f);
        for (int x = 0; x < width; x++) {
            im(x, y, 0) = scanline[x*3+0];
            im(x, y, 1) = scanline[x*3+1];
            im(x, y, 2) = scanline[x*3+2];
        }
    }

    fclose(f);

    return im;
}
Exemple #7
0
void save(Image im, string filename) {

    assert(im.channels == 3, "Can't save HDR image with <> 3 channels.\n");
    assert(im.frames == 1, "Can't save a multi-frame HDR image\n");

    FILE *f = fopen(filename.c_str(), "wb");

    assert(f, "Could not write output file %s\n", filename.c_str());

    // Write trivial hdr header
    fprintf(f,"#?RADIANCE\n");
    fprintf(f,"\n");
    fprintf(f,"-Y %d +X %d\n", im.height, im.width);

    // Read image
    vector<float> scanline(im.width*3);
    for (int y = 0; y < im.height; y++) {
        for (int x = 0; x < im.width; x++) {
            scanline[x*3+0] = im(x, y, 0);
            scanline[x*3+1] = im(x, y, 1);
            scanline[x*3+2] = im(x, y, 2);
        }
        fwritescan((COLOR *)&scanline[0], im.width, f);
    }

    fclose(f);
}
Exemple #8
0
void CScanLinePanic::TestBufferInvariant()
	{
	TInt buffLength=19;
	TInt length=10;
	TUint8* buffer=new(ELeave) TUint8[buffLength];
	TPtr8 scanline(buffer, buffLength, buffLength);
	iWsScrDev->GetScanLine(scanline, TPoint(), length, EColor64K);
	delete buffer;    
	}
Exemple #9
0
	void	resample(SDL_Surface* dest, int out_x0, int out_y0, int out_x1, int out_y1,
			 SDL_Surface* src, float in_x0, float in_y0, float in_x1, float in_y1)
	// Resample the specified rectangle of the src surface into the
	// specified rectangle of the destination surface.  Output coords
	// are inclusive.
	{
		// Make sure output is within bounds.
		assert(out_x0 >= 0 && out_x0 < dest->w);
		assert(out_x1 > out_x0 && out_x1 < dest->w);
		assert(out_y0 >= 0 && out_y0 < dest->h);
		assert(out_y1 > out_y0 && out_y1 < dest->h);

		int	dxo = (out_x1 - out_x0);
		int	dyo = (out_y1 - out_y0);

		// @@ check input...

		float	dxi = in_x1 - in_x0;
		float	dyi = in_y1 - in_y0;
		assert(dxi > 0.001f);
		assert(dyi > 0.001f);

		float	x_factor = dxi / dxo;
		float	y_factor = dyi / dyo;

		// @@ not optimized.

		for (int j = 0; j <= dyo; j++) {
			for (int i = 0; i <= dxo; i++) {
				// @@ simple nearest-neighbor point-sample.
				float	x = i * x_factor + in_x0;
				float	y = j * y_factor + in_y0;
				x = fclamp(x, 0.f, float(src->w - 1));
				y = fclamp(y, 0.f, float(src->h - 1));

				Uint8*	p = scanline(src, frnd(y)) + 3 * frnd(x);
				Uint8*	q = scanline(dest, out_y0 + j) + 3 * (out_x0 + i);

				*q++ = *p++;	// red
				*q++ = *p++;	// green
				*q++ = *p++;	// blue
			}
		}
	}
Exemple #10
0
// For reading SWF JPEG3-style image data, like ordinary JPEG, 
// but stores the data in ImageRGBA format.
std::unique_ptr<ImageRGBA>
Input::readSWFJpeg3(std::shared_ptr<IOChannel> in)
{

    std::unique_ptr<ImageRGBA> im;

    // Calling with headerBytes as 0 has a special effect...
    std::unique_ptr<JpegInput> j_in(
            JpegInput::createSWFJpeg2HeaderOnly(in, 0));

    // If this isn't true, we should have thrown.
    assert(j_in.get());

    j_in->read();

    const size_t height = j_in->getHeight();
    const size_t width = j_in->getWidth();

    im.reset(new ImageRGBA(width, height));

    if (j_in->imageType() == TYPE_RGBA) {

        for (size_t y = 0; y < height; ++y) {
            j_in->readScanline(scanline(*im, y));
        }
    } else {
        std::unique_ptr<GnashImage::value_type[]> line(
            new GnashImage::value_type[3 * width]);

        for (size_t y = 0; y < height; ++y) {
            j_in->readScanline(line.get());

            GnashImage::iterator data = scanline(*im, y);
            for (size_t x = 0; x < width; ++x) {
                data[4*x+0] = line[3*x+0];
                data[4*x+1] = line[3*x+1];
                data[4*x+2] = line[3*x+2];
                data[4*x+3] = 255;
            }
        }
    }

    return im;
}
Exemple #11
0
int main()
{
initwindow(320,240);
rectangle(32, 24, 188, 216);
circle(160, 120, 29);
scanline(50, 40, BLUE, WHITE);
while(!kbhit())
delay(50);
return EXIT_SUCCESS;
}
Exemple #12
0
char *parse_line(FILE *fp, char *line, int max_len, char *parts, char **part, int *n_parts, char** text_stream)
{
    char *cp;
    char *result;
    int    in_white;
    int    in_quote;
    int    k;

// If fp == NULL, we scan from the text stream instead
    if (fp)                       result = fgets(line, max_len, fp);
    else if (text_stream != NULL) result = scanline(text_stream, line, max_len);
    else result = 0;

    if (result) {
        cp       = &line[0];
        in_white = YES;
        in_quote = NO;
        *n_parts = 0;
        k        = 0;
        while (*cp != '\0') {
            if (in_quote) {
                if (*cp == '"') {
                    in_quote = NO;
                    in_white = YES;
                    parts[k++] = '\0';
                }
                else parts[k++] = *cp;
            }
            /* check for white space */
            /* 	else if ((*cp == '"') && in_white) {  */
            /* 	    in_quote = YES; */
            /* 	    part[(*n_parts)++] = &parts[k]; */
            /* 	    } */
            else if (*cp == '%') { /* ignore comments */
                *cp = '\0';
                continue;
            }
            else if ((*cp == ' ') || (*cp == '\t') || (*cp == ':') || (*cp == '\n')) {
                if (!in_white) {
                    in_white = YES;
                    if (*n_parts) parts[k++] = '\0';
                }
            }
            else {
                if (in_white) part[(*n_parts)++] = &parts[k];
                parts[k++] = *cp;
                in_white = NO;
            }
            cp++;
        }

        if (!in_white && *n_parts) parts[k] = '\0';
    }
    return result;
}
Exemple #13
0
	void	write_jpeg(SDL_RWops* out, rgb* image, int quality)
	// Write the given image to the given out stream, in jpeg format.
	{
		jpeg::output*	j_out = jpeg::output::create(out, image->m_width, image->m_height, quality);

		for (int y = 0; y < image->m_height; y++) {
			j_out->write_scanline(scanline(image, y));
		}

		delete j_out;
	}
void ImageSourceFileRadiance::loadStream( IStreamRef stream )
{
	setDataType( ImageIo::FLOAT32 );
	setColorModel( ImageIo::CM_RGB );
	setChannelOrder( ImageIo::RGB );

	char str[200];
	stream->readData( str, 10 );
	if( memcmp( str, "#?RADIANCE", 10 ) )
		throw ImageSourceFileRadianceException( "Invalid header" );

	stream->seekRelative( 1 );

	char cmd[200];
	int i = 0;
	char c = 0, oldc;
	while( true ) {
		oldc = c;
		stream->read( &c );
		if( c == 0xa && oldc == 0xa )
			break;
		cmd[i++] = c;
	}

	char resolution[200];
	i = 0;
	while( true ) {
		stream->read( &c );
		resolution[i++] = c;
		if( c == 0xa )
			break;
	}

	int width, height;
#if defined( CINDER_WINRT )
	if( ! sscanf_s( resolution, "-Y %d +X %d", &height, &width ) )
#else
	if( ! sscanf( resolution, "-Y %d +X %d", &height, &width ) )
#endif
		throw ImageSourceFileRadianceException( "Unable to parse size" );
	setSize( width, height );

	mRgbData = std::unique_ptr<float[]>( new float[width * height * 3] );
	std::unique_ptr<RgbePixel[]> scanline( new RgbePixel[width] );

	// convert image
	float *cols = mRgbData.get();
	for( int y = height - 1; y >= 0; y-- ) {
		if( ! decrunchScanline( scanline.get(), width, stream.get() ) )
			break;
		workOnRgbeScanline( scanline.get(), width, cols );
		cols += width * 3;
	}
}
Exemple #15
0
void PaintedWidget::drawSurface(int i,QPainter *painter) {
    double w=this->height()/4.0;
    for(int j=0;j<4;j++)drawLine(int((node[surface[i][j]][0]+2)*w),
                                 int((node[surface[i][j]][1]+2)*w),
                                 int((node[surface[i][(j+1)&3]][0]+2)*w),
                                 int((node[surface[i][(j+1)&3]][1]+2)*w));
    /*
    floodfill(int((node[surface[i][0]][0]+2)*w+(node[surface[i][2]][0]+2)*w)/2,
              int((node[surface[i][0]][1]+2)*w+(node[surface[i][2]][1]+2)*w)/2);
              */
    scanline(i,painter,w);
}
Exemple #16
0
void
ImageRGBA::setPixel(size_t x, size_t y, boost::uint8_t r, boost::uint8_t g,
        boost::uint8_t b, boost::uint8_t a)
{
    assert(x < _width);
    assert(y < _height);

    boost::uint8_t* data = scanline(y) + 4 * x;

    data[0] = r;
    data[1] = g;
    data[2] = b;
    data[3] = a;
}
Exemple #17
0
void bPPU::enter() {
  loop:
  //H =    0 (initialize)
  scanline();
  if(ivcounter() == 0) frame();
  add_clocks(10);

  //H =   10 (OAM address reset)
  if(ivcounter() == (!overscan() ? 225 : 240)) {
    if(regs.display_disabled == false) {
      regs.oam_addr = regs.oam_baseaddr << 1;
      regs.oam_firstsprite = (regs.oam_priority == false) ? 0 : (regs.oam_addr >> 2) & 127;
    }
  }
Exemple #18
0
void
ImageRGBA::setPixel(size_t x, size_t y, value_type r, value_type g,
        value_type b, value_type a)
{
    assert(x < _width);
    assert(y < _height);

    iterator data = scanline(*this, y) + 4 * x;

    *data = r;
    *(data + 1) = g;
    *(data + 2) = b;
    *(data + 3) = a;
}
Exemple #19
0
void tga_writer_t::do_write_image( const boost::filesystem::path& p,
				const image::const_image_view_t& view,
				const adobe::dictionary_t& params) const
{
    int channels    = adobe::get_value( params, adobe::name_t( "channels")).cast<int>();
    int compress    = adobe::get_value( params, adobe::name_t( "compress")).cast<int>();
    
    std::auto_ptr<OIIO::ImageOutput> out( OIIO::ImageOutput::create( filesystem::file_string( p)));

    if( !out.get())
		throw exception( "Write TGA: Can't open output file");

    if( channels)
		channels = 3;
    else
		channels = 4;

    OIIO::ImageSpec spec( view.width(), view.height(), channels, OIIO::TypeDesc::UINT8);
	add_common_attributes( spec);

	switch( compress)
	{
		case none_compression:
		break;
		
		case rle_compression:
			spec.attribute( "compression", "rle");
		break;
		
		default:
			throw unsupported_image( "unsupported compression");
	}

    if( !out->open( filesystem::file_string( p), spec))
		throw exception( "Can't open output file");

    std::vector<image::pixel_t> scanline( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
		std::copy( view.row_begin( y), view.row_end( y), scanline.begin());
		clamp( scanline.begin(), scanline.end());
	
		if( !out->write_scanline( y, 0, OIIO::TypeDesc::FLOAT, (void *) &( *scanline.begin()), sizeof( image::pixel_t)))
			throw exception( "Write image: Can't write pixels");
    }

    if( !out->close())
		throw exception( "Write image: Can't close file");
}
//internal
void PPUcounter::vcounter_tick() {
  if(++status.vcounter == 128) status.interlace = ppu.interlace();

  if((system.region.i == System::Region::NTSC && status.interlace == false && status.vcounter == 262)
  || (system.region.i == System::Region::NTSC && status.interlace == true  && status.vcounter == 263)
  || (system.region.i == System::Region::NTSC && status.interlace == true  && status.vcounter == 262 && status.field == 1)
  || (system.region.i == System::Region::PAL  && status.interlace == false && status.vcounter == 312)
  || (system.region.i == System::Region::PAL  && status.interlace == true  && status.vcounter == 313)
  || (system.region.i == System::Region::PAL  && status.interlace == true  && status.vcounter == 312 && status.field == 1)
  ) {
    status.vcounter = 0;
    status.field = !status.field;
  }
  if(scanline) scanline();
}
Exemple #21
0
	rgb*	read_jpeg(SDL_RWops* in)
	// Create and read a new image from the stream.
	{
		jpeg::input*	j_in = jpeg::input::create(in);
		if (j_in == NULL) return NULL;
		
		rgb*	im = image::create_rgb(j_in->get_width(), j_in->get_height());

		for (int y = 0; y < j_in->get_height(); y++) {
			j_in->read_scanline(scanline(im, y));
		}

		delete j_in;

		return im;
	}
Exemple #22
0
void PPU::enter() {
  while(true) {
    if(scheduler.sync == Scheduler::SynchronizeMode::All) {
      scheduler.exit(Scheduler::ExitReason::SynchronizeEvent);
    }

    scanline();
    if(vcounter() < display.height && vcounter()) {
      add_clocks(512);
      render_scanline();
      add_clocks(lineclocks() - 512);
    } else {
      add_clocks(lineclocks());
    }
  }
}
Exemple #23
0
//------------------------------------------------------------------------------
// scan() -- one pass through the scan pattern
//------------------------------------------------------------------------------
void Scanline::scan()
{
   reset();

   // ---
   // Main loop --
   //   scanlines are y = { 0 .. iy-1 }
   //   pixels in each scanline are x = { 0 .. ix-1 }
   // ---
   for (unsigned int y = 0; y < iy; y++) {
      scanline(y);
      for (unsigned int x = 0; x < ix; x++) {
         const PolyData* p = step(x);
         callback(p,x,y);
      }
   }
}
Exemple #24
0
static bool WriteImagePFM(const std::string &filename, const Float *rgb,
                          int width, int height) {
    FILE *fp;
    float scale;

    fp = fopen(filename.c_str(), "wb");
    if (!fp) {
        Error("Unable to open output PFM file \"%s\"", filename.c_str());
        return false;
    }

    std::unique_ptr<float[]> scanline(new float[3 * width]);

    // only write 3 channel PFMs here...
    if (fprintf(fp, "PF\n") < 0) goto fail;

    // write the width and height, which must be positive
    if (fprintf(fp, "%d %d\n", width, height) < 0) goto fail;

    // write the scale, which encodes endianness
    scale = hostLittleEndian ? -1.f : 1.f;
    if (fprintf(fp, "%f\n", scale) < 0) goto fail;

    // write the data from bottom left to upper right as specified by
    // http://netpbm.sourceforge.net/doc/pfm.html
    // The raster is a sequence of pixels, packed one after another, with no
    // delimiters of any kind. They are grouped by row, with the pixels in each
    // row ordered left to right and the rows ordered bottom to top.
    for (int y = height - 1; y >= 0; y--) {
        // in case Float is 'double', copy into a staging buffer that's
        // definitely a 32-bit float...
        for (int x = 0; x < 3 * width; ++x)
            scanline[x] = rgb[y * width * 3 + x];
        if (fwrite(&scanline[0], sizeof(float), width * 3, fp) <
            (size_t)(width * 3))
            goto fail;
    }

    fclose(fp);
    return true;

fail:
    Error("Error writing PFM file \"%s\"", filename.c_str());
    fclose(fp);
    return false;
}
Exemple #25
0
// Create and read a new image, using a input object that
// already has tables loaded.  The IJG documentation describes
// this as "abbreviated" format.
std::unique_ptr<GnashImage>
JpegInput::readSWFJpeg2WithTables(JpegInput& loader)
{

    loader.read();

    std::unique_ptr<GnashImage> im(
            new ImageRGB(loader.getWidth(), loader.getHeight()));

    for (size_t y = 0, height = loader.getHeight(); y < height; y++) {
        loader.readScanline(scanline(*im, y));
    }

    loader.finishImage();

    return im;
}
Exemple #26
0
static void write_compressed_image(FILE* f, Image* image)
{
  PixelIO<ImageTraits> pixel_io;
  z_stream zstream;
  int y, err;

  zstream.zalloc = (alloc_func)0;
  zstream.zfree  = (free_func)0;
  zstream.opaque = (voidpf)0;
  err = deflateInit(&zstream, Z_DEFAULT_COMPRESSION);
  if (err != Z_OK)
    throw base::Exception("ZLib error %d in deflateInit().", err);

  std::vector<uint8_t> scanline(ImageTraits::scanline_size(image->w));
  std::vector<uint8_t> compressed(4096);

  for (y=0; y<image->h; y++) {
    typename ImageTraits::address_t address = image_address_fast<ImageTraits>(image, 0, y);
    pixel_io.write_scanline(address, image->w, &scanline[0]);

    zstream.next_in = (Bytef*)&scanline[0];
    zstream.avail_in = scanline.size();

    do {
      zstream.next_out = (Bytef*)&compressed[0];
      zstream.avail_out = compressed.size();

      // Compress
      err = deflate(&zstream, (y < image->h-1 ? Z_NO_FLUSH: Z_FINISH));
      if (err != Z_OK && err != Z_STREAM_END)
        throw base::Exception("ZLib error %d in deflate().", err);

      int output_bytes = compressed.size() - zstream.avail_out;
      if (output_bytes > 0) {
        if ((fwrite(&compressed[0], 1, output_bytes, f) != (size_t)output_bytes)
            || ferror(f))
          throw base::Exception("Error writing compressed image pixels.\n");
      }
    } while (zstream.avail_out == 0);
  }

  err = deflateEnd(&zstream);
  if (err != Z_OK)
    throw base::Exception("ZLib error %d in deflateEnd().", err);
}
void MyScene::render(int type, int width, int height, unsigned char* pixels) {
    if (!isLoaded) {
		progress = 1.0;
        return;
    }
	bDoRender = true;
    // Add your rendering code here.
    // Keep track of your progress as a value between 0 and 1
    // so the progress bar can update as the rendering progresses
	progress = 0.0;
    switch (type) {
        case RenderingUI::RENDER_SCANLINE:  scanline(width, height, pixels); break;
        case RenderingUI::RENDER_RAY_TRACING:  raytrace(width, height, pixels); break;
        case RenderingUI::RENDER_PATH_TRACING:  break;
        default: break;
    }
	progress = 1.0;
}
Exemple #28
0
Image &Image::operator*=(float factor)
{
	factor = qBound(0.f, factor, 1.f);
	if (factor == 1.f)
		return *this;
	
	PixelVec vfactor(factor);
	QSize size = this->size();
	
	for (int y = 0; y < size.height(); ++y)
	{
		Pixel *p = scanline(y);
		
		for (int x = 0; x < size.width(); ++x)
			(p++)->rv() *= vfactor;
	}
	
	return *this;
}
    void GameWorld::update(const sf::Time &tslu) {

        // delete entities that should be removed
        auto shouldBeRemoved = [](Entity * s) {
            if (s->getDeletionStatus())
                return true;
            else
                return false;
        };
        entities.erase(std::remove_if(entities.begin(), entities.end(), shouldBeRemoved), entities.end());
        // update all entities
        for (auto entityIter = entities.begin();
             entityIter != entities.end(); ++entityIter) {
            Entity *e = *entityIter;
            e->update(tslu);
        }
        // Detect and resolve collisions between entities
        if (collisionActive)
            scanline();
    }
Exemple #30
0
void CreateTmp::apply(string filename, int width, int height, int frames, int channels) {

    assert(frames > 0 && width > 0 && height > 0 && channels > 0,
           "Some of the specified dimensions are less than 1\n");


    FILE *f = fopen(filename.c_str(), "wb");
    assert(f, "Could not open/create file %s\n", filename.c_str());

    int header[] = {width, height, frames, channels, 0};
    fwrite(header, sizeof(float), 5, f);
    vector<float> scanline(width*channels);
    memset(&scanline[0], 0, width*channels*sizeof(float));

    for (int i = 0; i < frames*height; i++) {
        fwrite(&scanline[0], sizeof(float), width*channels, f);
    }

    fclose(f);
}