00001
00025 #include "edtinc.h"
00026
00027 static void
00028 save_image(u_char * image_p, int width, int height, int depth,
00029 char *basename, int count);
00030
00031
00032
00033
00034 main(int argc, char **argv)
00035 {
00036 int unit = 0, channel = 0;
00037 char edt_devname[128];
00038 char *cameratype;
00039 char bmpfname[128];
00040 char errstr[64];
00041 u_char *image_p;
00042 PdvDev *pdv_p;
00043
00044 *bmpfname = '\0';
00045
00046 if (argc > 1)
00047 if (argv[1][0] == '-')
00048 printf("usage: simplest_take [filename]\n");
00049 else strcpy(bmpfname, argv[1]);
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 if ((pdv_p = pdv_open_channel(EDT_INTERFACE, unit, channel)) == NULL)
00061 {
00062 sprintf(errstr, "pdv_open_channel(%s%d_%d)", edt_devname, unit, channel);
00063 pdv_perror(errstr);
00064 return (1);
00065 }
00066
00067
00068
00069
00070 image_p = pdv_image(pdv_p);
00071
00072
00073
00074
00075 if (pdv_timeouts(pdv_p) > 0)
00076 printf("got timeout, check camera and cables\n");
00077 else printf("got one image\n");
00078
00079
00080
00081
00082 if (*bmpfname)
00083 save_image(image_p, pdv_get_width(pdv_p), pdv_get_height(pdv_p), pdv_get_depth(pdv_p), bmpfname, 0);
00084
00085
00086 pdv_close(pdv_p);
00087
00088 exit(0);
00089 }
00090
00091 static void
00092 save_image(u_char * image_p, int s_width, int s_height, int s_depth, char *tmpname, int count)
00093 {
00094 int s_db = bits2bytes(s_depth);
00095 u_char *bbuf = NULL;
00096 char fname[256];
00097
00098 #ifdef _NT_
00099 if ((strcmp(&tmpname[strlen(tmpname) - 4], ".bmp") == 0)
00100 || (strcmp(&tmpname[strlen(tmpname) - 4], ".BMP") == 0))
00101 tmpname[strlen(tmpname) - 4] = '\0';
00102 sprintf(fname, "%s%02d.bmp", tmpname, count);
00103 #else
00104 if ((strcmp(&tmpname[strlen(tmpname) - 4], ".ras") == 0)
00105 || (strcmp(&tmpname[strlen(tmpname) - 4], ".RAS") == 0))
00106 tmpname[strlen(tmpname) - 4] = '\0';
00107 sprintf(fname, "%s%02d.ras", tmpname, count);
00108 #endif
00109
00110
00111
00112
00113
00114 switch (s_db)
00115 {
00116 case 1:
00117 #ifdef _NT_
00118
00119 dvu_write_bmp(fname, image_p, s_width, s_height);
00120 #else
00121 printf("writing %dx%dx%d raster file to %s\n",
00122 s_width, s_height, s_depth, fname);
00123
00124 dvu_write_rasfile(fname, (u_char *) image_p, s_width, s_height);
00125 #endif
00126 break;
00127
00128 case 2:
00129 printf("converting %dx%dx%d image to 8 bits, writing to %s\n",
00130 s_width, s_height, s_depth, fname);
00131
00132 #ifdef _NT_
00133 if (!bbuf)
00134 bbuf = (u_char *) pdv_alloc(s_width * s_height);
00135
00136 if (bbuf == NULL)
00137 {
00138 pdv_perror("data buf malloc");
00139 exit(1);
00140 }
00141 dvu_word2byte((u_short *) image_p, (u_char *) bbuf,
00142 s_width * s_height, s_depth);
00143 dvu_write_bmp(fname, bbuf, s_width, s_height);
00144 #else
00145 dvu_write_rasfile16(fname, (u_char *) image_p, s_width, s_height, s_depth);
00146 #endif
00147 break;
00148
00149 case 3:
00150 printf("writing %dx%dx%d bmp file to %s\n",
00151 s_width, s_height, s_depth, fname);
00152
00153 #ifdef _NT_
00154 dvu_write_bmp_24(fname, (u_char *) image_p, s_width, s_height);
00155 #else
00156 dvu_write_rasfile24(fname, (u_char *) image_p, s_width, s_height);
00157 #endif
00158
00159 break;
00160
00161 default:
00162 printf("invalid image depth for file write...!\n");
00163 break;
00164 }
00165 }
00166