Пример #1
0
inline RGBA Interpolate(const RGBA& start, const RGBA& end, float fractionComplete) {
	RGBA interpRGBA;
	interpRGBA.r() = Interpolate(start.r(), end.r(), fractionComplete);
	interpRGBA.g() = Interpolate(start.g(), end.g(), fractionComplete);
	interpRGBA.b() = Interpolate(start.b(), end.b(), fractionComplete);
	interpRGBA.a() = Interpolate(start.a(), end.a(), fractionComplete);
	return interpRGBA;
}
Пример #2
0
void ImageDrawing::filledcircle(Image* image, float x, float y, float r, const RGBA& c, AlphaCombineMode am) {
    for(float yi = y-r; yi < y+r; yi++) {
        float phi = ::asin(::abs(yi-y)/r);
        float xr = abs(::cos(phi)*r);
        // Antialiased begin point
        float a = 1 - ((x-xr) - int(x-xr));
        RGBA d = RGBA(c.r(), c.g(), c.b(), c.a() * a);
        pixel(image, int(x-xr), yi, d, ImageDrawing::DECAL);
        // Middle 
        for(float xi = x-xr+1; xi <= int(x+xr); xi++) {
            pixel(image, xi, yi, c);
        }
        // Antialiased end point
        a = ((x+xr) - int(x+xr));
        d = RGBA(c.r(), c.g(), c.b(), c.a() * a);
        pixel(image, int(x+xr), yi, d, ImageDrawing::DECAL);
    }
}
Пример #3
0
RGBA ColorMatrix::operator*(const RGBA& color) const {
    double result[4] = {0,0,0,0};
    double c[4] = {color.r(), color.g(), color.b(), color.a()};

    for(int y = 0; y < 4; y++) {
	result[y] = matrix[y*4 + 0] * c[0] +
	            matrix[y*4 + 1] * c[1] +
	            matrix[y*4 + 2] * c[2] +
	            matrix[y*4 + 3] * c[3];
    }
    return RGBA(c[0],c[1],c[2],c[3]);
}
Пример #4
0
static bool readRGBA(const zeitgeist::ParameterList& in, RGBA& m)
{
    if (
        (in.GetSize() != 4) ||
        (! in.GetValue(in[0], m.r())) ||
        (! in.GetValue(in[1], m.g())) ||
        (! in.GetValue(in[2], m.b())) ||
        (! in.GetValue(in[3], m.a()))
        )
        {
            return false;
        }

    return true;
}
Пример #5
0
void Buffer::change_color(uint32_t vertex_offset, uint32_t vertex_count, const RGBA& color)
{
	ColorStruct clr;
	clr.color[0] = color.r();
	clr.color[1] = color.g();
	clr.color[2] = color.b();
	clr.color[3] = color.a();
	
	std::vector<ColorStruct> colors;
	for (uint32_t i=0; i < vertex_count; i++)
		colors.push_back(clr);

	glBindBuffer(GL_ARRAY_BUFFER, color_buffer_id);
	glBufferSubData(GL_ARRAY_BUFFER, vertex_offset * sizeof(ColorStruct), 
		vertex_count * sizeof(ColorStruct), &colors[0]);
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}
Пример #6
0
static bool
readRGBAVal(const zeitgeist::ParameterList& in, RGBA& m)
{
    int r,g,b;

    if (
        (in.GetSize() != 4) ||
        (! in.GetValue(in[0], r)) ||
        (! in.GetValue(in[1], g)) ||
        (! in.GetValue(in[2], b)) ||
        (! in.GetValue(in[3], m.a()))
        )
    {
        return false;
    }
    m.r() = r / 255.0;
    m.g() = g / 255.0;
    m.b() = b / 255.0;
    return true;
}
Пример #7
0
RGBA applyAlpha(double a, const RGBA& c) {
    return RGBA(c.r(), c.g(), c.b(), c.a()*a);         
}
Пример #8
0
bool Buffer::add_ctm_data(CTMDecoder& ctm, const glm::mat4& matrix, const RGBA& color, Box& bbox, BufferOffset& offset)
{
	auto vertCnt = ctm.get_vertex_count();
	auto triCnt = ctm.get_tri_count();
	auto indexCnt = triCnt * 3;

	update_buffer_count();

	if ((buf_vertex_count + vertCnt) > MAX_VERTEX_COUNT || (buf_index_count + indexCnt) > MAX_INDEX_COUNT)
		return false;

	vertex_buffer.reserve(buf_vertex_count + vertCnt);
	index_buffer.reserve(buf_index_count + indexCnt);

	transparent = color.is_transparent();

	const float* ctm_vertices = ctm.get_vertices();
	const unsigned int* ctm_indices = ctm.get_indices();

	offset.vertex_offset = buf_vertex_count;
	offset.vertex_count = vertCnt;
	offset.index_offset = buf_index_count;
	offset.index_count = indexCnt;

	for (unsigned int i=0; i < vertCnt; i++)
	{
		glm::vec4 pos(ctm_vertices[i * 3], ctm_vertices[i * 3 + 1], ctm_vertices[i * 3 + 2], 1);
		pos = matrix * pos;
		bbox.add_point(glm::vec3(pos));

		VertexStruct vertex;
		vertex.position[0] = pos.x;
		vertex.position[1] = pos.y;
		vertex.position[2] = pos.z;

		vertex.normal[0] = 0;
		vertex.normal[1] = 0;
		vertex.normal[2] = 0;

		ColorStruct clr;
		clr.color[0] = color.r();
		clr.color[1] = color.g();
		clr.color[2] = color.b();
		clr.color[3] = color.a();

		vertex_buffer.push_back(vertex);
		color_buffer.push_back(clr);
	}

	for (unsigned int i=0; i < indexCnt; i += 3)
	{
		auto i0 = ctm_indices[i] + buf_vertex_count;
		auto i1 = ctm_indices[i + 1] + buf_vertex_count;
		auto i2 = ctm_indices[i + 2] + buf_vertex_count;

		index_buffer.push_back(i0);
		index_buffer.push_back(i1);
		index_buffer.push_back(i2);

		glm::vec3 p0(vertex_buffer[i0].position[0], vertex_buffer[i0].position[1], vertex_buffer[i0].position[2]);
		glm::vec3 p1(vertex_buffer[i1].position[0], vertex_buffer[i1].position[1], vertex_buffer[i1].position[2]);
		glm::vec3 p2(vertex_buffer[i2].position[0], vertex_buffer[i2].position[1], vertex_buffer[i2].position[2]);
		glm::vec3 norm = glm::cross((p1 - p0), (p2 - p0));
		
		vertex_buffer[i0].normal[0] += norm.x;
		vertex_buffer[i0].normal[1] += norm.y;
		vertex_buffer[i0].normal[2] += norm.z;

		vertex_buffer[i1].normal[0] += norm.x;
		vertex_buffer[i1].normal[1] += norm.y;
		vertex_buffer[i1].normal[2] += norm.z;

		vertex_buffer[i2].normal[0] += norm.x;
		vertex_buffer[i2].normal[1] += norm.y;
		vertex_buffer[i2].normal[2] += norm.z;
	}

	for (unsigned int i=0; i < vertCnt; i++)
	{
		glm::vec3 norm(vertex_buffer[buf_vertex_count + i].normal[0], 
					vertex_buffer[buf_vertex_count + i].normal[1], 
					vertex_buffer[buf_vertex_count + i].normal[2]);
		norm = glm::normalize(norm);
		vertex_buffer[buf_vertex_count + i].normal[0] = norm.x;
		vertex_buffer[buf_vertex_count + i].normal[1] = norm.y;
		vertex_buffer[buf_vertex_count + i].normal[2] = norm.z;
	}

	return true;
}
Пример #9
0
u32 Surface::MapRGB(const RGBA & color) const
{
    return amask() ? SDL_MapRGBA(surface->format, color.r(), color.g(), color.b(), color.a()) : SDL_MapRGB(surface->format, color.r(), color.g(), color.b());
}
Пример #10
0
void PngIO::save(const Image* const image, FILE* fp) const {

    png_structp png_ptr;
    png_infop info_ptr;

    int width = image->getWidth();
    int height = image->getHeight();

    /* Create and initialize the png_struct with the desired error handler
     * functions.  If you want to use the default stderr and longjump method,
     * you can supply NULL for the last three parameters.  We also check that
     * the library version is compatible with the one used at compile time,
     * in case we are using dynamically linked libraries.  REQUIRED.
     */
    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
	    NULL, NULL, NULL);

    if (png_ptr == NULL)
    {
	::fclose(fp);
	throw_exception("Error saving PNG");
    }

    /* Allocate/initialize the image information data.  REQUIRED */
    info_ptr = png_create_info_struct(png_ptr);
    if (info_ptr == NULL)
    {
	::fclose(fp);
	png_destroy_write_struct(&png_ptr,  NULL);
	throw_exception("Error saving PNG");
    }

    /* Set error handling.  REQUIRED if you aren't supplying your own
     * error handling functions in the png_create_write_struct() call.
     */
    if (setjmp(png_jmpbuf(png_ptr)))
    {
	/* If we get here, we had a problem reading the file */
	::fclose(fp);
	png_destroy_write_struct(&png_ptr, &info_ptr);
	throw_exception("Error saving ");
    }

    png_init_io(png_ptr, fp);

    png_set_IHDR(png_ptr, info_ptr, width, height, 8, 
	    PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, 
	    PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

    /*
       text_ptr[0].key = "Title";
       text_ptr[0].text = "RayGay Image";
       text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
       text_ptr[1].key = "Author";
       text_ptr[1].text = "RayGay";
       text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
       text_ptr[2].key = "Description";
       text_ptr[2].text = "An image rendered with RayGay";
       text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
#ifdef PNG_iTXt_SUPPORTED
text_ptr[0].lang = NULL;
text_ptr[1].lang = NULL;
text_ptr[2].lang = NULL;
#endif

png_set_text(png_ptr, info_ptr, text_ptr, 3);
*/
    png_write_info(png_ptr, info_ptr);

    /* If you are only writing one row at a time, this works */
    png_byte row[width*4];
    png_bytep rowp = row;

    for (int y = 0; y < height; y++)
    {
	for(int x = 0; x < width; x++) {
	    RGBA pixel = image->getRGBA(x,y);
	    row[x*4 + 0] = int(pixel.r() * 255);
	    row[x*4 + 1] = int(pixel.g() * 255);
	    row[x*4 + 2] = int(pixel.b() * 255);
	    row[x*4 + 3] = int(pixel.a() * 255);
	}
	png_write_rows(png_ptr, &rowp, 1);
    }

    png_write_end(png_ptr, info_ptr);

    /* clean up after the write, and free any memory allocated */
    png_destroy_write_struct(&png_ptr, &info_ptr);
}