SUTextureCreateFromImageData () behaves platform dependent




We use the SketchUp 2016 SDK for exporting SKP files from our ARCHICAD software and we found that the
SUTextureCreateFromImageData () method behaves differently depending on the platform we use. On Mac OS X this method works as expected if we use an RGBA pixel array, while on Windows we need to use a BGRA pixel array for this.

Here is the scheme of the code we use for creating a texture (not compileable):

	SUGeometryInputRef geometry = SU_INVALID;
	size_t faceIdx = 0;
	... // Here we init the geometry input and add a face to it (this part works)
	// Create a new material input object
	SUMaterialInput matInput;
	SUSetInvalid (matInput.material);
	SUMaterialCreate (&matInput.material);
	SUMaterialSetName (matInput.material, "material");

	// Fill texture image data using ARCHICAD (AC) pixel map representation
	// You can test it replacing AC* constants with specific numbers
	std::vector<SUByte> pixels (ACPixelMapSize * 4);
	for (size_t pixelIdx = 0; pixelIdx < ACPixelMapSize; ++pixelIdx) {
#if defined(WINDOWS)
		// BGRA array
		pixels[4 * pixelIdx] = ACPixelMap[pixelIdx].blue;
		pixels[4 * pixelIdx + 1] = ACPixelMap[pixelIdx].green;
		pixels[4 * pixelIdx + 2] = ACPixelMap[pixelIdx].red;
		pixels[4 * pixelIdx + 3] = ACPixelMap[pixelIdx].alpha ;
		// RGBA array
		pixels[4 * pixelIdx] = ACPixelMap[pixelIdx].red;
		pixels[4 * pixelIdx + 1] = ACPixelMap[pixelIdx].green;
		pixels[4 * pixelIdx + 2] = ACPixelMap[pixelIdx].blue;
		pixels[4 * pixelIdx + 3] = ACPixelMap[pixelIdx].alpha ;
	SUTextureRef skpTexture = SU_INVALID;
	SUTextureCreateFromImageData (&skpTexture, ACPixelMapXSize, ACPixelMapYSize, 32, ());

	// Add texture to material and set material to face
	SUMaterialSetTexture (matInput.material, skpTexture);
	SUMaterialSetType (matInput.material, SUMaterialType_Textured);
	CalculateUVCoords (matInput); // Here the UV coords are set correctly
	SUGeometryInputFaceSetFrontMaterial (geometry, faceIdx, &matInput);
	... // Fill geometry to model and save the model to a file

The code were tested and works well, but this platform dependent behavior seems a bug.
Any idea?

Tamás Zolnai


Hm… that was unknown to me. Doesn’t sound right to me either. I’ve logged this internally as SU-33833 for further investigation. Thank you for the report.


Can confirm this issue at least on Windows 7, using 2016 C API. Surprised the heck out of me.

The issue I have is what happens if this is “fixed” in a future version of Sketchup? We’re then going to have to detect version numbers and apply either BGRA or RGBA so our code is backwards compatible.

Does anyone know is 2017 already fixed this?


The issue I opened isn’t closed yet - so I think it would still be current. I added your concern to the issue.