Example #1
0
void GetEncodedRGBValue(const Image* img, unsigned int x, unsigned int y, const GammaCurvePtr& g, RGBColour& col)
{
    if (!img->IsPremultiplied() && img->HasTransparency())
    {
        // data has transparency and is stored non-premultiplied; precompose against a black background
        float fAlpha;
        img->GetRGBAValue(x, y, col.red(), col.green(), col.blue(), fAlpha);
        AlphaPremultiply(col, fAlpha);
    }
    else
    {
        // no need to worry about premultiplication
        img->GetRGBValue(x, y, col.red(), col.green(), col.blue());
    }
    col.red()   = GammaCurve::Encode(g,col.red());
    col.green() = GammaCurve::Encode(g,col.green());
    col.blue()  = GammaCurve::Encode(g,col.blue());
}
Example #2
0
void Evaluate_Density_Pigment(const PIGMENT *pigm, const Vector3d& p, RGBColour& c, TraceThreadData *ttd)
{
	Colour lc;

	c.set(1.0);

	while(pigm != NULL)
	{
		lc.clear();

		Compute_Pigment(lc, pigm, *p, NULL, NULL, ttd);

		c.red()   *= lc.red();
		c.green() *= lc.green();
		c.blue()  *= lc.blue();

		pigm = reinterpret_cast<const PIGMENT *>(pigm->Next);
	}
}
Example #3
0
bool ot_read_file(OT_NODE **root, IStream *fd, const OT_READ_PARAM* param, OT_READ_INFO* info)
{
    bool retval, got_eof;
    int line_num = 0;
    int tempdepth, tx, ty, tz;
    int goodreads = 0;
    int count;
    bool goodparse = true;
    DBL brightness;
    OT_BLOCK bl;
    OT_BLOCK *new_block;
    OT_ID id;
    char normal_string[30], to_nearest_string[30];
    char line[101];

    memset(&bl, 0, sizeof(OT_BLOCK));

    if ( fd != NULL )
    {
        info->Gather_Total.Clear();
        info->Gather_Total_Count = 0;

        while (!(got_eof = fd->getline (line, 99).eof ()) && goodparse)
        {
            switch ( line[0] )
            {
                case 'B':    // the file contains the old radiosity_brightness value
                {
                    if ( sscanf(line, "B%lf\n", &brightness) == 1 )
                    {
                        info->Brightness = brightness;
                    }
                    break;
                }
                case 'P':    // the file made it to the point that the Preview was done
                {
                    info->FirstRadiosityPass = true;
                    break;
                }
                case 'C':
                {
#if (NUM_COLOUR_CHANNELS == 3)
                    RGBColour tempCol;
                    count = sscanf(line, "C%d %lf %lf %lf %s %f %f %f %f %f %s\n", // tw
                                   &tempdepth,      // since you can't scan a short
                                   &bl.Point[X], &bl.Point[Y], &bl.Point[Z],
                                   normal_string,
                                   &tempCol.red(), &tempCol.green(), &tempCol.blue(),
                                   &bl.Harmonic_Mean_Distance,
                                   &bl.Nearest_Distance, to_nearest_string );
                    bl.Illuminance = ToMathColour(tempCol);
#else
                    #error TODO!
#endif

                    // TODO FIXME - read Quality and Brilliance

                    if ( count == 11 )
                    {
                        bl.Bounce_Depth = (short)tempdepth - 1;

                        // normals aren't very critical for direction precision, so they are packed
                        sscanf(normal_string, "%02x%02x%02x", &tx, &ty, &tz);
                        bl.S_Normal[X] = ((double)tx * (1./ 254.))*2.-1.;
                        bl.S_Normal[Y] = ((double)ty * (1./ 254.))*2.-1.;
                        bl.S_Normal[Z] = ((double)tz * (1./ 254.))*2.-1.;
                        bl.S_Normal.normalize();

                        sscanf(to_nearest_string, "%02x%02x%02x", &tx, &ty, &tz);
                        bl.To_Nearest_Surface[X] = ((double)tx * (1./ 254.))*2.-1.;
                        bl.To_Nearest_Surface[Y] = ((double)ty * (1./ 254.))*2.-1.;
                        bl.To_Nearest_Surface[Z] = ((double)tz * (1./ 254.))*2.-1.;
                        bl.To_Nearest_Surface.normalize();

                        line_num++;

                        new_block = reinterpret_cast<OT_BLOCK *>(POV_MALLOC(sizeof (OT_BLOCK), "octree node from file"));
                        if ( new_block != NULL )
                        {
                            POV_MEMCPY(new_block, &bl, sizeof (OT_BLOCK));

                            ot_index_sphere(bl.Point, bl.Harmonic_Mean_Distance * param->RealErrorBound, &id);
                            ot_ins(root, new_block, &id);
                            goodreads++;
                        }
                        else
                        {
                            goodparse = false;    // allocation error, better stop now
                        }
                    }
                    break;
                }

                default:
                {
                    // wrong leading character on line, just try again on next line
                }

            }   // end switch
        } // end while-reading loop

        if ( !got_eof  ||  !goodparse ) {
;// TODO MESSAGE      PossibleError("Cannot process radiosity cache file at line %d.", (int)line_num);
            retval = false;
        }
        else
        {
            if ( goodreads > 0 )
;// TODO MESSAGE         Debug_Info("Reloaded %d values from radiosity cache file.\n", goodreads);
            else
;// TODO MESSAGE         PossibleError("Unable to read any values from the radiosity cache file.");
            retval = true;
        }
    }
    else
    {
        retval = false;
    }

    return retval;
}
Example #4
0
void SetEncodedRGBValue(Image* img, unsigned int x, unsigned int y, const GammaCurvePtr& g, const RGBColour& col)
{
    img->SetRGBValue(x, y, GammaCurve::Decode(g,col.red()), GammaCurve::Decode(g,col.green()), GammaCurve::Decode(g,col.blue()));
}
Example #5
0
void AlphaUnPremultiply(RGBColour& colour, float fAlpha)
{
    AlphaUnPremultiply(colour.red(), colour.green(), colour.blue(), fAlpha);
}
Example #6
0
DblRGBColour SubsurfaceInterior::GetReducedAlbedo(const RGBColour& diffuseReflectance) const
{
	return DblRGBColour(((const PrecomputedReducedAlbedo&)precomputedReducedAlbedo)(diffuseReflectance.red()),
	                    ((const PrecomputedReducedAlbedo&)precomputedReducedAlbedo)(diffuseReflectance.green()),
	                    ((const PrecomputedReducedAlbedo&)precomputedReducedAlbedo)(diffuseReflectance.blue()));
}