Results 1 to 13 of 13

Thread: What is wrong with this code??? (resolved)

Threaded View

  1. #1

    Thread Starter
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    What is wrong with this code??? (resolved)

    [SIZE=24pt]Woooohooo it works!! (resolved)[/SIZE]

    This code will not run no matter what!!! I tried everything... its the function thats causing it to crash??

    Here;s the code.
    Code:
    // Temp2.cpp : Defines the entry point for the console application.
    //
    
    #include <iostream.h>
    #include <math.h>
    #include <stdio.h>
    
    
    struct nTemp
    {
    	unsigned char Temp[18][256][256];
    };
    
    void saveIt(void);
    nTemp loadIt(void);
    
    int main(int argc, char* argv[])
    {
    	saveIt();
    	// thats all.
    
    	cout << "Saved!" << endl;
    	cin.ignore();
    
    	return 0;
    }
    
    void saveIt(void)
    {
    	long temp = 0;
    	long effect = 0;
    	long src = 0;
    	long dest = 0;
    	nTemp myTemp;
    	FILE* f = 0;
    
    	cout << "Saving....\n";
    	for( effect = 0; effect < 18; effect++ )
    	{
    		cout << "Effect: \t\t" << effect << endl;
    		for( dest = 0; dest < 256; dest++ )
    		{
    			for( src = 0; src < 256; src++ )
    			{
    				switch( effect )
    				{
    				case 0:
    					// Add
    					temp = (temp = src + dest) > 255 ? 255 : temp;
    					break;
    					
    				case 1:
    					// Subtract
    					temp = (temp = dest - src) < 0 ? 0 : temp;
    					break;
    					
    				case 2:
    					// Subtract (corrected)
    					temp = (temp = dest - (255 - src)) < 0 ? 0 : temp;
    					break;
    					
    				case 3:
    					// Better Add Effect (Alpha Map to White)
    					temp = (((255 - src) * (dest + 1)) >> 16) - src;
    					break;
    					
    				case 4:
    					// Better Subtract Effect (Alpha Map to Black)
    					temp = ((src * (dest + 256)) >> 16) - src;
    					break;
    					
    				case 5:
    				case 6:
    				case 7:
    				case 8:
    				case 9:
    				case 10:
    				case 11:
    				case 12:
    					// Translucency (5 to 12)
    					temp = (src > 0) ? ((effect - 3) * ((dest + 11) - src)) / 11 + src - (effect - 3) : dest;
    					break;
    					
    				case 13:
    					// Weird Effects (13 - 17)
    					temp = (src > 0) ? ((temp = (dest * atan(dest / src))) > 255 ? 255 : ((temp < 0) ? 0 : temp)) : dest;
    					break;
    					
    				case 14:
    					// Weird Effects (13 - 17)
    					temp = (src > 0) ? ((temp = (dest * sqrt(dest / src))) > 255 ? 255 : ((temp < 0) ? 0 : temp)) : dest;
    					break;
    					
    				case 15:
    					// Weird Effects (13 - 17)
    					temp = (src > 0) ? ((temp = (src * sin(dest / src))) > 255 ? 255 : ((temp < 0) ? 0 : temp)) : dest;
    					break;
    					
    				case 16:
    					// Weird Effects (13 - 17)
    					temp = (src > 0) ? ((temp = (src * cos(dest / src))) > 255 ? 255 : ((temp < 0) ? 0 : temp)) : dest;
    					break;
    					
    				case 17:
    					// Weird Effects (13 - 17)
    					temp = (src > 0) ? ((temp = (sqrt(dest) * sqrt(src))) > 255 ? 255 : ((temp < 0) ? 0 : temp)) : dest;
    					break;
    					
    				//default:
    					// if no effect selected, do nothing.
    					// return;
    				}
    				
    				myTemp.Temp[effect][dest][src] = temp;
    			}
    		}
    	}
    
    	// now write it to a file.
    	f = fopen("spfx.dat", "w+b");
    	fwrite(&myTemp, 1, sizeof(myTemp), f);
    	fclose(f);
    }
    
    nTemp loadIt(void)
    {
    	FILE* f = NULL;
    	nTemp s;
    	cout << "Loading...\n";
    	f = fopen("spfx.dat", "r+b");
    	fread(&s, 1, sizeof(s), f);
    	fclose(f);
    
    	cout << "Loaded!" << endl;
    	cout << "Temp[3][6][9] = " << s.Temp[3][6][9] << endl;
    	return s;
    }
    Sorry, it doesnt wrap...
    Last edited by MoMad; Sep 22nd, 2001 at 12:21 AM.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width