コード例 #1
0
static
int StripBasedXform(cmsHTRANSFORM hXForm, TIFF* in, TIFF* out, int nPlanes)
{
    tsize_t BufSizeIn  = TIFFStripSize(in);
    tsize_t BufSizeOut = TIFFStripSize(out);
    unsigned char *BufferIn, *BufferOut;
    ttile_t i, StripCount = TIFFNumberOfStrips(in) / nPlanes;
    uint32 sw;
    uint32 sl;
    uint32 iml;
    int j;
    int PixelCount;

    TIFFGetFieldDefaulted(in, TIFFTAG_IMAGEWIDTH,  &sw);
    TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &sl);
    TIFFGetFieldDefaulted(in, TIFFTAG_IMAGELENGTH, &iml);

   

    BufferIn = (unsigned char *) _TIFFmalloc(BufSizeIn * nPlanes);
    if (!BufferIn) OutOfMem(BufSizeIn * nPlanes);

    BufferOut = (unsigned char *) _TIFFmalloc(BufSizeOut * nPlanes);
    if (!BufferOut) OutOfMem(BufSizeOut * nPlanes);


    for (i = 0; i < StripCount; i++) {

        for (j=0; j < nPlanes; j++) {

            if (TIFFReadEncodedStrip(in, i + (j * StripCount), 
                                        BufferIn + (j * BufSizeIn), BufSizeIn) < 0)   goto cleanup;
        }

        PixelCount = (int) sw * (iml < sl ? iml : sl);
        iml -= sl;

        cmsDoTransform(hXForm, BufferIn, BufferOut, PixelCount);

        for (j=0; j < nPlanes; j++) {
            if (TIFFWriteEncodedStrip(out, i + (j * StripCount), 
                                     BufferOut + j * BufSizeOut, BufSizeOut) < 0) goto cleanup;
        }

    }

    _TIFFfree(BufferIn);
    _TIFFfree(BufferOut);
    return 1;


cleanup:

    _TIFFfree(BufferIn);
   _TIFFfree(BufferOut);
   return 0;
}
コード例 #2
0
static
int TileBasedXform(cmsHTRANSFORM hXForm, TIFF* in, TIFF* out, int nPlanes)
{
    tsize_t BufSizeIn  = TIFFTileSize(in);
    tsize_t BufSizeOut = TIFFTileSize(out);
    unsigned char *BufferIn, *BufferOut;
    ttile_t i, TileCount = TIFFNumberOfTiles(in) / nPlanes;
    uint32 tw, tl;
    int PixelCount, j;


    TIFFGetFieldDefaulted(in, TIFFTAG_TILEWIDTH,  &tw);
    TIFFGetFieldDefaulted(in, TIFFTAG_TILELENGTH, &tl);

     PixelCount = (int) tw * tl;

     BufferIn = (unsigned char *) _TIFFmalloc(BufSizeIn * nPlanes);
    if (!BufferIn) OutOfMem(BufSizeIn * nPlanes);

    BufferOut = (unsigned char *) _TIFFmalloc(BufSizeOut * nPlanes);
    if (!BufferOut) OutOfMem(BufSizeOut * nPlanes);


    for (i = 0; i < TileCount; i++) {

        for (j=0; j < nPlanes; j++) {

            if (TIFFReadEncodedTile(in, i + (j* TileCount), 
                                    BufferIn + (j*BufSizeIn), BufSizeIn) < 0)   goto cleanup;
        }

      cmsDoTransform(hXForm, BufferIn, BufferOut, PixelCount);

      for (j=0; j < nPlanes; j++) {

             if (TIFFWriteEncodedTile(out, i + (j*TileCount),
                                    BufferOut + (j*BufSizeOut), BufSizeOut) < 0) goto cleanup;
      }

    }

    _TIFFfree(BufferIn);
    _TIFFfree(BufferOut);
    return 1;


cleanup:

    _TIFFfree(BufferIn);
   _TIFFfree(BufferOut);
   return 0;
}
コード例 #3
0
ファイル: screenshot.cpp プロジェクト: AMDmi3/symwars3
void SaveScreenshot()
{
	Player* py = &g_player[g_curP];

	LoadedTex screenshot;
	screenshot.channels = 3;
	screenshot.sizeX = py->width;
	screenshot.sizeY = py->height;
	screenshot.data = (unsigned char*)malloc( sizeof(unsigned char) * py->width * py->height * 3 );

	if(!screenshot.data)
	{
		OutOfMem(__FILE__, __LINE__);
		return;
	}

	memset(screenshot.data, 0, py->width * py->height * 3);

	glReadPixels(0, 0, py->width, py->height, GL_RGB, GL_UNSIGNED_BYTE, screenshot.data);

	FlipImage(&screenshot);

	char relative[256];
	std::string datetime = FileDateTime();
	sprintf(relative, "screenshots/%s.jpg", datetime.c_str());
	char fullpath[MAX_PATH+1];
	FullPath(relative, fullpath);

	g_log<<"Writing screenshot "<<fullpath<<std::endl;
	g_log.flush();

	SaveJPEG(fullpath, &screenshot, 0.9f);

	//free(screenshot.data);
}
コード例 #4
0
ファイル: main.c プロジェクト: meesokim/z88dk
void *mymalloc(size_t size)
{
   void *ptr;

   if   ( (ptr=calloc(size,1)) != NULL ) return ptr;
   else OutOfMem();
   return 0;   /* Sigh */
}
コード例 #5
0
ファイル: getpassword.c プロジェクト: glance-/conserver
char *
GetPassword(char *prompt)
{
    int fd;
    int nc;
    char buf[BUFSIZ];
    int done = 0;

    if (prompt == (char *)0)
	prompt = "";
    if ((pass = AllocString()) == (STRING *)0)
	OutOfMem();
    BuildString((char *)0, pass);

    if ((fd = open("/dev/tty", O_RDWR)) == -1) {
	Error("could not open `/dev/tty': %s", strerror(errno));
	return (char *)0;
    }

    C2Raw(fd);
    write(fd, prompt, strlen(prompt));
    while (!done) {
	int i;
	if ((nc = read(0, buf, sizeof(buf))) == 0)
	    break;
	for (i = 0; i < nc; ++i) {
	    if (buf[i] == 0x0d || buf[i] == 0x0a) {
		/* CR, NL */
		done = 1;
		break;
	    } else
		BuildStringChar(buf[i], pass);
	}
    }
    C2Normal(fd);
    /*
       {
       static STRING *c = (STRING *) 0;
       if ((c = AllocString()) == (STRING *) 0)
       OutOfMem();
       write(fd, "\n'", 2);
       if (pass->used) {
       FmtCtlStr(pass->string, pass->used - 1, c);
       write(fd, c->string, c->used - 1);
       }
       write(fd, "'\n", 2);
       }
     */
    write(fd, "\n", 1);
    close(fd);
    /* this way a (char*)0 is only returned on error */
    if (pass->string == (char *)0)
	return "";
    else
	return pass->string;
}
コード例 #6
0
/*
 * MyStrdup()
 *
 * duplicates the string 'str' and returns a pointer to the new string
 */
char *MyStrdup(const char *str)
{
  char *newstr;

  newstr = strdup(str);
  if (!newstr)
    OutOfMem();

  return(newstr);
} /* MyStrdup() */
コード例 #7
0
/*
 * MyRealloc()
 *
 * calls realloc() with 'oldptr' and 'newsize'; returns pointer to
 * allocated memory if successful, otherwise calls OutOfMem()
 */
void *MyRealloc(void *oldptr, size_t newsize)
{
  void *ptr;

  ptr = realloc(oldptr, newsize);
  if (!ptr)
    OutOfMem();

  return(ptr);
} /* MyRealloc() */
コード例 #8
0
/*
 * MyMalloc()
 *
 * attempt to malloc 'bytes' bytes of memory; returns a pointer to
 * allocated memory if successful, otherwise calls OutOfMem()
*/
void *MyMalloc(size_t bytes)
{
  void *ptr;

  ptr = malloc(bytes);
  if (!ptr)
    OutOfMem();

  return(ptr);
} /* MyMalloc() */
コード例 #9
0
ファイル: BstClass.cpp プロジェクト: gordondr196/BstClass
node<ItemType>* BstClass<ItemType>::Allocate()
{
	node<ItemType>* newNode;
	newNode = new node<ItemType>;

	if (newNode == nullptr)
		throw OutOfMem("Node Creation Failed, Program Terminating...");
	else
	{
		newNode->left = nullptr;
		newNode->right = nullptr;
		return newNode;
	}//end else
}//end Allocate
コード例 #10
0
ファイル: fallback.c プロジェクト: conserver/conserver
/*
 * get a pty using the GetPseudoTTY code above
 */
int
FallBack(char **slave, int *sfd)
{
    int fd;
    static STRING *pcTSlave = (STRING *)0;

    if (pcTSlave == (STRING *)0)
	pcTSlave = AllocString();

    if ((fd = GetPseudoTTY(pcTSlave, sfd)) == -1) {
	return -1;
    }
    if ((*slave) != (char *)0)
	free(*slave);
    if (((*slave) = StrDup(pcTSlave->string))
	== (char *)0)
	OutOfMem();
    return fd;
}
コード例 #11
0
ファイル: main.c プロジェクト: meesokim/z88dk
/*
 *      Compiler begins execution here
 */
int main(int argc, char **argv)
{
        int     n;      /* Loop counter */
		int     i;
        gargc = argc ;
        gargv = argv ;
/*
 * Empty our mem ptrs
 */

        litq=dubq=tempq=glbq=0;
        symtab=loctab=0;
        wqueue=0;membptr=0;tagptr=0;swnext=0;stage=0;
        gotoq=0;

        /* allocate space for arrays */
        litq = mymalloc(FNLITQ) ;         /* literals, these 2 dumped end */
        dubq = mymalloc(FNLITQ) ;         /* Doubles */
        tempq = mymalloc(LITABSZ) ;        /* Temp strings... */
        glbq  = mymalloc(LITABSZ) ;        /* Used for glb lits, dumped now */
        symtab = SYM_CAST mymalloc(NUMGLBS*sizeof(SYMBOL)) ;
        loctab = SYM_CAST mymalloc(NUMLOC*sizeof(SYMBOL)) ;
        wqueue = WQ_CAST mymalloc(NUMWHILE*sizeof(WHILE_TAB)) ;
        gotoq= (GOTO_TAB *)calloc(NUMGOTO,sizeof(GOTO_TAB));
   if (gotoq==NULL) OutOfMem();

        tagptr = tagtab = TAG_CAST mymalloc(NUMTAG*sizeof(TAG_SYMBOL)) ;
        membptr = membtab = SYM_CAST mymalloc(NUMMEMB*sizeof(SYMBOL)) ;

        swnext = SW_CAST mymalloc(NUMCASE*sizeof(SW_TAB)) ;
        swend = swnext + (NUMCASE-1) ;

        stage = mymalloc(STAGESIZE) ;
        stagelast = stage+STAGELIMIT ;

        /* empty symbol table */
        glbptr = STARTGLB;
        while ( glbptr < ENDGLB ) {
                glbptr->name[0] = 0 ;
                ++glbptr ;
        }

        glbcnt = 0 ;                    /* clear global symbols */
        locptr = STARTLOC ;             /* clear local symbols */
        wqptr = wqueue ;                /* clear while queue */
        gltptr=dubptr=0 ;               /* clear literal pools */
        *litq=0;         /* First entry in literal queue is zero */
        litptr=1;       /* So miniprintf search works */

        Zsp =                   /* stack ptr (relative) */
        errcnt =                /* no errors */
        errstop =               /* keep going after an error */
        eof =                   /* not eof yet */
        swactive =              /* not in switch */
        skiplevel =             /* #if not encountered */
        iflevel =               /* #if nesting level = 0 */
        ncmp =                  /* no open compound states */
        lastst =                /* not first file to asm */
        fnstart =               /* current "function" started at line 0 */
        lineno =                /* no lines read from file */
        infunc =                /* not in function now */
                        0 ;             /*  ...all set to zero.... */

        stagenext = NULL_CHAR ; /* direct output mode */

        input =                                 /* no input file */
        inpt2 =                                 /* or include file */
        saveout =                               /* no diverted output */
        output = NULL_FD ;              /* no open units */

        currfn = NULL_SYM ;             /* no function yet */
        macptr = cmode = 1 ;    /* clear macro pool and enable preprocessing */
        ncomp=doinline=mathz88 = incfloat= compactcode =0;
        intuition=zorg=lpointer=cppcom=appz88=0;
        dosigned=NO;
        makelib=useshare=makeshare=sharedfile=NO;
        smartprintf=expanded=YES;
        startup=0;                      /* Which startup do we want? */
        nxtlab =                        /* start numbers at lowest possible */
        ctext =                         /* don't include the C text as comments */
        errstop =                       /* don't stop after errors */
        verbose = 0;
        gotocnt=0;
   defdenums=0;
   doublestrings = 0;
   noaltreg = NO;
        safedata=reqpag = -1;
   shareoffset=SHAREOFFSET;   /* Offset for shared libs */
   debuglevel=NO;
   farheapsz=-1;         /* Size of far heap */
    assemtype = ASM_Z80ASM;
   printflevel=0;
#ifdef USEFRAME
   indexix=YES;
   useframe=NO;
#endif

        /*
         *      compiler body
         */
        setup_sym() ;   /* define some symbols */
/* Parse the command line options */
        atexit(MemCleanup);     /* To free everything */
        clear();
        filenum=0;
        for (n=1;n<argc;n++) {
                if (argv[n][0]=='-') ParseArgs(1+argv[n]);
                else {filenum=n; break;}
        }
        clear();

        if (filenum == 0)
        {
                info();
                exit(1);
        }
        litlab=getlabel();              /* Get labels for function lits*/
        dublab=getlabel();              /* and fn doubles*/
        openout();              /* get the output file */
        openin();               /* and initial input file */
        header();               /* intro code */
        parse();                /* process ALL input */
        /* dump literal queues, with label */
        /* litq starts from 1, so literp has to be -1 */
        dumplits(0, YES,litptr-1,litlab,litq+1) ;
        dumplits(1, YES,dubptr,dublab,dubq) ;
        dumpvars();
        dumpfns();
        trailer();              /* follow-up code */
        closeout();
        errsummary();   /* summarize errors */
        if (errcnt) exit(1);
        exit(0);
}