int read_tif(char *filename, int filetype, F_pic *pic) { char buf[2*PATH_MAX+40],pcxname[PATH_MAX]; FILE *tiftopcx; int stat; /* make name for temp output file */ sprintf(pcxname, "%s/%s%06d.pix", TMPDIR, "xfig-pcx", getpid()); /* make command to convert tif to pnm then to pcx into temp file */ /* for some reason, tifftopnm requires a file and can't work in a pipe */ sprintf(buf, "tifftopnm %s 2> /dev/null | ppmtopcx > %s 2> /dev/null", filename, pcxname); if ((tiftopcx = popen(buf,"w" )) == 0) { file_msg("Cannot open pipe to tifftopnm or ppmtopcx\n"); /* remove temp file */ unlink(pcxname); return FileInvalid; } /* close pipe */ pclose(tiftopcx); if ((tiftopcx = fopen(pcxname, "rb")) == NULL) { file_msg("Can't open temp output file\n"); /* remove temp file */ unlink(pcxname); return FileInvalid; } /* now call read_pcx to read the pcx file */ stat = read_pcx(tiftopcx, filetype, pic); pic->pic_cache->subtype = T_PIC_TIF; /* remove temp file */ unlink(pcxname); return stat; }
Matrix<Color> read_img(std::string filename) { std::size_t n = filename.size(); std::string extension3 = filename.substr(n-3, n); std::string extension4 = filename.substr(n-4, n); if(!extension3.compare("bmp")) { return read_bmp(filename); } else if(!extension3.compare("gif")) { return read_gif(filename); } else if(!extension3.compare("ico")) { return read_ico(filename); } /*else if(!extension3.compare("jpg")) { return read_jpeg(filename); }*/ else if(!extension3.compare("pcx")) { return read_pcx(filename); } else if(!extension3.compare("png")) { return read_png(filename); } else if(!extension3.compare("pbm")) { return bw2colorimage(read_pbm(filename)); } else if(!extension3.compare("pgm")) { return gray2colorimage(read_pgm(filename)); } else if(!extension3.compare("ppm")) { return read_ppm(filename); } else if(!extension3.compare("tga")) { return read_tga(filename); } else if(!extension4.compare("tiff")) { return read_tiff(filename); } else { return Matrix<Color>(); } }
CL_PCXProvider_Impl::CL_PCXProvider_Impl( CL_IODevice &datafile) { image = NULL; bool little_endian = datafile.is_little_endian(); if (!little_endian) datafile.set_little_endian_mode(); read_pcx(datafile); if (!little_endian) datafile.set_big_endian_mode(); }
void main (void) { filename=parse_args (); puts ("PCX Viewer v1.0"); puts ("by Ricardo Bittencourt"); putchar (10); file=open (filename); header=(char *) malloc (128); read (file,header); print ("Name: "); puts (filename); print ("Xmax: "); number (INT (header,8),10); putchar (13); putchar (10); print ("Ymax: "); number (INT (header,10),10); putchar (13); putchar (10); putchar (10); print ("Press any key to start..."); getchar (); screen (8); read_pcx (file,header); getchar (); screen (0); }
int main( int argc, char *argv[] ) { pcx_picture_t image; std::string file = "all2.pcx"; Uint32 rmask, gmask, bmask, amask; SDL_Color colors[256]; SDL_Surface *tmp; read_pcx( file.c_str(), &image ); SDL_Init( SDL_INIT_VIDEO ); screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE ); SDL_WM_SetCaption( "Raw image Data", NULL ); #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif for(int i=0;i<256;i++){ colors[i].r = image.palette.triples[i].red; colors[i].g = image.palette.triples[i].green; colors[i].b = image.palette.triples[i].blue; } /* http://damien.douxchamps.net/ieee1394/coriander/ http://www.gamedev.net/topic/227811-sdl_creatergbsurfacefrom/ lsize = (long )hdr.BytesPerLine * hdr.Nplanes * (1 + hdr.Ymax - hdr.Ymin); Quote from the above linked documentation: "pitch is the length of each scanline in bytes." So if the line is 640 pixels wide, and each pixel is three bytes, then pitch is 640*3. EDIT: That would be a line in the source image. I.e. the one "pixels" is pointing to. */ /* raw_image = SDL_CreateRGBSurfaceFrom( image.buffer, image.header.pcx_window.x_max, image.header.pcx_window.y_max, image.header.bitsperpixel, image.header.pcx_window.x_max * 3, rmask, gmask, bmask, amask ); */ // Set the color info for the screen //SDL_SetColors(screen, colors, 0, 256 ); tmp = SDL_CreateRGBSurfaceFrom( image.buffer, 320, 200, 8, image.header.bytes_per_line, rmask, gmask, bmask, 0 ); //SDL_SetPalette(tmp, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); SDL_SetColors(tmp, colors, 0, 256); raw_image = SDL_DisplayFormat( tmp ); SDL_BlitSurface( raw_image, NULL, screen, NULL ); SDL_Flip( screen ); //printf("== Image Data ==\n"); //printf("Image Width = %d\n", image.header.h_screen_size); //printf("Image Height = %d\n", image.header.v_screen_size); SDL_Delay(10000); SDL_FreeSurface( tmp ); SDL_FreeSurface( raw_image ); SDL_FreeSurface( screen ); SDL_Quit(); return 0; }