Exemplo n.º 1
0
status_t MesaDriver::CopyPixelsIn(BBitmap *bitmap, BPoint location)
{
	color_space scs = bitmap->ColorSpace();
	color_space dcs = m_bitmap->ColorSpace();

	if (scs != dcs && (dcs != B_RGBA32 || scs != B_RGB32)) {
		printf("CopyPixelsIn(): incompatible color space: %s != %s\n",
			color_space_name(scs),
			color_space_name(dcs));
		return B_BAD_TYPE;
	}
	
	// debugger("CopyPixelsIn()");

	BRect sr = bitmap->Bounds();
	BRect dr = m_bitmap->Bounds();

	sr = sr & dr.OffsetBySelf(location);
	dr = sr.OffsetByCopy(-location.x, -location.y); 
	
	uint8 *ps = (uint8 *) bitmap->Bits();
	uint8 *pd = (uint8 *) m_bitmap->Bits();
	uint32 *s, *d;
	uint32 y;
	for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) {
		s = (uint32 *) (ps + y * bitmap->BytesPerRow());
		s += (uint32) sr.left;
		
		d = (uint32 *) (pd + (y + (uint32) (dr.top - sr.top)) * m_bitmap->BytesPerRow());
		d += (uint32) dr.left;
		
		memcpy(d, s, dr.IntegerWidth() * 4);
	}
	return B_OK;
}
Exemplo n.º 2
0
bool Material::on_frame_begin(
    const Project&      project,
    const Assembly&     assembly)
{
    m_surface_shader = get_uncached_surface_shader();
    m_bsdf = get_uncached_bsdf();
    m_edf = get_uncached_edf();
    m_alpha_map = get_uncached_alpha_map();

    const Source* displacement_source = m_inputs.source("displacement_map");

    if (displacement_source)
    {
        if (dynamic_cast<const TextureSource*>(displacement_source) == 0)
        {
            RENDERER_LOG_ERROR(
                "while defining material \"%s\": a texture instance must be bound "
                "to the \"displacement_map\" input; disabling displacement map for this material.",
                get_name());
        }
        else
        {
            const TextureSource* displacement_map = static_cast<const TextureSource*>(displacement_source);
            const Texture& texture = displacement_map->get_texture_instance().get_texture();

            if (texture.get_color_space() != ColorSpaceLinearRGB)
            {
                RENDERER_LOG_WARNING(
                    "while defining material \"%s\": color space for displacement map \"%s\" "
                    "should be \"%s\" but is \"%s\" instead; expect artifacts and/or slowdowns.",
                    get_name(),
                    texture.get_name(),
                    color_space_name(ColorSpaceLinearRGB),
                    color_space_name(texture.get_color_space()));
            }

            // Retrieve the displacement method and create the normal modifier.
            const string displacement_method =
                m_params.get_required<string>("displacement_method", "bump");
            if (displacement_method == "bump")
            {
                const double amplitude = m_params.get_optional<double>("bump_amplitude", 1.0);
                m_normal_modifier = new BumpMappingModifier(displacement_map, 2.0, amplitude);
            }
            else if (displacement_method == "normal")
                m_normal_modifier = new NormalMappingModifier(displacement_map);
            else
            {
                RENDERER_LOG_ERROR(
                    "while defining material \"%s\": invalid value \"%s\" for parameter "
                    "\"displacement_method\"; disabling displacement map for this material.",
                    get_name(),
                    displacement_method.c_str());
            }
        }
    }

    return true;
}
Exemplo n.º 3
0
IBasisModifier* Material::create_basis_modifier(const MessageContext& context) const
{
    // Retrieve the source bound to the displacement map input.
    const Source* displacement_source = m_inputs.source("displacement_map");

    // Nothing to do if there is no displacement source.
    if (displacement_source == 0)
        return 0;

    // Only texture instances can be bound to the displacement map input.
    if (dynamic_cast<const TextureSource*>(displacement_source) == 0)
    {
        RENDERER_LOG_ERROR(
            "%s: a texture instance must be bound to the \"displacement_map\" input.",
            context.get());
        return 0;
    }

    // Retrieve the displacement texture.
    const TextureSource* displacement_map = static_cast<const TextureSource*>(displacement_source);
    const Texture& texture = displacement_map->get_texture_instance().get_texture();

    // Print a warning if the displacement texture is not expressed in the linear RGB color space.
    if (texture.get_color_space() != ColorSpaceLinearRGB)
    {
        RENDERER_LOG_WARNING(
            "%s: color space for displacement map \"%s\" "
            "should be \"%s\" but is \"%s\" instead; expect artifacts and/or slowdowns.",
            context.get(),
            texture.get_path().c_str(),
            color_space_name(ColorSpaceLinearRGB),
            color_space_name(texture.get_color_space()));
    }

    // Retrieve the displacement method.
    const string displacement_method =
        m_params.get_required<string>(
            "displacement_method",
            "bump",
            make_vector("bump", "normal"),
            context);

    // Create the basis modifier.
    if (displacement_method == "bump")
    {
        const float offset = m_params.get_optional<float>("bump_offset", 2.0f);
        const float amplitude = m_params.get_optional<float>("bump_amplitude", 1.0f);
        return new BumpMappingModifier(displacement_map, offset, amplitude);
    }
    else
    {
        const NormalMappingModifier::UpVector up_vector =
            m_params.get_optional<string>("normal_map_up", "z", make_vector("y", "z"), context) == "y"
                ? NormalMappingModifier::UpVectorY
                : NormalMappingModifier::UpVectorZ;
        return new NormalMappingModifier(displacement_map, up_vector);
    }
}
Exemplo n.º 4
0
void Frame::print_settings()
{
    RENDERER_LOG_INFO(
        "frame settings:\n"
        "  resolution       %s x %s\n"
        "  tile size        %s x %s\n"
        "  pixel format     %s\n"
        "  filter           %s\n"
        "  filter size      %f\n"
        "  color space      %s\n"
        "  premult. alpha   %s\n"
        "  clamping         %s\n"
        "  gamma correction %f\n"
        "  crop window      (%s, %s)-(%s, %s)",
        pretty_uint(impl->m_frame_width).c_str(),
        pretty_uint(impl->m_frame_height).c_str(),
        pretty_uint(impl->m_tile_width).c_str(),
        pretty_uint(impl->m_tile_height).c_str(),
        pixel_format_name(impl->m_pixel_format),
        impl->m_filter_name.c_str(),
        impl->m_filter_radius,
        color_space_name(m_color_space),
        m_is_premultiplied_alpha ? "on" : "off",
        impl->m_clamp ? "on" : "off",
        impl->m_target_gamma,
        pretty_uint(impl->m_crop_window.min[0]).c_str(),
        pretty_uint(impl->m_crop_window.min[1]).c_str(),
        pretty_uint(impl->m_crop_window.max[0]).c_str(),
        pretty_uint(impl->m_crop_window.max[1]).c_str());
}
Exemplo n.º 5
0
SoftPipeRenderer::SoftPipeRenderer(BGLView *view, ulong options,
		BGLDispatcher* dispatcher)
	: BGLRenderer(view, options, dispatcher),
	fBitmap(NULL),
	fDirectModeEnabled(false),
	fInfo(NULL),
	fInfoLocker("info locker"),
	fOptions(options),
	fColorSpace(B_NO_COLOR_SPACE)
{
	CALLED();
	time_t beg, end;
	beg = time(NULL);
	hsp_init(options);
	end = time(NULL);
	TRACE("hsp_init time: %f.\n", difftime(end, beg));
	BRect b = GLView()->Bounds();
	fColorSpace = B_RGBA32;
	if (fDirectModeEnabled && fInfo != NULL) {
		fColorSpace = BScreen(GLView()->Window()).ColorSpace();
	}
	int32 width = b.IntegerWidth();// + 1;
	int32 height = b.IntegerHeight();// + 1;
	TRACE("ColorSpace:\t%s\n", color_space_name(fColorSpace));
	fBitmap = new BBitmap(BRect(0.f, 0.f, width /*- 1*/, height /*- 1*/), fColorSpace);
	fWidth = width;
	fHeight = height;
	beg = time(NULL);
	fContext = hsp_create_layer_context(fBitmap, 0);
	TRACE("context:\t%d\n", (int)fContext);
	end = time(NULL);
	TRACE("hsp_create_layer_context time: %f.\n", difftime(end, beg));
	if (!hsp_get_current_context())
		LockGL();
}
Exemplo n.º 6
0
void ColorEntity::extract_parameters()
{
    // Retrieve the color space.
    const ColorSpace DefaultColorSpace = ColorSpaceSRGB;
    const char* DefaultColorSpaceName = color_space_name(DefaultColorSpace);
    const string color_space = m_params.get_required<string>("color_space", DefaultColorSpaceName);
    if (color_space == "linear_rgb")
        impl->m_color_space = ColorSpaceLinearRGB;
    else if (color_space == "srgb")
        impl->m_color_space = ColorSpaceSRGB;
    else if (color_space == "ciexyz")
        impl->m_color_space = ColorSpaceCIEXYZ;
    else if (color_space == "spectral")
        impl->m_color_space = ColorSpaceSpectral;
    else
    {
        RENDERER_LOG_ERROR(
            "invalid value \"%s\" for parameter \"color_space\", "
            "using default value \"%s\".",
            color_space.c_str(),
            DefaultColorSpaceName);
        impl->m_color_space = DefaultColorSpace;
    }

    // For the spectral color space, retrieve the wavelength range.
    if (impl->m_color_space == ColorSpaceSpectral)
    {
        const Vector2f DefaultWavelengthRange(LowWavelength, HighWavelength);
        impl->m_wavelength_range =
            m_params.get_required<Vector2f>(
                "wavelength_range",
                DefaultWavelengthRange);

        if (impl->m_wavelength_range[0] < 0.0 ||
            impl->m_wavelength_range[1] < 0.0 ||
            impl->m_wavelength_range[0] > impl->m_wavelength_range[1])
        {
            RENDERER_LOG_ERROR(
                "invalid value \"%f %f\" for parameter \"%s\", "
                "using default value \"%f %f\".",
                impl->m_wavelength_range[0],
                impl->m_wavelength_range[1],
                "wavelength_range",
                DefaultWavelengthRange[0],
                DefaultWavelengthRange[1]);

            impl->m_wavelength_range = DefaultWavelengthRange;
        }
    }
    else
    {
        impl->m_wavelength_range[0] =
        impl->m_wavelength_range[1] = 0.0f;
    }

    // Retrieve multiplier.
    impl->m_multiplier = m_params.get_optional<float>("multiplier", 1.0f);
}
Exemplo n.º 7
0
status_t
IntelRenderer::CopyPixelsIn(BBitmap *bitmap, BPoint location)
{
	CALLED();

	color_space sourceCS = bitmap->ColorSpace();
	color_space destinationCS = fBitmap->ColorSpace();

	if (sourceCS != destinationCS
		&& (sourceCS != B_RGB32 || destinationCS != B_RGBA32)) {
		ERROR("%s::CopyPixelsIn(): incompatible color space: %s != %s\n",
			__PRETTY_FUNCTION__, color_space_name(sourceCS),
			color_space_name(destinationCS));
		return B_BAD_TYPE;
	}

	BRect sr = bitmap->Bounds();
	BRect dr = fBitmap->Bounds();

	sr = sr & dr.OffsetBySelf(location);
	dr = sr.OffsetByCopy(-location.x, -location.y);

	uint8 *ps = (uint8 *) bitmap->Bits();
	uint8 *pd = (uint8 *) fBitmap->Bits();
	uint32 *s, *d;
	uint32 y;

	for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) {
		s = (uint32 *)(ps + y * bitmap->BytesPerRow());
		s += (uint32) sr.left;

		d = (uint32 *)(pd + (y + (uint32)(dr.top - sr.top))
			* fBitmap->BytesPerRow());
		d += (uint32) dr.left;

		memcpy(d, s, dr.IntegerWidth() * 4);
	}

	return B_OK;
}
Exemplo n.º 8
0
status_t
SoftwareRenderer::CopyPixelsOut(BPoint location, BBitmap *bitmap)
{
	CALLED();
	color_space scs = fBitmap->ColorSpace();
	color_space dcs = bitmap->ColorSpace();

	if (scs != dcs && (scs != B_RGBA32 || dcs != B_RGB32)) {
		ERROR("%s::CopyPixelsOut(): incompatible color space: %s != %s\n",
			__PRETTY_FUNCTION__, color_space_name(scs), color_space_name(dcs));
		return B_BAD_TYPE;
	}

	BRect sr = fBitmap->Bounds();
	BRect dr = bitmap->Bounds();

//	int32 w1 = sr.IntegerWidth();
//	int32 h1 = sr.IntegerHeight();
//	int32 w2 = dr.IntegerWidth();
//	int32 h2 = dr.IntegerHeight();

	sr = sr & dr.OffsetBySelf(location);
	dr = sr.OffsetByCopy(-location.x, -location.y);

	uint8 *ps = (uint8 *) fBitmap->Bits();
	uint8 *pd = (uint8 *) bitmap->Bits();
	uint32 *s, *d;
	uint32 y;
	for (y = (uint32) sr.top; y <= (uint32) sr.bottom; y++) {
		s = (uint32 *)(ps + y * fBitmap->BytesPerRow());
		s += (uint32) sr.left;

		d = (uint32 *)(pd + (y + (uint32)(dr.top - sr.top))
			* bitmap->BytesPerRow());
		d += (uint32) dr.left;
		memcpy(d, s, dr.IntegerWidth() * 4);
	}

	return B_OK;
}
Exemplo n.º 9
0
IntelRenderer::IntelRenderer(BGLView *view, ulong options,
	BGLDispatcher* dispatcher)
	:
	BGLRenderer(view, options, dispatcher),
	fBitmap(NULL),
	fDirectModeEnabled(false),
	fInfo(NULL),
	fInfoLocker("info locker"),
	fOptions(options),
	fColorSpace(B_NO_COLOR_SPACE)
{
	CALLED();

	// Disable double buffer for the moment.
	options &= ~BGL_DOUBLE;

	// Initialize the "Haiku Software GL Pipe"
	time_t beg;
	time_t end;
	beg = time(NULL);
	fContextObj = new GalliumContext(options);
	end = time(NULL);
	TRACE("Haiku Intel GL Pipe initialization time: %f.\n",
		difftime(end, beg));

	// Allocate a bitmap
	BRect b = view->Bounds();
	fColorSpace = BScreen(view->Window()).ColorSpace();
	TRACE("%s: Colorspace:\t%s\n", __func__, color_space_name(fColorSpace));

	fWidth = (GLint)b.IntegerWidth();
	fHeight = (GLint)b.IntegerHeight();
	fNewWidth = fWidth;
	fNewHeight = fHeight;

	_AllocateBitmap();

	// Initialize the first "Haiku Intel GL Pipe" context
	beg = time(NULL);
	fContextID = fContextObj->CreateContext(fBitmap);
	end = time(NULL);

	if (fContextID < 0)
		ERROR("%s: There was an error creating the context!\n", __func__);
	else {
		TRACE("%s: Haiku Intel GL Pipe context creation time: %f.\n",
			__func__, difftime(end, beg));
	}

	if (!fContextObj->GetCurrentContext())
		LockGL();
}
Exemplo n.º 10
0
void ColorEntity::check_validity()
{
    // Check the number of color values.
    if (impl->m_color_space == ColorSpaceSpectral)
    {
        if (impl->m_values.empty())
        {
            RENDERER_LOG_ERROR("1 or more values required for \"spectral\" color space, got 0.");
        }
    }
    else
    {
        if (impl->m_values.size() != 1 && impl->m_values.size() != 3)
        {
            RENDERER_LOG_ERROR(
                "1 or 3 values required for \"%s\" color space, got " FMT_SIZE_T ".",
                color_space_name(impl->m_color_space),
                impl->m_values.size());
        }
    }
}
Exemplo n.º 11
0
static void fill_metadata(opj_image_t *img, GP_DataStorage *storage)
{
	unsigned int i;

	GP_DataStorageAddInt(storage, NULL, "Width", img->x1 - img->x0);
	GP_DataStorageAddInt(storage, NULL, "Height", img->y1 - img->y0);
	GP_DataStorageAddString(storage, NULL, "Color Space",
	                        color_space_name(img->color_space));
	GP_DataStorageAddInt(storage, NULL, "Samples per Pixel", img->numcomps);

	for (i = 0; i < img->numcomps; i++) {
		char buf[32];
		GP_DataNode *comp_node;

		snprintf(buf, sizeof(buf), "Channel %u", i);

		comp_node = GP_DataStorageAddDict(storage, NULL, buf);

		GP_DataStorageAddInt(storage, comp_node, "Width", img->comps[i].w);
		GP_DataStorageAddInt(storage, comp_node, "Height", img->comps[i].h);
		GP_DataStorageAddInt(storage, comp_node, "Bits per Sample", img->comps[i].prec);
	}
}
Exemplo n.º 12
0
int GP_ReadJP2Ex(GP_IO *io, GP_Context **rimg, GP_DataStorage *storage,
                 GP_ProgressCallback *callback)
{
	opj_dparameters_t params;
	opj_codec_t *codec;
	opj_stream_t *stream;
	opj_image_t *img;

	GP_PixelType pixel_type;
	GP_Context *res = NULL;
	unsigned int i, x, y;
	int err = 0, ret = 1;

	opj_set_default_decoder_parameters(&params);

	codec = opj_create_decompress(OPJ_CODEC_JP2);

	if (!codec) {
		GP_DEBUG(1, "opj_create_decompress failed");
		err = ENOMEM;
		goto err0;
	}

	opj_set_error_handler(codec, jp2_err_callback, NULL);
	opj_set_warning_handler(codec, jp2_warn_callback, NULL);
	opj_set_info_handler(codec, jp2_info_callback, callback);

	if (!opj_setup_decoder(codec, &params)) {
		GP_DEBUG(1, "opj_setup_decoder failed");
		err = ENOMEM;
		goto err1;
	}

	stream = opj_stream_default_create(OPJ_TRUE);

	if (!stream) {
		GP_DEBUG(1, "opj_stream_create_default_file_stream faled");
		err = ENOMEM;
		goto err1;
	}

	//TODO: Do we need seek and skip?
	opj_stream_set_read_function(stream, jp2_io_read);
	opj_stream_set_user_data(stream, io);

	if (!opj_read_header(stream, codec, &img)) {
		GP_DEBUG(1, "opj_read_header failed");
		err = EINVAL;
		goto err2;
	}

	if (storage)
		fill_metadata(img, storage);

	GP_DEBUG(1, "Have image %ux%u-%ux%u colorspace=%s numcomps=%u",
	         img->x0, img->y0, img->x1, img->y1,
	         color_space_name(img->color_space), img->numcomps);

	if (!rimg)
		return 0;

	/*
	 * Try to match the image information into pixel type.
	 *
	 * Unfortunately the images I had have color_space set
	 * to unspecified yet they were RGB888.
	 */
	for (i = 0; i < img->numcomps; i++) {
		opj_image_comp_t *comp = &img->comps[i];

		GP_DEBUG(2, "Component %u %ux%u bpp=%u",
		         i, comp->w, comp->h, comp->prec);

		if (comp->w != img->comps[0].w ||
		    comp->h != img->comps[0].h) {
			GP_DEBUG(1, "Component %u has different size", 1);
			err = ENOSYS;
			goto err3;
		}

		if (comp->prec != 8) {
			GP_DEBUG(1, "Component %u has different bpp", 1);
			err = ENOSYS;
			goto err3;
		}
	}

	switch (img->color_space) {
	case OPJ_CLRSPC_UNSPECIFIED:
		if (img->numcomps != 3) {
			GP_DEBUG(1, "Unexpected number of components");
			err = ENOSYS;
			goto err3;
		}
		pixel_type = GP_PIXEL_RGB888;
	break;
	default:
		GP_DEBUG(1, "Unsupported colorspace");
		err = ENOSYS;
		goto err3;
	}

	GP_ProgressCallbackReport(callback, 0, 100, 100);

	if (!opj_decode(codec, stream, img)) {
		GP_DEBUG(1, "opj_decode failed");
		err = EINVAL;
		goto err3;
	}

	res = GP_ContextAlloc(img->comps[0].w, img->comps[0].h, pixel_type);

	if (!res) {
		GP_DEBUG(1, "Malloc failed :(");
		err = ENOMEM;
		goto err3;
	}

	for (y = 0; y < res->h; y++) {
		for (x = 0; x < res->w; x++) {
			i = y * res->w + x;

			GP_Pixel p = img->comps[0].data[i] << 16|
			             img->comps[1].data[i] << 8 |
			             img->comps[2].data[i];

			GP_PutPixel_Raw_24BPP(res, x, y, p);
		}
	}

	GP_ProgressCallbackDone(callback);
	*rimg = res;
	ret = 0;
err3:
	opj_image_destroy(img);
err2:
	opj_stream_destroy(stream);
err1:
	opj_destroy_codec(codec);
err0:
	if (err)
		errno = err;
	return ret;
}
status_t
MesaSoftwareRenderer::_SetupRenderBuffer(
	struct msr_renderbuffer* buffer, color_space colorSpace)
{
	CALLED();

	buffer->base.DataType = GL_UNSIGNED_BYTE;
	buffer->base.Data = NULL;

	switch (colorSpace) {
		case B_RGBA32:
			buffer->base._BaseFormat = GL_RGBA;
			buffer->base.Format = MESA_FORMAT_ARGB8888;

			buffer->base.GetRow = get_row_RGBA32;
			buffer->base.GetValues = get_values_RGBA32;
			buffer->base.PutRow = put_row_RGBA32;
			buffer->base.PutValues = put_values_RGBA32;
#if HAIKU_MESA_VER <= 711
			buffer->base.PutRowRGB = put_row_rgb_RGBA32;
			buffer->base.PutMonoRow = put_mono_row_RGBA32;
			buffer->base.PutMonoValues = put_values_RGBA32;
#endif
			break;
		case B_RGB32:
			buffer->base._BaseFormat = GL_RGB;
#if HAIKU_MESA_VER >= 709
			// XRGB8888 only in newer Mesa
			buffer->base.Format = MESA_FORMAT_XRGB8888;
#else
			buffer->base.Format = MESA_FORMAT_ARGB8888;
#endif

			buffer->base.GetRow = get_row_RGB32;
			buffer->base.GetValues = get_values_RGB32;
			buffer->base.PutRow = put_row_RGB32;
			buffer->base.PutValues = put_values_RGB32;
#if HAIKU_MESA_VER <= 711
			buffer->base.PutRowRGB = put_row_rgb_RGB32;
			buffer->base.PutMonoRow = put_mono_row_RGB32;
			buffer->base.PutMonoValues = put_values_RGB32;
#endif
			break;
		case B_RGB24:
			buffer->base._BaseFormat = GL_RGB;
			buffer->base.Format = MESA_FORMAT_RGB888;

			buffer->base.GetRow = get_row_RGB24;
			buffer->base.GetValues = get_values_RGB24;
			buffer->base.PutRow = put_row_RGB24;
			buffer->base.PutValues = put_values_RGB24;
#if HAIKU_MESA_VER <= 711
			buffer->base.PutRowRGB = put_row_rgb_RGB24;
			buffer->base.PutMonoRow = put_mono_row_RGB24;
			buffer->base.PutMonoValues = put_values_RGB24;
#endif
			break;
		case B_RGB16:
			buffer->base._BaseFormat = GL_RGB;
			buffer->base.Format = MESA_FORMAT_RGB565;

			buffer->base.GetRow = get_row_RGB16;
			buffer->base.GetValues = get_values_RGB16;
			buffer->base.PutRow = put_row_RGB16;
			buffer->base.PutValues = put_values_RGB16;
#if HAIKU_MESA_VER <= 711
			buffer->base.PutRowRGB = put_row_rgb_RGB16;
			buffer->base.PutMonoRow = put_mono_row_RGB16;
			buffer->base.PutMonoValues = put_values_RGB16;
#endif
			break;
		case B_RGB15:
			buffer->base._BaseFormat = GL_RGB;
			buffer->base.Format = MESA_FORMAT_ARGB1555;

			buffer->base.GetRow = get_row_RGB15;
			buffer->base.GetValues = get_values_RGB15;
			buffer->base.PutRow = put_row_RGB15;
			buffer->base.PutValues = put_values_RGB15;
#if HAIKU_MESA_VER <= 711
			buffer->base.PutRowRGB = put_row_rgb_RGB15;
			buffer->base.PutMonoRow = put_mono_row_RGB15;
			buffer->base.PutMonoValues = put_values_RGB15;
#endif
			break;
		default:
			fprintf(stderr, "Unsupported screen color space %s\n",
				color_space_name(fColorSpace));
			debugger("Unsupported OpenGL color space");
			return B_ERROR;
	}
	return B_OK;
}