POV-Ray : Newsgroups : povray.unix : Cloud generator. tga2df3 source code? Server Time
24 Apr 2024 16:27:24 EDT (-0400)
  Cloud generator. tga2df3 source code? (Message 1 to 4 of 4)  
From: John Coppens
Subject: Cloud generator. tga2df3 source code?
Date: 19 Jun 2012 12:43:32
Message: <20120619134331.6489b47b.john@johncoppens.com>
Hello people.

Googling around, most of the suggestions for cloud generation seem to
include the use of tga2df3. I cannot find the source code for that
utility anywhere. The original sites, as linked to by all references,
are dead.

Does anyone have the source code laying around? Preferably for Linux?

Or has better suggestions for cloud generation?

John


Post a reply to this message

From: jhu
Subject: Re: Cloud generator. tga2df3 source code?
Date: 28 Jun 2012 17:40:01
Message: <web.4feccf126ccad12fa281e0440@news.povray.org>
John Coppens <joh### [at] johncoppenscom> wrote:
> Hello people.
>
> Googling around, most of the suggestions for cloud generation seem to
> include the use of tga2df3. I cannot find the source code for that
> utility anywhere. The original sites, as linked to by all references,
> are dead.
>
> Does anyone have the source code laying around? Preferably for Linux?
>
> Or has better suggestions for cloud generation?
>
> John

I think I might have it. Although the df3 file format is pretty simple; you
could easily (for varying degrees of "easily") write your own, especially if you
convert from an uncompressed tga file.


Post a reply to this message

From: jhu
Subject: Re: Cloud generator. tga2df3 source code?
Date: 3 Jul 2012 20:40:00
Message: <web.4ff3901d6ccad12fd19b0ec40@news.povray.org>
Here you go (it's Windows source). You can easily modify to make it compile in
Linux.

/*
        convert a series of 24bit uncompressed TGA files
        into a POV-Ray 3.1 df3 density file
*/
#include<stdio.h>
#include<stdlib.h>
#include<dir.h>
#include<string.h>

char *fileNames;
char baseName[256];
int nFiles, longestName;

int convert( void );

int main()
{
        char searchName[256];
        char *fName;
        struct ffblk ff;
        int Err;
        int nameLen;

        printf("Enter base name of files to convert ");
        gets( baseName );
        printf("\n");
        strcpy(searchName,baseName);
        strcat( searchName,"*.tga");
        Err = findfirst(searchName,&ff,0);
        if( Err == -1 )
        {
                printf("Can't find any files matching \'%s\'\n", searchName );
                return 1;
        }
        nFiles = 1;
        longestName = strlen(ff.ff_name);
        while( findnext(&ff) == 0 )
        {
                nFiles++;
                nameLen = strlen(ff.ff_name);
                longestName = max(longestName,nameLen);
        }
        longestName++;
        fileNames = calloc(nFiles,longestName);
        if( !fileNames )
        {
                puts("Couldn't allocate name buffer");
                return 2;
        }
        findfirst(searchName,&ff,0);
        fName = fileNames;
        strcpy( fName, ff.ff_name);
        fName += longestName;
        while( findnext(&ff) == 0 )
        {
                strcpy( fName, ff.ff_name);
                fName += longestName;
        }
        qsort( fileNames, nFiles, longestName, strcmp );
        convert();


        free( fileNames );
        return 0;
}

/* assumes 24bit uncompressed TGA */
int convert( void )
{
        char dfName[256];
        char *fName;
        FILE *tgaFile, *dfFile;
        static int width,height;
        unsigned char d;
        int f,p;
        double i;

        strcpy( dfName, baseName);
        strcat( dfName,".df3");

        /* open first tga to get dimensions */
        tgaFile = fopen( fileNames,"rb");
        fseek( tgaFile, 12,SEEK_SET );
        /* read width,height of first TGA
           low byte first */
        fread( &d,1,1,tgaFile );
        width = d;
        fread( &d,1,1,tgaFile );
        width += ((int)d) << 8;
        fread( &d,1,1,tgaFile );
        height = d;
        fread( &d,1,1,tgaFile );
        height += ((int)d) << 8;
        fclose( tgaFile );

        dfFile = fopen( dfName,"wb");
        /* write width,height,depth of df3 file
           high byte first */
        d = (width >> 8);
        fwrite( &d,1,1,dfFile );
        d = (width & 0xff);
        fwrite( &d,1,1,dfFile );
        d = (height >> 8);
        fwrite( &d,1,1,dfFile );
        d = (height & 0xff);
        fwrite( &d,1,1,dfFile );
        d = (nFiles >> 8);
        fwrite( &d,1,1,dfFile );
        d = (nFiles & 0xff);
        fwrite( &d,1,1,dfFile );

        fName = fileNames;
        for( f = 0; f < nFiles; f++ )
        {
                puts(fName);
                tgaFile = fopen( fName,"rb");
                fseek( tgaFile,18,SEEK_SET);
                for( p = 0; p < width*height; p++ )
                {
                        /* read B,G,R convert to grey level */
                        fread( &d,1,1,tgaFile );
                        i = (double)d*0.11;
                        fread( &d,1,1,tgaFile );
                        i += (double)d*0.59;
                        fread( &d,1,1,tgaFile );
                        i += (double)d*0.30;
                        d = (int)i;
                        fwrite( &d,1,1,dfFile);
                }
                fclose(tgaFile);
                fName += longestName;
        }
        fclose(dfFile);

        return 0;
}


Post a reply to this message

From: John Coppens
Subject: Re: Cloud generator. tga2df3 source code?
Date: 11 Jul 2012 13:00:35
Message: <20120711140033.3ee1d129e60e526e92f5dfc8@johncoppens.com>
On Tue,  3 Jul 2012 20:36:45 EDT
"jhu" <nomail@nomail> wrote:

> Here you go (it's Windows source). You can easily modify to make it compile in
> Linux.

Thanks jhu!


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.