bool ReadCubeCrossConstructor(FloatPixMapRef sourceImage, RenderFlags flags, SphericalPixelSourceFunction *source, void **context) { if (sourceImage == NULL || context == NULL) return false; ReadCubeContext *cx = malloc(sizeof (ReadCubeContext)); if (cx == NULL) return false; cx->pm = FPMRetain(sourceImage); FPMSize totalSize = FPMGetSize(sourceImage); if (totalSize.width % 4 != 0 || totalSize.height % 3 != 0) { fprintf(stderr, "Cross cube map width must be a multiple of four pixels and height must be a multiple of three pixels.\n"); return false; } cx->faceSize.width = totalSize.width / 4; cx->faceSize.height = totalSize.height / 3; cx->halfWidth = (float)cx->faceSize.width / 2.0; cx->halfHeight = (float)cx->faceSize.height / 2.0; cx->maxX = (float)cx->faceSize.width - 1.0f; cx->maxY = (float)cx->faceSize.height - 1.0f; cx->pxPos = (FPMPoint){ 2 * cx->faceSize.width, 1 * cx->faceSize.height }; cx->nxPos = (FPMPoint){ 0 * cx->faceSize.width, 1 * cx->faceSize.height }; cx->pyPos = (FPMPoint){ 1 * cx->faceSize.width, 0 * cx->faceSize.height }; cx->nyPos = (FPMPoint){ 1 * cx->faceSize.width, 2 * cx->faceSize.height }; cx->pzPos = (FPMPoint){ 1 * cx->faceSize.width, 1 * cx->faceSize.height }; cx->nzPos = (FPMPoint){ 3 * cx->faceSize.width, 1 * cx->faceSize.height }; *context = cx; *source = ReadCube; return true; }
bool ReadCubeConstructor(FloatPixMapRef sourceImage, RenderFlags flags, void **context) { if (sourceImage == NULL || context == NULL) return false; ReadCubeContext *cx = malloc(sizeof (ReadCubeContext)); if (cx == NULL) return false; cx->pm = FPMRetain(sourceImage); FPMSize totalSize = FPMGetSize(sourceImage); if (totalSize.height % 6 != 0) { fprintf(stderr, "Cube map height must be a multiple of six pixels.\n"); return false; } cx->faceSize.width = totalSize.width; cx->faceSize.height = totalSize.height / 6; cx->halfWidth = (float)cx->faceSize.width / 2.0f; cx->halfHeight = (float)cx->faceSize.height / 2.0f; cx->maxX = (float)cx->faceSize.width - 1.0f; cx->maxY = (float)cx->faceSize.height - 1.0f; cx->pxPos = (FPMPoint) { 0, 0 * cx->faceSize.height }; cx->nxPos = (FPMPoint) { 0, 1 * cx->faceSize.height }; cx->pyPos = (FPMPoint) { 0, 2 * cx->faceSize.height }; cx->nyPos = (FPMPoint) { 0, 3 * cx->faceSize.height }; cx->pzPos = (FPMPoint) { 0, 4 * cx->faceSize.height }; cx->nzPos = (FPMPoint) { 0, 5 * cx->faceSize.height }; *context = cx; return true; }