Implementierung | 
    Top Previous Next | 
| 
 #include "..\..\..\include\moskito.h" #include "..\..\..\include\assert.h" #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include "..\..\..\include\loadsave.h" 
 
 //############################################################################## // // Output Pixel to Position (x,y) in Buffer // void putPix( char *p_output_buffer, int linesize, int destSizeX, int destSizeY, int x, int y, int r, int g, int b){ p_output_buffer[y*linesize+3*x+0]=r; p_output_buffer[y*linesize+3*x+1]=g; p_output_buffer[y*linesize+3*x+2]=b; } 
 
 static void DLLENTRY PPMplotRasterElement(PRASTER_ELEMENT raster, int hilightEbene, PZEICHENDATEN data, FarbDefinition fd, RASTER_SETTINGS *rSet, double x1, double y1, double x2, double y2, int flags){ char buffer[1000]; char magic[100]; FILE *file; // int w,h; int x,y; int maxPixelValue; int lightning=100; double minY, maxY,minX,maxX; int linesize; char initial[300], path[300]; char *p_output_buffer; int nRasterXSize, nRasterYSize, destSizeX, destSizeY, count, startX, startY; 
 // if Output System has no Raster leave here if(!data->addRaster) return; 
 /* only use if driver has ability to rescale itself */ // w=fabs(x2-x1)*data->scaleBeforeUse/data->pixelSize; // h=fabs(y2-y1)*data->scaleBeforeUse/data->pixelSize; // if(w>500000) w=500000; // if(h>500000) h=500000; 
 // if zoomed to show only part of Picture // only store this part later minY=0; maxY=1; minX=0; maxX=1; if(data->bottom-data->offsY>y1-data->rotY){ minY=(data->bottom-data->offsY-y1+data->rotY)/(y2-y1)/1.03; } if(data->top-data->offsY<y2-data->rotY){ maxY=(data->top-data->offsY-y1+data->rotY)/(y2-y1)*1.03; } if(data->left-data->offsX>x1-data->rotX){ minX=(data->left-data->offsX-x1+data->rotX)/(x2-x1)/1.03; } if(data->right-data->offsX<x2-data->rotX){ maxX=(data->right-data->offsX-x1+data->rotX)/(x2-x1)*1.03; } if(!(maxX>minX && maxY>minY)){ // Picture is invisible, leave now return; } 
 /* ** Open the input File */ // direct name given file = fopen( rSet->file, "r" ); 
 if (file == NULL) { // file may be stored in GDS$Raster DBgetInitialValueText(DBowner(DBowner(DBowner(DBowner(raster)))), "GDS$RASTER",initial,""); SYSfullPath ( "GDS$RASTER", "", rSet->file, ".PPM",path,GDS_RASTER,initial,FALSE); file = fopen( path, "r" ); 
 // file may be stored in same directory as the plan if (file == NULL) { PPLANS plan; PLAN_SETTINGS plSet; plan=DBowner(DBowner(raster)); DBreturnPlanSettings(plan,&plSet,1); SYSfullPath ( "", plSet.pfad, rSet->file, ".PPM",path,"","",FALSE); file = fopen( path, "r" ); 
 // no raster present, give up now if (file == NULL) { return; } } 
 } 
 flags |=RASTER_FLAG_SIZE; 
 // get file header with magic and size if(!fgets(buffer,1000,file)){ fclose(file); return; } count=sscanf(buffer,"%s %d %d", &magic, &nRasterXSize, &nRasterYSize); if(count<1 || strcmp(magic,"P3")){ fclose(file); return; } if(count<3){ while(TRUE){ if(!fgets(buffer,1000,file)){ fclose(file); return; } if(buffer[0]=='#') continue; count=sscanf(buffer,"%d %d", &nRasterXSize, &nRasterYSize); if(count==2) break; } } 
 // read Range of pixel values, but we do not use it fscanf(file,"%d",&maxPixelValue); 
 //############################################################################ // // minX,minY,maxX,maxY sind die gewünschten Ausschnitte, Wetebereiche 0 - 1 // 
 destSizeX=(maxX-minX)*nRasterXSize; destSizeY=(maxY-minY)*nRasterYSize; startX=minX*nRasterXSize; startY=minY*nRasterYSize; 
 /* only use if driver has ability to rescale itself */ // if(w<nRasterXSize) // destSizeX=(maxX-minX)*w; // else // destSizeX=(maxX-minX)*nRasterXSize; // if(h<nRasterYSize) // destSizeY=(maxY-minY)*h; // else // destSizeY=(maxY-minY)*nRasterYSize; 
 // Allocate Buffer for picture p_output_buffer=Malloc(3*(destSizeX+3)*destSizeY+10000); 
 linesize=(destSizeX*3); 
 //############################################################################## // Read the picture and store values in Array // for(x=0;x<nRasterXSize;x++){ for(y=0;y<nRasterXSize;y++){ int r,g,b; fscanf(file,"%d %d %d",&r,&g,&b); if(x>=startX && x<startX+destSizeX){ if(y>=startY && y<startY+destSizeY){ putPix(p_output_buffer,linesize, destSizeX, destSizeY,x-startX,y-startY,r,g,b); } } } } // //############################################################################## 
 lightning=100; if(data->modLayer[hilightEbene].mLightning){ lightning=data->modLayer[hilightEbene].lightningVal; } 
 data->addRaster(data, fd, 3, destSizeX, destSizeY, p_output_buffer, flags, hilightEbene, x1+minX*(x2-x1), y1+minY*(y2-y1), x1+maxX*(x2-x1), y1+maxY*(y2-y1), NULL, destSizeX*destSizeY*3, lightning, TRUE); 
 Free(p_output_buffer); 
 fclose(file); 
 return; } 
 
 //##################################################################################### 
 static void DLLENTRY PPMdeleteRasterElement(PRASTER_ELEMENT raster, RASTER_SETTINGS *rSet){ } 
 //##################################################################################### 
 
 RASTER_PROC procsPPM={ sizeof(RASTER_PROC), NULL, "PPM", NULL, NULL, PPMplotRasterElement, PPMdeleteRasterElement }; 
 
 RASTER_PROC * EXPORTENTRY __RASTER_PROCS(void){ return &procsPPM; } 
  |