double HeikenAshi(int tf,int price,int bar) { //if(bar == iBars(NULL,TimeFrame)- 1) //if(bar == chartbars[displayedfile]- 1) if(bar == 666- 1) { haClose[bar] = iclose(tf,bar); haOpen[bar] = iopen(tf,bar); haHigh[bar] = ihigh(tf,bar); haLow[bar] = ilow(tf,bar); } else { haClose[bar] = (iopen(tf,bar)+ihigh(tf,bar)+ilow(tf,bar)+iclose(tf,bar))/4; haOpen[bar] = (haOpen[bar+1]+haClose[bar+1])/2; haHigh[bar] = mathmax(ihigh(tf,bar),mathmax(haOpen[bar], haClose[bar])); haLow[bar] = mathmin(ilow(tf,bar),mathmin(haOpen[bar], haClose[bar])); } switch(price) { case 0: return(haClose[bar]);break; case 1: return(haOpen[bar]);break; case 2: return(haHigh[bar]);break; case 3: return(haLow[bar]);break; } }
int main(int argc, char **argv) { struct DiskPartition *dp; Inode testcreate; Device devno; int fd, count; char *buff="This is a test string"; InitPartitions("vicetab"); dp = VGetPartition("simpled"); devno = dp->device; testcreate = icreate(devno, 0, 0, 0, 0, 0); printf("icreate returned: %d\n", testcreate); if ( testcreate == 0 ) exit(1); fd = iopen(devno, testcreate, O_RDONLY); printf("iopen returned: %d\n", fd); if ( fd != -1 ) close(fd); else exit(2); count = iwrite(devno, testcreate, 0, 0, buff, strlen(buff)); printf("iwrite returned %d (of %d)\n", count, strlen(buff)); printnames(VGetPartition("/tmp/f"), 0, 1, 64); dp = VGetPartition("/tmp/f"); devno = dp->device; testcreate = icreate(devno, 0, 0, 0, 0, 0); printf("icreate returned: %d\n", testcreate); if ( testcreate == 0 ) exit(1); fd = iopen(devno, testcreate, O_RDONLY); printf("iopen returned: %d\n", fd); if ( fd != -1 ) close(fd); else exit(2); count = iwrite(devno, testcreate, 0, 0, buff, strlen(buff)); printf("iwrite returned %d (of %d)\n", count, strlen(buff)); return 0; }
void sgiWritUB(ppu rgb[4], unt dW, unt dH, char *path) { IMAGE *sgim; int k,y,yI; unc *sr, *sg, *sb ; ush *dr, *dg, *db, rr[512], gg[512], bb[512]; assert(dW <= 512); sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (y = 0, yI = dH; yI ; y++) { sr = rgb[1][--yI]; sg = rgb[2][ yI]; sb = rgb[3][ yI]; for (dr = rr, dg = gg, db = bb, k = dW; k; k--) { *dr++ = *sr++; *dg++ = *sg++; *db++ = *sb++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); }
int main(){ Color black = make_color(0, 0, 0); MMC mmc, *mp; IMG img, *ip; while(1){ mmc = mopen(), mp = &mmc; mseek(mp, PROGRAM_SIZE, SEEK_CUR); img = iopen(mp), ip = &img; draw_clear(&black); draw_img(ip); while(1){ if(check_switch(SWITCH1, ON)){ if(seek_next_img(ip)){ mclose(mp); break; } draw_img(ip); } } } }
/** * Prepare a statement for running. * * @param mc mysql context * @param sh statement handle to prepare * @return #GNUNET_OK on success */ static int prepare_statement (struct GNUNET_MYSQL_StatementHandle *sh) { struct GNUNET_MYSQL_Context *mc = sh->mc; if (GNUNET_YES == sh->valid) return GNUNET_OK; if ((NULL == mc->dbf) && (GNUNET_OK != iopen (mc))) return GNUNET_SYSERR; sh->statement = mysql_stmt_init (mc->dbf); if (NULL == sh->statement) { GNUNET_MYSQL_statements_invalidate (mc); return GNUNET_SYSERR; } if (0 != mysql_stmt_prepare (sh->statement, sh->query, strlen (sh->query))) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", "prepare_statement: %s\n", sh->query); LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_stmt_prepare", mc); mysql_stmt_close (sh->statement); sh->statement = NULL; GNUNET_MYSQL_statements_invalidate (mc); return GNUNET_SYSERR; } sh->valid = GNUNET_YES; return GNUNET_OK; }
void file::Write(const char* szFilename, const char* szContent, bool bAppend) { _iobuf* pFile = iopen(szFilename, bAppend ? "a" : "w"); { if (pFile != nullptr) fwrite(szContent, sizeof(char), strlen(szContent), pFile); } fclose(pFile); }
void saveSGIImage(char *name, int doAlphaToo) { IMAGE *img; FILE *fp; GLubyte *pixels; int x, y; int numComp = doAlphaToo ? 4 : 3; pixels = malloc(winWidth * winHeight * numComp * sizeof(GLubyte)); glReadPixels(0, 0, winWidth, winHeight, doAlphaToo ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE, pixels); img = iopen(name, "w", RLE(1), numComp, winWidth, winHeight, numComp); for(y = 0; y < winHeight; y++) { for(x = 0; x < winWidth; x++) { rrow[x] = pixels[(y * winWidth + x) * numComp + 0]; grow[x] = pixels[(y * winWidth + x) * numComp + 1]; brow[x] = pixels[(y * winWidth + x) * numComp + 2]; if(doAlphaToo) arow[x] = pixels[(y * winWidth + x) * numComp + 3]; } putrow(img, rrow, y, 0); putrow(img, grow, y, 1); putrow(img, brow, y, 2); if(doAlphaToo) putrow(img, arow, y, 3); } iclose(img); free(pixels); }
void sgiWritFB(ppf rgb[4], int dX, int dY, unt dW, unt dH, unt dD, char *path) { IMAGE *sgim; int k,y,yI; flt *sr, *sg, *sb ; pus dr, dg, db, rr, gg, bb; mallocAss(rr,ush,dW); mallocAss(gg,ush,dW); mallocAss(bb,ush,dW); wrn("sgiWritFB dD: %u path: %s", dD,path); if (dD < 3 || rgb[1] == NULL) { sgiWritFlt(rgb[0],dX,dY,dW,dH,path); return; } sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (y = 0, yI = dH+dY; yI > dY ; y++) { sr = &rgb[1][--yI][dX]; sg = &rgb[2][ yI][dX]; sb = &rgb[3][ yI][dX]; for (dr = rr, dg = gg, db = bb, k = dW; k; k--) { *dr++ = 0.5F + *sr++; *dg++ = 0.5F + *sg++; *db++ = 0.5F + *sb++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); free(rr); free(gg); free(bb); }
void main(int argc, char **argv) { IMAGE *image; char *cp, cc; unt type = MM_UNC, order = MM_INTERL; void *dst; if (argc < 2) Usage("Need two filenames"); if (argc > 3) { cp = argv[3]; if (*cp != '-') Usage("options must begin with '-'"); while ( (cc = *++cp) != '\0') { switch(cc) { case 'B': order = MM_PLANAR; break; case 'I': order = MM_INTERL; break; case 'R': order = MM_BANDED; break; case 'c': type = MM_UNC; break; case 'f': type = MM_FLT; break; case 'i': type = MM_UNT; break; case 's': type = MM_USH; break; default: Usage("Unrecognized option: %c", cc); } } } if ( ! (image=iopen(argv[1],"r"))) die("Can't open input file %s\n",argv[1]); dst = readSGI(image,order,type); memWriteUnc(dst,image->xsize,image->ysize ,(type==MM_USHORT?2:1),0,argv[2],NULL); }
static int loadMibFromRcSource(char *mibSource) { int sourceFile; LoadMibState state; char buf[256]; int length; int result = 0; if (*mibSource == '\0') /* Use default file name. */ { mibSource = "mib.amsrc"; } sourceFile = iopen(mibSource, O_RDONLY, 0777); if (sourceFile < 0) { putSysErrmsg("Can't open MIB source file", mibSource); return -1; } memset((char *) &state, 0, sizeof state); state.abandoned = 0; state.currentOperation = LoadDormant; state.lineNbr = 0; while (1) { if (igets(sourceFile, buf, sizeof(buf), &length) == NULL) { if (length == 0) /* End of file. */ { break; /* Out of loop. */ } putErrmsg("Failed reading MIB.", mibSource); break; /* Out of loop. */ } state.lineNbr++; if (rcParse(&state, buf, length) < 0) { isprintf(buf, sizeof buf, "amsrc error at line %d.", state.lineNbr); writeMemo(buf); result = -1; break; /* Out of loop. */ } if (state.abandoned) { writeMemo("[?] Abandoning MIB load."); result = -1; break; /* Out of loop. */ } } close(sourceFile); return result; }
int main(int argc,char *argv[]) { IMAGE *image; int x, y, z, x0, y0; int r, g, b; short *rbuf, *gbuf, *bbuf; unsigned short pixel; int imgsize_x, imgsize_y; /* chack parameters */ if (4 == argc){ imgsize_x = atoi(argv[2]); imgsize_y = atoi(argv[3]); } else if (2 != argc){ /* print usage message */ fprintf(stderr,"usage: rgb2u64 infile [x_size y_size]\n"); return 1; } /* open the image file */ if ((image=iopen(argv[1],"r")) == NULL ){ fprintf(stderr,"readimage: can't open input file %s\n",argv[1]); return 1; } /* print a little info about the image */ fprintf(stderr,"Image x and y size : %d %d\n",image->xsize,image->ysize); fprintf(stderr,"Image zsize in channels: %d \n",image->zsize); fprintf(stderr,"Image pixel min and max: %d %d\n",image->min,image->max); if (2 == argc){ imgsize_x = image->xsize; imgsize_y = image->ysize; } /* allocate buffers for image data */ rbuf = (short *)malloc(image->xsize*sizeof(short)); gbuf = (short *)malloc(image->xsize*sizeof(short)); bbuf = (short *)malloc(image->xsize*sizeof(short)); x0 = (image->xsize - imgsize_x) / 2; y0 = (image->ysize - imgsize_y) / 2; /* check to see if the image is B/W or RGB */ if ( image->zsize == 1 ) { fprintf(stderr,"This is a black and write image. exiting...\n"); return 1; } else if ( image->zsize >= 3 ){ /* if the image has alpha zsize is 4 */ fprintf(stderr,"This is a rgb image.\n"); for (y = y0 + imgsize_y - 1; y >= y0; y--) { if (y < 0 || y >= image->ysize){ pixel = GRGBA5551(0,0,0,1); for (x = 0; x < imgsize_x; x ++){ printf("%c%c", pixel>>8, pixel&0xff); } } else {
unt sgiRead4U (ppu ret[4], unt *dW, unt *dH, int oX, int oY, char *path, unt flags) { IMAGE *sgim; ush *rowbuf; unt sW,sH,sD; size_t rsize; int y, yI; if ( ! (sgim=iopen(path,"r"))) die("sgiRead4U: iopen(%s) failed\n",path); sW = sgim->xsize; sH = sgim->ysize; sD = sgim->zsize; rsize = sizeof(unsigned short)*sW*sD; if (! (rowbuf = (unsigned short *)malloc(rsize))) die("sgiRead4U(%s): malloc(%u)",path,rsize); sH -= oY; *dH = sH; sW -= oX; *dW = sW; switch (sD) { case 1: { ppu dst; ret[0] = dst = rowMalUnc(0,0,sW,sH); ret[1] = NULL; for (yI = sH, y = oY; yI ; y++) { getrow(sgim,rowbuf,y,1); uncUsh(dst[--yI],rowbuf+oX,sW); } } break; case 3: { ppu gry, red, grn, blu; ret[0] = gry = rowMalUnc(0,0,sW,sH); ret[1] = red = rowMalUnc(0,0,sW,sH); ret[2] = grn = rowMalUnc(0,0,sW,sH); ret[3] = blu = rowMalUnc(0,0,sW,sH); /***** ret[4] = NULL; *****/ for (yI = sH, y = oY; yI-- ; y++) { getrow(sgim, rowbuf, y, 0); uncUsh(red[yI],rowbuf+oX,sW); getrow(sgim, rowbuf, y, 1); uncUsh(grn[yI],rowbuf+oX,sW); getrow(sgim, rowbuf, y, 2); uncUsh(blu[yI],rowbuf+oX,sW); } gryRgbUnc(gry,red,grn,blu,0,0,sW,sH); } break; default: die("sgiRead4U [%s]: NOIMP for SGI image depth %u",__FILE__,sD); } free(rowbuf); iclose(sgim); if (sD == 3) return 4; else if (sD <= 1) return 1; else return 0; }
isis() { BYTE opcode; if ((WORD)savepc != 0x41) /* not an ISIS-II call? */ { monitor(); /* must be an MDS monitor call */ return; } switch(savebc & 0xff) /* it's an ISIS-II trap - do the right thing */ { case 0: iopen((OBLK *)savede); /* OPEN call */ break; case 1: iclose((CBLK *)savede); /* CLOSE call */ break; case 2: idelete((DBLK *)savede); /* DELETE call */ break; case 3: iread((RBLK *)savede); /* READ call */ break; case 4: iwrite((WBLK *)savede); /* WRITE call */ break; case 5: iseek((SBLK *)savede); /* SEEK call */ break; case 6: iload((LBLK *)savede); /* LOAD call */ break; case 7: irename((RNBLK *)savede); /* RENAME call */ break; case 9: cleanup(); break; case 11: irescan((RSBLK *)savede); /* RESCAN call */ break; case 12: /* ERROR call */ ierror((EBLK *)savede); break; case 14: /* SPATH call */ ispath((SPBLK *)savede); break; default: print("\r\nIllegal ISIS-II function call "); phexw(savebc); print("\r\n"); break; } }
int main(int argc, char ** argv) { if (argc < 3) { fprintf(stderr, "Expected two additional arguments: a ramdisk, and a file path to second stage to find in it.\n"); return -1; } fprintf(stderr, "I will look for %s in %s and generate appropriate output.\n", argv[2], argv[1]); /* Open sesame! */ FILE * hdd = fopen(argv[1], "r"); fseek(hdd, 0, SEEK_END); /* Get size of file */ uint32_t hdd_size = ftell(hdd); fprintf(stderr, "HDD image is %d bytes.\n", hdd_size); fseek(hdd, 0, SEEK_SET); /* Allocate us up some mems for the hard disk image */ hdd_dump = malloc(sizeof(char) * hdd_size); /* Read 'er in. */ fread(hdd_dump, hdd_size, 1, hdd); /* And lets make us some pointers. */ sblock = (ext2_superblock_t *)((uintptr_t)hdd_dump + 0x400); assert(sblock->magic == EXT2_SUPER_MAGIC); if (sblock->inode_size == 0) { sblock->inode_size = 128; } /* More pointers! */ ext2_bgdescriptor_t * rblock = (ext2_bgdescriptor_t *)((uintptr_t)hdd_dump + 0x400 + 0x400); /* Inode table */ itable = (ext2_inodetable_t *)((uintptr_t)hdd_dump + (0x400 << sblock->log_block_size) * rblock->inode_table); /* Root node */ ext2_inodetable_t * rnode = (ext2_inodetable_t *)((uintptr_t)itable + sblock->inode_size); ext2_inodetable_t * fnode = iopen(rnode, argv[2]); if (!fnode) { fprintf(stderr,"Failed to locate the requested file on the disk image.\n"); return -1; } uint32_t offset = 0x10000; /* Destination offset */ uint32_t _block = 0; uint32_t _block_last = 0; for (uint32_t i = 0; i < fnode->blocks; ++i) { uint32_t block = ext2_get_inode_block_num(fnode, i); if (_block == 0 || block != _block_last + 1) { if (_block != 0) { uint32_t size = (_block_last - _block + 1) * (0x400 << sblock->log_block_size); uint32_t place = ext2_get_block_offset(_block); fprintf(stdout, "read(0x%x, 0x%x, 0x%x, 0x%x);\n", size / 512, place / 512, 0x1000, offset % 0x10000); offset += size; } if (block == 0) { break; } _block = block; } _block_last = block; } }
unt sgiReadU( ppu *ret, unt *dW, unt *dH , int oX, int oY, unt mW, unt mH, char *path, unt flags) { IMAGE *sgim; ush *rowbuf; unt sW,sH,sD; int y, yI; if ( ! (sgim=iopen(path,"r"))) die("sgiReadU: iopen(%s) failed\n",path); sW = sgim->xsize; sH = sgim->ysize; sD = sgim->zsize; yI = sizeof(unsigned short)*sW*sD; mallocAss(rowbuf,ush,yI); sW -= oX; if (sW > mW) sW = mW; *dW = sW; sH -= oY; if (sH > mH) sH = mH; *dH = sH; switch (sD) { case 1: { ppu dst; ret[0] = dst = rowMalUnc(0,0,sW,sH); /***** ret[1] = NULL; *****/ for (yI = sH, y = oY; yI ; y++) { getrow(sgim,rowbuf,y,1); uncUsh(dst[--yI],rowbuf+oX,sW); } } break; case 3: { ppu red, grn, blu; ret[0] = red = rowMalUnc(0,0,sW,sH); ret[1] = grn = rowMalUnc(0,0,sW,sH); ret[2] = blu = rowMalUnc(0,0,sW,sH); /***** ret[4] = NULL; *****/ for (yI = sH, y = oY; yI-- ; y++) { getrow(sgim, rowbuf, y, 0); uncUsh(red[yI],rowbuf+oX,sW); getrow(sgim, rowbuf, y, 1); uncUsh(grn[yI],rowbuf+oX,sW); getrow(sgim, rowbuf, y, 2); uncUsh(blu[yI],rowbuf+oX,sW); } } break; default: die("sgiReadU [%s]: NOIMP for SGI image depth %u",__FILE__,sD); } free(rowbuf); iclose(sgim); return sD; }
void writSgiUsh(ppus rgb[4], unt dW, unt dH, char *path) { IMAGE *sgim; unt y,yI; sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (y = 0, yI = dH; yI-- ; y++) { putrow(sgim,rgb[1][yI],y,0); putrow(sgim,rgb[2][yI],y,1); putrow(sgim,rgb[3][yI],y,2); } iclose(sgim); }
int open (const char* pathname, int flags, ...) { // back up original open() int (*Normal_Open)(const char *name, int flags); *(void **)(&Normal_Open) = dlsym(RTLD_NEXT, "open"); char* inter = getenv("INTER"); if (*inter == '1') { return iopen(pathname, flags, Normal_Open); } else { return costum_open(pathname, flags, Normal_Open); } }
unt readSgiUsh ( ppus ret[4], unt *dW, unt *dH, int oX, int oY, char *path, unt flags ) { IMAGE *sgim; unt sW,sH,sD; size_t rsize; int y, yI; if ( ! (sgim=iopen(path,"r"))) die("readSgiUsh: iopen(%s) failed\n",path); sW = sgim->xsize; sH = sgim->ysize; sD = sgim->zsize; rsize = sizeof(unsigned short)*sW*sD; sH -= oY; *dH = sH; sW -= oX; *dW = sW; switch (sD) { case 1: { ppus dst; ret[0] = dst = rowMalUsh(0,0,sW,sH); ret[1] = NULL; for (yI = sH, y = oY; yI ; y++) getrow(sgim,dst[--yI],y,1); } break; case 3: { ppus gry, red, grn, blu; ret[0] = gry = rowMalUsh(0,0,sW,sH); ret[1] = red = rowMalUsh(0,0,sW,sH); ret[2] = grn = rowMalUsh(0,0,sW,sH); ret[3] = blu = rowMalUsh(0,0,sW,sH); for (yI = sH, y = oY; yI-- ; y++) { getrow(sgim, red[yI], y, 0); getrow(sgim, grn[yI], y, 1); getrow(sgim, blu[yI], y, 2); } gryRgbUsh(gry,red,grn,blu,sW,sH); } break; default: die("readSgiUsh [%s]: NOIMP for SGI image depth %u",__FILE__,sD); } iclose(sgim); if (sD == 3) return 4; else if (sD <= 1) return 1; else return 0; }
const char* file::Read(const char* szFilename) { long lFilesize; char* szResult = ""; _iobuf* pFile = iopen(szFilename, "r"); { if (pFile != nullptr) { fseek(pFile, 0, SEEK_END); { lFilesize = ftell(pFile); szResult = (char*)malloc(lFilesize + 1); } rewind(pFile); fread(szResult, sizeof(char), lFilesize, pFile); szResult[lFilesize] = '\0'; } } fclose(pFile); return szResult; }
/** * Run a SQL statement. * * @param mc mysql context * @param sql SQL statement to run * @return #GNUNET_OK on success * #GNUNET_SYSERR if there was a problem */ int GNUNET_MYSQL_statement_run (struct GNUNET_MYSQL_Context *mc, const char *sql) { if ( (NULL == mc->dbf) && (GNUNET_OK != iopen (mc)) ) return GNUNET_SYSERR; mysql_query (mc->dbf, sql); if (mysql_error (mc->dbf)[0]) { LOG_MYSQL (GNUNET_ERROR_TYPE_ERROR, "mysql_query", mc); GNUNET_MYSQL_statements_invalidate (mc); return GNUNET_SYSERR; } return GNUNET_OK; }
int /** replaced rowWriteSGIN **/ rowWritSGImU(ppu *srcU, int dX, int dY, unt dW, unt dH, unt chan, char *path) { ush sbuf[1536]; ppu srcp; int q,j,yI; IMAGE *sgim = iopen(path,"w",RLE(1),3,dW,dH,chan); if (!sgim) { warn("rowWritSGImU: iopen failed"); return -1; } for (q = 0; q < chan; q++) { for (srcp = &srcU[q][dY], j = dH, yI = dY; j-- ; ) { ushUnc(sbuf,*srcp++ + dX,dW); putrow(sgim,sbuf,j,q); } } return iclose(sgim); }
void rowWriteSGI(ppf src, int sX, int sY, unt sW, unt sH, char *path) { IMAGE *sgim; int k,y,yI; flt *fp; ush *up, *urow; mallocAss(urow,unsigned short,sW); sgim = iopen(path,"w",RLE(1),2,sW,sH,1); for (y = 0, yI = sH+sY; yI > sY ; y++) { fp = &src[--yI][sX]; for (up = urow, k = sW; k-- ; ) { *up++ = 0.5F + *fp++; } putrow(sgim,urow,y,0); } iclose(sgim); }
void sgiWritFlt (ppf src, int sX, int sY, unt sW, unt sH, char *path) { IMAGE *image; int k; unsigned short *rowp, *row; pfl srcp; if (! (image = iopen(path,"w",RLE(1),2,sW,sH))) die("sgiWritFlt: iopen(%s)", path); mallocAss(row,unsigned short,sW); for (src += sY; sH; ) { for (rowp = row, srcp = *src++ + sX, k = sW; k-- ; ) *rowp++ = 0.5F + *srcp++; /* Not IRINTF */ putrow(image,row,--sH,0); } iclose(image); free(row); }
int /* DOES NOT FLIP IMAGE AROUND X-AXIS -- ORIGIN AT BOTTOM LEFT */ rowWritSgiU(ppu *srcU, int dX, int dY, unt dW, unt dH, unt chan, char *path) { ush sbuf[1024]; ppu srcp; int j,q; IMAGE *sgim = iopen(path,"w",RLE(1),3,dW,dH,chan); if (!sgim) { warn("rowWritSgiU: iopen failed"); return -1; } for (q = 0; q < chan; q++) { for (srcp = &srcU[q][dY], j = 0; j < dH; j++) { ushUnc(sbuf,*srcp++ + dX,dW); putrow(sgim, sbuf,j,q); } } return iclose(sgim); /* 0:success, -1:stdlib close err (check errno), EOF:sgi err */ }
void rowGraySGI (ppu src, int sX, int sY, unt sW, unt sH, char *path) { IMAGE *image; int k; unsigned short *rowp, *row; puc ucp; mallocAss(row,unsigned short,sW); if (! (image = iopen(path,"w",RLE(1),2,sW,sH))) die("rowGraySGI: iopen(%s)", path); for (src += sY; sH; ) { for (rowp = row, ucp = *src++ + sX, k = 0; k < sW; k++) *rowp++ = *ucp++; putrow(image,row,--sH,0); } iclose(image); free(row); }
static gint itip_estimate_iter(gint **image, gint im_xsiz, gint im_ysiz, gint tip_xsiz, gint tip_ysiz, gint xc, gint yc, gint **tip0, gint thresh, gboolean use_edges, GwySetFractionFunc set_fraction, G_GNUC_UNUSED GwySetMessageFunc set_message) { gint ixp, jxp; /* index into the image (x') */ gint **open; gdouble total = (im_ysiz - tip_ysiz)*(im_xsiz - tip_xsiz); guint k = 0; gint count = 0; /* counts places where tip estimate is improved */ open = iopen(image, im_xsiz, im_ysiz, tip0, tip_xsiz, tip_ysiz); if (!open) return -1; for (jxp = tip_ysiz - 1 - yc; jxp <= im_ysiz - 1 - yc; jxp++) { for (ixp = tip_xsiz - 1 - xc; ixp <= im_xsiz - 1 - xc; ixp++) { if (image[jxp][ixp] - open[jxp][ixp] > thresh) { if (itip_estimate_point(ixp, jxp, image, im_xsiz, im_ysiz, tip_xsiz, tip_ysiz, xc, yc, tip0, thresh, use_edges)) { count++; } } k++; if (set_fraction) { gdouble fraction = k/total; fraction = CLAMP(fraction, 0.0, 1.0); if (!set_fraction(fraction)) { _gwy_morph_lib_ifreematrix(open); return -1; } } } } _gwy_morph_lib_ifreematrix(open); return count; }
void * rowReadSGI(char *path, unt *sW, unt *sH, unt *deep, unt flags) { IMAGE *sgim; ush *rowbuf; void *ret=NULL; unt xsize, ysize, zsize, y, yI, type = flags & MM_TYPE; size_t rsize; if ( ! (sgim=iopen(path,"r"))) die("rowReadSGI: iopen(%s) failed\n",path); *sW = xsize = sgim->xsize; *sH = ysize = sgim->ysize; *deep = zsize = sgim->zsize; rsize = sizeof(unsigned short)*xsize*zsize; if (! (rowbuf = (unsigned short *)malloc(rsize))) die("rowReadSGI(%s): malloc(%u)",path,rsize); switch (type) { case MM_UNC: { unc **dst = rowMalUnc(0,0,xsize,ysize); ret = dst; for (yI = ysize, y = 0; yI ; y++) { getrow(sgim,rowbuf,y,1); uncUsh(dst[--yI],rowbuf,xsize); } } break; case MM_FLT: { flt **dst = rowMalFlt(0,0,xsize,ysize); ret = dst; for (yI = ysize, y = 0; yI ; y++) { getrow(sgim,rowbuf,y,1); fltUsh(dst[--yI],rowbuf,xsize); } } break; default: die("rowReadSGI(%s): NOIMP for flags:%d",path,flags); } free(rowbuf); iclose(sgim); return ret; }
void rgbWriteSGIn(ppf rgb, int dX, int dY, unt dW, unt dH, char *path) { IMAGE *sgim; int k,y; flt *sp; ush *rp, *gp, *bp, rr[1280], gg[1280], bb[1280]; assert(dW <= 1280); sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (rgb += dY, dX *= 3, y = 0; y < dH; y++) { sp = *rgb++ + dX; for (rp = rr, gp = gg, bp = bb, k = dW; k; k--) { *rp++ = 0.5F + *sp++; *gp++ = 0.5F + *sp++; *bp++ = 0.5F + *sp++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); }
void rgbWriteSGI(ppf rgb, int dX, int dY, unt dW, unt dH, char *path) { IMAGE *sgim; int k,y,yI; flt *sp; ush *rp, *gp, *bp, rr[1024], gg[1024], bb[1024]; assert(dW <= 1024); sgim = iopen(path,"w",RLE(1),3,dW,dH,3); /* WHAT'S the 1st 3? */ for (dX *= 3, y = 0, yI = dH+dY; yI > dY ; y++) { sp = &rgb[--yI][dX]; for (rp = rr, gp = gg, bp = bb, k = dW; k; k--) { *rp++ = 0.5F + *sp++; *gp++ = 0.5F + *sp++; *bp++ = 0.5F + *sp++; } putrow(sgim,rr,y,0); putrow(sgim,gg,y,1); putrow(sgim,bb,y,2); } iclose(sgim); }
int main(int argc, char* argv[]) { IMAGE *in; TIFF *out; int c; extern int optind; extern char* optarg; while ((c = getopt(argc, argv, "c:p:r:")) != -1) switch (c) { case 'c': /* compression scheme */ if (!processCompressOptions(optarg)) usage(); break; case 'f': /* fill order */ if (streq(optarg, "lsb2msb")) fillorder = FILLORDER_LSB2MSB; else if (streq(optarg, "msb2lsb")) fillorder = FILLORDER_MSB2LSB; else usage(); break; case 'p': /* planar configuration */ if (streq(optarg, "separate")) config = PLANARCONFIG_SEPARATE; else if (streq(optarg, "contig")) config = PLANARCONFIG_CONTIG; else usage(); break; case 'r': /* rows/strip */ rowsperstrip = atoi(optarg); break; case '?': usage(); /*NOTREACHED*/ } if (argc - optind != 2) usage(); in = iopen(argv[optind], "r"); if (in == NULL) return (-1); out = TIFFOpen(argv[optind+1], "w"); if (out == NULL) return (-2); TIFFSetField(out, TIFFTAG_IMAGEWIDTH, (uint32) in->xsize); TIFFSetField(out, TIFFTAG_IMAGELENGTH, (uint32) in->ysize); TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8); TIFFSetField(out, TIFFTAG_COMPRESSION, compression); if (in->zsize == 1) photometric = PHOTOMETRIC_MINISBLACK; else photometric = PHOTOMETRIC_RGB; switch (compression) { case COMPRESSION_JPEG: if (photometric == PHOTOMETRIC_RGB && jpegcolormode == JPEGCOLORMODE_RGB) photometric = PHOTOMETRIC_YCBCR; TIFFSetField(out, TIFFTAG_JPEGQUALITY, quality); TIFFSetField(out, TIFFTAG_JPEGCOLORMODE, jpegcolormode); break; case COMPRESSION_LZW: case COMPRESSION_DEFLATE: if (predictor != 0) TIFFSetField(out, TIFFTAG_PREDICTOR, predictor); break; } TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photometric); if (fillorder != 0) TIFFSetField(out, TIFFTAG_FILLORDER, fillorder); TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, in->zsize); if (in->zsize > 3) { uint16 v[1]; v[0] = EXTRASAMPLE_UNASSALPHA; TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, v); } TIFFSetField(out, TIFFTAG_MINSAMPLEVALUE, (uint16) in->min); TIFFSetField(out, TIFFTAG_MAXSAMPLEVALUE, (uint16) in->max); TIFFSetField(out, TIFFTAG_PLANARCONFIG, config); if (config != PLANARCONFIG_SEPARATE) TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, rowsperstrip)); else /* force 1 row/strip for library limitation */ TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 1L); if (in->name[0] != '\0') TIFFSetField(out, TIFFTAG_IMAGEDESCRIPTION, in->name); if (config == PLANARCONFIG_CONTIG) cpContig(in, out); else cpSeparate(in, out); (void) iclose(in); (void) TIFFClose(out); return (0); }