Beispiel #1
0
  void deserialize_float(FILE * file, char * name, float * v, bool use_float)
  {
    float f[4];
    fscanf(file, "#%s = %f; \n", name, &v[0]);

    if (use_float)
      deserialize_uint(file, name, (uint *) f);
    else
      deserialize_uint(file, name, (uint *) v);
  }
Beispiel #2
0
int traverse_zooms(int geomfd[4], off_t geom_size[4], char *metabase, unsigned *file_bbox, struct pool **file_keys, unsigned *midx, unsigned *midy, char **layernames, int maxzoom, int minzoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int nlayers, char *prevent) {
	int i;
	for (i = 0; i <= maxzoom; i++) {
		long long most = 0;

		FILE *sub[4];
		int subfd[4];
		int j;
		for (j = 0; j < 4; j++) {
			char geomname[strlen(tmpdir) + strlen("/geom2.XXXXXXXX") + 1];
			sprintf(geomname, "%s/geom%d.XXXXXXXX", tmpdir, j);
			subfd[j] = mkstemp(geomname);
			//printf("%s\n", geomname);
			if (subfd[j] < 0) {
				perror(geomname);
				exit(EXIT_FAILURE);
			}
			sub[j] = fopen(geomname, "wb");
			if (sub[j] == NULL) {
				perror(geomname);
				exit(EXIT_FAILURE);
			}
			unlink(geomname);
		}

		long long todo = 0;
		long long along = 0;
		for (j = 0; j < 4; j++) {
			todo += geom_size[j];
		}

		for (j = 0; j < 4; j++) {
			if (geomfd[j] < 0) {
				// only one source file for zoom level 0
				continue;
			}
			if (geom_size[j] == 0) {
				continue;
			}

			// printf("%lld of geom_size\n", (long long) geom_size[j]);

			char *geom = mmap(NULL, geom_size[j], PROT_READ, MAP_PRIVATE, geomfd[j], 0);
			if (geom == MAP_FAILED) {
				perror("mmap geom");
				exit(EXIT_FAILURE);
			}

			char *geomstart = geom;
			char *end = geom + geom_size[j];

			while (geom < end) {
				int z;
				unsigned x, y;

				deserialize_int(&geom, &z);
				deserialize_uint(&geom, &x);
				deserialize_uint(&geom, &y);

				// fprintf(stderr, "%d/%u/%u\n", z, x, y);

				long long len = write_tile(&geom, metabase, file_bbox, z, x, y, z == maxzoom ? full_detail : low_detail, maxzoom, file_keys, layernames, outdb, droprate, buffer, fname, sub, minzoom, maxzoom, todo, geomstart, along, gamma, nlayers, prevent);

				if (len < 0) {
					return i - 1;
				}

				if (z == maxzoom && len > most) {
					*midx = x;
					*midy = y;
					most = len;
				}
			}

			if (munmap(geomstart, geom_size[j]) != 0) {
				perror("munmap geom");
			}
			along += geom_size[j];
		}

		for (j = 0; j < 4; j++) {
			close(geomfd[j]);
			fclose(sub[j]);

			struct stat geomst;
			if (fstat(subfd[j], &geomst) != 0) {
				perror("stat geom\n");
				exit(EXIT_FAILURE);
			}

			geomfd[j] = subfd[j];
			geom_size[j] = geomst.st_size;
		}
	}

	fprintf(stderr, "\n");
	return maxzoom;
}
AMD_AOFX_DLL_API AOFX_RETURN_CODE AOFX_DebugDeserialize(AOFX_Desc& desc,
                                                        const char*                                            params,
                                                        ID3D11Texture2D**                                      ppT2D[],
                                                        ID3D11ShaderResourceView**                             ppSRV[])
{
    AMD_OUTPUT_DEBUG_STRING("CALL: " AMD_FUNCTION_NAME " \n");

    HRESULT hr = S_OK;
    std::string strParams(params);
    std::wstring wstrParams(strParams.begin(), strParams.end());

    if (ppT2D != NULL && ppSRV != NULL &&
        ppT2D[0] != NULL && ppSRV[0] != NULL)
    {
        std::wstring depth = wstrParams + L".depth.dds";
        hr = DirectX::CreateDDSTextureFromFile(desc.m_pDevice, depth.c_str(), (ID3D11Resource**)ppT2D[0], ppSRV[0]);
        desc.m_pDepthSRV = *ppSRV[0];
    }
    if (ppT2D != NULL && ppSRV != NULL &&
        ppT2D[1] != NULL && ppSRV[1] != NULL)
    {
        std::wstring normal = wstrParams + L".normal.dds";
        hr = DirectX::CreateDDSTextureFromFile(desc.m_pDevice, normal.c_str(), (ID3D11Resource**)ppT2D[1], ppSRV[1]);
        desc.m_pNormalSRV = *ppSRV[1];
    }

    strParams += ".txt";
    FILE * file = fopen(strParams.c_str(), "rt");
    if (file != NULL)
    {
        char readStr[1024];
        uint multiResLayerCount = 0;

        deserialize_uint(file, readStr, (uint *)&multiResLayerCount);
        assert(multiResLayerCount == desc.m_MultiResLayerCount);

        for (uint i = 0; i < desc.m_MultiResLayerCount; i++)
        {
            deserialize_uint(file, readStr, (uint *)&desc.m_LayerProcess[i]);
            deserialize_uint(file, readStr, (uint *)&desc.m_BilateralBlurRadius[i]);
            deserialize_uint(file, readStr, (uint *)&desc.m_SampleCount[i]);
            deserialize_uint(file, readStr, (uint *)&desc.m_NormalOption[i]);
            deserialize_uint(file, readStr, (uint *)&desc.m_TapType[i]);
            deserialize_float(file, readStr, (float *)&desc.m_MultiResLayerScale[i]);
            deserialize_float(file, readStr, (float *)&desc.m_PowIntensity[i]);
            deserialize_float(file, readStr, (float *)&desc.m_RejectRadius[i]);
            deserialize_float(file, readStr, (float *)&desc.m_AcceptRadius[i]);
            deserialize_float(file, readStr, (float *)&desc.m_RecipFadeOutDist[i]);
            deserialize_float(file, readStr, (float *)&desc.m_LinearIntensity[i]);
            deserialize_float(file, readStr, (float *)&desc.m_NormalScale[i]);
            deserialize_float(file, readStr, (float *)&desc.m_ViewDistanceDiscard[i]);
            deserialize_float(file, readStr, (float *)&desc.m_ViewDistanceFade[i]);
            deserialize_float(file, readStr, (float *)&desc.m_DepthUpsampleThreshold[i]);
        }

        deserialize_uint(file, readStr, (uint *)&desc.m_Implementation);

        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[0]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[1]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[2]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View.r[3]);

        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[0]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[1]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[2]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection.r[3]);

        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[0]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[1]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[2]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection.r[3]);

        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[0]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[1]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[2]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_View_Inv.r[3]);

        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[0]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[1]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[2]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Projection_Inv.r[3]);

        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[0]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[1]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[2]);
        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_ViewProjection_Inv.r[3]);

        deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Position);
        deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Direction);
        deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Right);
        deserialize_float3(file, readStr, (float *)&desc.m_Camera.m_Up);

        deserialize_float(file, readStr, (float *)&desc.m_Camera.m_Aspect);
        deserialize_float(file, readStr, (float *)&desc.m_Camera.m_FarPlane);
        deserialize_float(file, readStr, (float *)&desc.m_Camera.m_NearPlane);
        deserialize_float(file, readStr, (float *)&desc.m_Camera.m_Fov);

        deserialize_float4(file, readStr, (float *)&desc.m_Camera.m_Color);

        deserialize_uint2(file, readStr, (uint*)&desc.m_InputSize);

        deserialize_uint(file, readStr, (uint *)&desc.m_OutputChannelsFlag);

        fclose(file);
    }

    return AOFX_RETURN_CODE_SUCCESS;
}