Implementing

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, colour definition fd,

RASTER_SETTINGS *rSet, stands in x1, stands in y1,

stand in x2, stand in y2, int flags) {

char buffer [1000];

char magic [100];

FILE *file;

//int w, h;

int x, y;

int maxPixelValue;

int lightning=100;

stand in minY, maxY, minX, maxX;

int linesize;

char initially [300], path [300];

char *p_output_buffer;

int nRasterXSize, nRasterYSize, destSizeX, destSizeY, count, startX, startY;

 

//if output system has no grid 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 == ZERO) {

//file may be stored in GDS$Raster

DBgetInitialValueText (DBowner (DBowner (DBowner (DBowner (raster)))),

"GDS$RASTER", initially,"");

SYSfullPath ("GDS$RASTER""", rSet >file,

".PPM", path, GDS_RASTER, initially, FALSE);

file = fopen (path, "r");

 

//file may be stored in same directory as the flat

if (file == ZERO) {

PPLANS flat;

PLAN_SETTINGS plSet;

plan=DBowner (DBowner (raster));

DBreturnPlanSettings (flat, &plSet, 1);

SYSfullPath (""plSet.pfad, rSet >file".PPM", path"""", FALSE);

file = fopen (path, "r");

 

//no raster present, give up now

if (file == ZERO) {

return;

}

}

 

}

 

flags | =RASTER_FLAG_SIZE;

 

//get file header with magic and size

if (! fgets (buffer, in 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, in 1000, file)) {

fclose (file);

return;

}

if (buffer [0] =='#') continue;

count=sscanf (buffer, "%d %d", &nRasterXSize, &nRasterYSize);

if (count == 2) break;

}

}

 

//read to rank of pixel values, but we do use it

fscanf (file, "%d", &maxPixelValue);

 

//############################################################################

//

//minX, minY, maxX, maxY are the desired cuttings, 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), ZERO, 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),

ZERO,

"PPM",

ZERO,

ZERO,

PPMplotRasterElement,

PPMdeleteRasterElement

};

 

 

RASTER_PROC * EXPORTENTRY __ RASTER_PROCS (void) {

return &procsPPM;

}