00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <cstdio>
00024 #include <cstring>
00025 #include <climits>
00026 #include <ctime>
00027 #include <cmath>
00028 #include <cfloat>
00029 #include <string>
00030
00031 #include "ConvPic.hh"
00032
00033
00034 clConvPic ConvPic;
00035
00036
00037 int main (int argc, char *argv[])
00038 {
00039 return ConvPic.Main(&argc, &argv);
00040 }
00041
00042
00043 bool clConvPic::Initialize ()
00044 {
00045 return true;
00046 }
00047
00048
00049 bool clConvPic::LoadLOFARInfo (const char *cpImageFileName)
00050 {
00051 char cpInfoFileName[_POSIX_PATH_MAX + 1];
00052 char cpReadBuf[4096];
00053 FILE *fileInf;
00054 string strParam;
00055 string strValue;
00056
00057 sprintf(cpInfoFileName, "%s.inf", cpImageFileName);
00058 fileInf = fopen(cpInfoFileName, "rt");
00059 if (fileInf == NULL)
00060 {
00061 fprintf(stderr, "Failed to open .inf file for reading!\n");
00062 return false;
00063 }
00064
00065 while (fgets(cpReadBuf, 4096, fileInf))
00066 {
00067 SplitLine(cpReadBuf, strParam, strValue);
00068
00069 if (strParam == "Time:")
00070 uPicInfo.sLOFAR.ttTime = ParseTime(strValue.c_str());
00071 if (strParam == "LowFreq:")
00072 sscanf(strValue.c_str(), "%lg", &uPicInfo.sLOFAR.dLowFreq);
00073 if (strParam == "HighFreq:")
00074 sscanf(strValue.c_str(), "%lg", &uPicInfo.sLOFAR.dHighFreq);
00075 if (strParam == "LineTime:")
00076 sscanf(strValue.c_str(), "%lg", &uPicInfo.sLOFAR.dLineTime);
00077 }
00078
00079 fclose(fileInf);
00080
00081 return true;
00082 }
00083
00084
00085 bool clConvPic::LoadDEMONInfo (const char *cpImageFileName)
00086 {
00087 char cpInfoFileName[_POSIX_PATH_MAX + 1];
00088 char cpReadBuf[4096];
00089 FILE *fileInf;
00090 string strParam;
00091 string strValue;
00092
00093 sprintf(cpInfoFileName, "%s.inf", cpImageFileName);
00094 fileInf = fopen(cpInfoFileName, "rt");
00095 if (fileInf == NULL)
00096 {
00097 fprintf(stderr, "Failed to open .inf file for reading!\n");
00098 return false;
00099 }
00100
00101 while (fgets(cpReadBuf, 4096, fileInf))
00102 {
00103 SplitLine(cpReadBuf, strParam, strValue);
00104
00105 if (strParam == "Time:")
00106 uPicInfo.sDEMON.ttTime = ParseTime(strValue.c_str());
00107 if (strParam == "LowFreq:")
00108 sscanf(strValue.c_str(), "%lg", &uPicInfo.sDEMON.dLowFreq);
00109 if (strParam == "HighFreq:")
00110 sscanf(strValue.c_str(), "%lg", &uPicInfo.sDEMON.dHighFreq);
00111 if (strParam == "DemonBand:")
00112 sscanf(strValue.c_str(), "%lg", &uPicInfo.sDEMON.dDEMONBand);
00113 if (strParam == "LineTime:")
00114 sscanf(strValue.c_str(), "%lg", &uPicInfo.sDEMON.dLineTime);
00115 }
00116
00117 fclose(fileInf);
00118
00119 return true;
00120 }
00121
00122
00123 bool clConvPic::LoadSGramInfo (const char *cpImageFileName)
00124 {
00125 char cpInfoFileName[_POSIX_PATH_MAX + 1];
00126 char cpReadBuf[4096];
00127 FILE *fileInf;
00128 string strParam;
00129 string strValue;
00130
00131 sprintf(cpInfoFileName, "%s.inf", cpImageFileName);
00132 fileInf = fopen(cpInfoFileName, "rt");
00133 if (fileInf == NULL)
00134 {
00135 fprintf(stderr, "Failed to open .inf file for reading!\n");
00136 return false;
00137 }
00138
00139 while (fgets(cpReadBuf, 4096, fileInf))
00140 {
00141 SplitLine(cpReadBuf, strParam, strValue);
00142
00143 if (strParam == "Time:")
00144 uPicInfo.sSGram.ttTime = ParseTime(strValue.c_str());
00145 if (strParam == "LowFreq:")
00146 sscanf(strValue.c_str(), "%lg", &uPicInfo.sSGram.dLowFreq);
00147 if (strParam == "HighFreq:")
00148 sscanf(strValue.c_str(), "%lg", &uPicInfo.sSGram.dHighFreq);
00149 if (strParam == "LineTime:")
00150 sscanf(strValue.c_str(), "%lg", &uPicInfo.sSGram.dLineTime);
00151 }
00152
00153 fclose(fileInf);
00154
00155 return true;
00156 }
00157
00158
00159 bool clConvPic::LoadTBearInfo (const char *cpImageFileName)
00160 {
00161 char cpInfoFileName[_POSIX_PATH_MAX + 1];
00162 char cpReadBuf[4096];
00163 FILE *fileInf;
00164 string strParam;
00165 string strValue;
00166
00167 sprintf(cpInfoFileName, "%s.inf", cpImageFileName);
00168 fileInf = fopen(cpInfoFileName, "rt");
00169 if (fileInf == NULL)
00170 {
00171 fprintf(stderr, "Failed to open .inf file for reading!\n");
00172 return false;
00173 }
00174
00175 while (fgets(cpReadBuf, 4096, fileInf))
00176 {
00177 SplitLine(cpReadBuf, strParam, strValue);
00178
00179 if (strParam == "Time:")
00180 uPicInfo.sTBear.ttTime = ParseTime(strValue.c_str());
00181 if (strParam == "LeftDir:")
00182 sscanf(strValue.c_str(), "%lg", &uPicInfo.sTBear.dLeftDir);
00183 if (strParam == "RightDir:")
00184 sscanf(strValue.c_str(), "%lg", &uPicInfo.sTBear.dRightDir);
00185 if (strParam == "IntTime:")
00186 sscanf(strValue.c_str(), "%lg", &uPicInfo.sTBear.dIntTime);
00187 if (strParam == "HighFreq:")
00188 sscanf(strValue.c_str(), "%lg", &uPicInfo.sTBear.dHighFreq);
00189 if (strParam == "Sectors:")
00190 sscanf(strValue.c_str(), "%d", &uPicInfo.sTBear.iSectors);
00191 }
00192
00193 fclose(fileInf);
00194
00195 return true;
00196 }
00197
00198
00199 bool clConvPic::LoadAndCreate (const char *cpSrcFileName)
00200 {
00201 try
00202 {
00203 ImgSrc = new Image(cpSrcFileName);
00204
00205 iSrcWidth = ImgSrc->columns();
00206 iSrcHeight = ImgSrc->rows();
00207
00208 ImgDst = new Image(Geometry(
00209 iSrcWidth + CP_MARGIN_L + CP_MARGIN_R,
00210 iSrcHeight + CP_MARGIN_T + CP_MARGIN_B),
00211 ColorRGB(1, 1, 1));
00212 ImgDst->resolutionUnits(PixelsPerInchResolution);
00213 if (cpPageSize)
00214 {
00215 string PageSpec;
00216
00217 PageSpec = string(cpPageSize) + string(CP_PAGE_SPEC);
00218 fprintf(stdout, "page: %s\n", PageSpec.c_str());
00219 ImgDst->magick("PS2");
00220 ImgDst->page(Geometry(PageSpec));
00221
00222 }
00223 else
00224 {
00225 ImgDst->density(Geometry(100, 100));
00226 }
00227
00228 if (!bTwoColor)
00229 {
00230 ImgDst->compressType(NoCompression);
00231 ImgDst->quality(100);
00232 ImgDst->quantizeDither(false);
00233 }
00234 else
00235 {
00236 ImgDst->compressType(RunlengthEncodedCompression);
00237 ImgDst->quality(100);
00238 ImgDst->quantizeDither(true);
00239 }
00240
00241 ImgDst->depth(8);
00242 ImgDst->matte(false);
00243 if (!bTwoColor)
00244 {
00245 ImgDst->antiAlias(true);
00246 ImgDst->strokeAntiAlias(true);
00247 }
00248 else
00249 {
00250 ImgDst->antiAlias(false);
00251 ImgDst->strokeAntiAlias(false);
00252 new DrawableTextAntialias(false);
00253 }
00254
00255 ImgDst->font(CP_FONT_NAME);
00256
00257 iDstWidth = ImgDst->columns();
00258 iDstHeight = ImgDst->rows();
00259 }
00260 catch (Exception &X)
00261 {
00262 fprintf(stderr, "exception: %s\n", X.what());
00263 return false;
00264 }
00265
00266 return true;
00267 }
00268
00269
00270 bool clConvPic::CopySource ()
00271 {
00272 try
00273 {
00274 ImgDst->strokeColor(ColorRGB(0, 0, 0));
00275 ImgDst->strokeWidth(1);
00276 ImgDst->draw(DrawableRectangle(CP_MARGIN_L - 1, CP_MARGIN_T - 1,
00277 CP_MARGIN_L + iSrcWidth, CP_MARGIN_T + iSrcHeight));
00278
00279 ImgDst->draw(DrawableCompositeImage(CP_MARGIN_L, CP_MARGIN_T, *ImgSrc));
00280 }
00281 catch (Exception &X)
00282 {
00283 fprintf(stderr, "exception: %s\n", X.what());
00284 return false;
00285 }
00286
00287 return true;
00288 }
00289
00290
00291 bool clConvPic::DrawLOFARInfo ()
00292 {
00293 time_t ttCreateTime;
00294 time_t ttTickTime;
00295 int iMarkCntr;
00296 int iMarkCount;
00297 int iMarkPos;
00298 int iTextWidth;
00299 int iTextHeight;
00300 int iAdvanceY;
00301 double dStartTime;
00302 double dEndTime;
00303 double dDeltaTime;
00304 double dDeltaFreq;
00305 double dFreqScale;
00306 double dRoundedRange;
00307 double dRoundStep;
00308 double dCountScale;
00309 double dTickStep;
00310 double dTickFreq;
00311 char cpTimeBuf[24];
00312 char cpTextBuf[4096];
00313 TypeMetric TextMetrics;
00314
00315 try
00316 {
00317 ImgDst->fontPointsize(CP_FONT_NORMAL);
00318 ImgDst->strokeColor(ColorRGB(0, 0, 0));
00319
00320 dStartTime = (double) uPicInfo.sLOFAR.ttTime;
00321 dEndTime = dStartTime + uPicInfo.sLOFAR.dLineTime * (double) iSrcHeight;
00322 dDeltaTime = dEndTime - dStartTime;
00323
00324 ImgDst->fontPointsize(CP_FONT_LARGE);
00325 ttCreateTime = (time_t) (dEndTime + 0.5);
00326 strftime(cpTimeBuf, 23, "%Y/%m/%d %H:%M:%S", localtime(&ttCreateTime));
00327 sprintf(cpTextBuf, "LOFAR %s", cpTimeBuf);
00328 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight, &iAdvanceY);
00329 ImgDst->draw(DrawableText(1, iAdvanceY + 1, cpTextBuf));
00330 sprintf(cpTextBuf, "Band: %g - %g Hz",
00331 uPicInfo.sLOFAR.dLowFreq, uPicInfo.sLOFAR.dHighFreq);
00332 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00333 ImgDst->draw(DrawableText(1, iAdvanceY * 2 + 1, cpTextBuf));
00334
00335 ImgDst->fontPointsize(CP_FONT_SMALL);
00336 iMarkCount = (int) (dDeltaTime / 60.0);
00337 for (iMarkCntr = 0; iMarkCntr <= iMarkCount; iMarkCntr++)
00338 {
00339 ttTickTime = (time_t)
00340 (dStartTime + (double) iMarkCntr * 60.0 + 0.5);
00341 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00342 GetTextSize(cpTimeBuf, &iTextWidth, &iTextHeight);
00343 ImgDst->fontTypeMetrics(cpTimeBuf, &TextMetrics);
00344 iMarkPos = CP_MARGIN_T + iSrcHeight -
00345 (int) ((double) iMarkCntr * 60.0 /
00346 uPicInfo.sLOFAR.dLineTime + 0.5);
00347 if (iMarkPos < (CP_MARGIN_T + iTextHeight))
00348 continue;
00349 ImgDst->draw(DrawableText(CP_MARGIN_L - iTextWidth - 1,
00350 iMarkPos + TextMetrics.descent() - 1, cpTimeBuf));
00351 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00352 CP_MARGIN_L, iMarkPos));
00353 }
00354 ttTickTime = (time_t) (dEndTime + 0.5);
00355 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00356 GetTextSize(cpTimeBuf, &iTextWidth, &iTextHeight);
00357 ImgDst->fontTypeMetrics(cpTimeBuf, &TextMetrics);
00358 iMarkPos = CP_MARGIN_T;
00359 ImgDst->draw(DrawableText(CP_MARGIN_L - iTextWidth - 1,
00360 iMarkPos + TextMetrics.descent() - 1, cpTimeBuf));
00361 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00362 CP_MARGIN_L, iMarkPos));
00363
00364 dDeltaFreq = uPicInfo.sLOFAR.dHighFreq - uPicInfo.sLOFAR.dLowFreq;
00365 dFreqScale = (double) iSrcWidth / dDeltaFreq;
00366 dRoundStep = pow(10.0, floor(log10(dDeltaFreq)));
00367 dRoundedRange = dDeltaFreq - fmod(dDeltaFreq, dRoundStep);
00368 if ((dRoundedRange / dRoundStep) <= 5.0)
00369 dCountScale = 0.01;
00370 else
00371 dCountScale = 0.1;
00372 iMarkCount = (int) (dDeltaFreq / (dRoundStep * dCountScale) + 0.5);
00373 dTickStep = dRoundStep * dCountScale;
00374 for (iMarkCntr = 0; iMarkCntr < iMarkCount; iMarkCntr++)
00375 {
00376 dTickFreq = uPicInfo.sLOFAR.dLowFreq +
00377 (double) iMarkCntr * dTickStep;
00378 iMarkPos = CP_MARGIN_L +
00379 (int) ((double) iMarkCntr * dTickStep * dFreqScale + 0.5);
00380 if (iMarkCntr % 10)
00381 {
00382 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00383 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKS_LEN));
00384 }
00385 else
00386 {
00387 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00388 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00389 sprintf(cpTextBuf, "%g", dTickFreq);
00390 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00391 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00392 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00393 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00394 cpTextBuf));
00395 }
00396 }
00397 iMarkPos = CP_MARGIN_L + (int) (dDeltaFreq * dFreqScale + 0.5);
00398 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00399 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00400 sprintf(cpTextBuf, "%g", uPicInfo.sLOFAR.dHighFreq);
00401 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00402 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00403 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00404 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00405 cpTextBuf));
00406 }
00407 catch (Exception &X)
00408 {
00409 fprintf(stderr, "exception: %s\n", X.what());
00410 return false;
00411 }
00412
00413 return true;
00414 }
00415
00416
00417 bool clConvPic::DrawDEMONInfo ()
00418 {
00419 time_t ttCreateTime;
00420 time_t ttTickTime;
00421 int iMarkCntr;
00422 int iMarkCount;
00423 int iMarkPos;
00424 int iTextWidth;
00425 int iTextHeight;
00426 int iAdvanceY;
00427 double dStartTime;
00428 double dEndTime;
00429 double dDeltaTime;
00430 double dFreqScale;
00431 double dRoundedRange;
00432 double dRoundStep;
00433 double dCountScale;
00434 double dTickStep;
00435 double dTickFreq;
00436 char cpTimeBuf[24];
00437 char cpTextBuf[4096];
00438 TypeMetric TextMetrics;
00439
00440 try
00441 {
00442 ImgDst->fontPointsize(CP_FONT_NORMAL);
00443 ImgDst->strokeColor(ColorRGB(0, 0, 0));
00444
00445 dStartTime = (double) uPicInfo.sDEMON.ttTime;
00446 dEndTime = dStartTime + uPicInfo.sDEMON.dLineTime * (double) iSrcHeight;
00447 dDeltaTime = dEndTime - dStartTime;
00448
00449 ImgDst->fontPointsize(CP_FONT_LARGE);
00450 ttCreateTime = (time_t) (dEndTime + 0.5);
00451 strftime(cpTimeBuf, 23, "%Y/%m/%d %H:%M:%S", localtime(&ttCreateTime));
00452 sprintf(cpTextBuf, "DEMON %s", cpTimeBuf);
00453 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight, &iAdvanceY);
00454 ImgDst->draw(DrawableText(1, iAdvanceY + 1, cpTextBuf));
00455 sprintf(cpTextBuf, "Band: %g - %g Hz, DEMON bandwidth %g Hz",
00456 uPicInfo.sDEMON.dLowFreq, uPicInfo.sDEMON.dHighFreq,
00457 uPicInfo.sDEMON.dDEMONBand);
00458 ImgDst->draw(DrawableText(1, iAdvanceY * 2 + 1, cpTextBuf));
00459
00460 ImgDst->fontPointsize(CP_FONT_SMALL);
00461 iMarkCount = (int) (dDeltaTime / 60.0);
00462 for (iMarkCntr = 0; iMarkCntr <= iMarkCount; iMarkCntr++)
00463 {
00464 ttTickTime = (time_t)
00465 (dStartTime + (double) iMarkCntr * 60.0 + 0.5);
00466 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00467 GetTextSize(cpTimeBuf, &iTextWidth, &iTextHeight);
00468 ImgDst->fontTypeMetrics(cpTimeBuf, &TextMetrics);
00469 iMarkPos = CP_MARGIN_T + iSrcHeight -
00470 (int) ((double) iMarkCntr * 60.0 /
00471 uPicInfo.sDEMON.dLineTime + 0.5);
00472 if (iMarkPos < (CP_MARGIN_T + iTextHeight))
00473 continue;
00474 ImgDst->draw(DrawableText(CP_MARGIN_L - iTextWidth - 1,
00475 iMarkPos + TextMetrics.descent() - 1, cpTimeBuf));
00476 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00477 CP_MARGIN_L, iMarkPos));
00478 }
00479 ttTickTime = (time_t) (dEndTime + 0.5);
00480 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00481 GetTextSize(cpTimeBuf, &iTextWidth, &iTextHeight);
00482 ImgDst->fontTypeMetrics(cpTimeBuf, &TextMetrics);
00483 iMarkPos = CP_MARGIN_T;
00484 ImgDst->draw(DrawableText(CP_MARGIN_L - iTextWidth - 1,
00485 iMarkPos + TextMetrics.descent() - 1, cpTimeBuf));
00486 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00487 CP_MARGIN_L, iMarkPos));
00488
00489 dFreqScale = (double) iSrcWidth / uPicInfo.sDEMON.dDEMONBand;
00490 dRoundStep = pow(10.0, floor(log10(uPicInfo.sDEMON.dDEMONBand)));
00491 dRoundedRange = uPicInfo.sDEMON.dDEMONBand -
00492 fmod(uPicInfo.sDEMON.dDEMONBand, dRoundStep);
00493 if ((dRoundedRange / dRoundStep) <= 5.0)
00494 dCountScale = 0.01;
00495 else
00496 dCountScale = 0.1;
00497 iMarkCount = (int) (uPicInfo.sDEMON.dDEMONBand /
00498 (dRoundStep * dCountScale) + 0.5);
00499 dTickStep = dRoundStep * dCountScale;
00500 for (iMarkCntr = 0; iMarkCntr < iMarkCount; iMarkCntr++)
00501 {
00502 dTickFreq = (double) iMarkCntr * dTickStep;
00503 iMarkPos = CP_MARGIN_L +
00504 (int) ((double) iMarkCntr * dTickStep * dFreqScale + 0.5);
00505 if (iMarkCntr % 10)
00506 {
00507 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00508 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKS_LEN));
00509 }
00510 else
00511 {
00512 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00513 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00514 sprintf(cpTextBuf, "%g", dTickFreq);
00515 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00516 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00517 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00518 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00519 cpTextBuf));
00520 }
00521 }
00522 iMarkPos = CP_MARGIN_L + (int)
00523 (uPicInfo.sDEMON.dDEMONBand * dFreqScale + 0.5);
00524 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00525 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00526 sprintf(cpTextBuf, "%g", uPicInfo.sDEMON.dDEMONBand);
00527 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00528 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00529 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00530 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00531 cpTextBuf));
00532 }
00533 catch (Exception &X)
00534 {
00535 fprintf(stderr, "exception: %s\n", X.what());
00536 return false;
00537 }
00538
00539 return true;
00540 }
00541
00542
00543 bool clConvPic::DrawSGramInfo ()
00544 {
00545 time_t ttCreateTime;
00546 time_t ttTickTime;
00547 int iMarkCntr;
00548 int iMarkCount;
00549 int iMarkPos;
00550 int iTextWidth;
00551 int iTextHeight;
00552 int iAdvanceY;
00553 double dStartTime;
00554 double dEndTime;
00555 double dDeltaTime;
00556 double dDeltaFreq;
00557 double dFreqScale;
00558 double dRoundedRange;
00559 double dRoundStep;
00560 double dCountScale;
00561 double dTickStep;
00562 double dTickFreq;
00563 char cpTimeBuf[24];
00564 char cpTextBuf[4096];
00565 TypeMetric TextMetrics;
00566
00567 try
00568 {
00569 ImgDst->fontPointsize(CP_FONT_NORMAL);
00570 ImgDst->strokeColor(ColorRGB(0, 0, 0));
00571
00572 dEndTime = (double) uPicInfo.sSGram.ttTime;
00573 dStartTime = dEndTime - uPicInfo.sSGram.dLineTime * (double) iSrcWidth;
00574 dDeltaTime = dEndTime - dStartTime;
00575
00576 ImgDst->fontPointsize(CP_FONT_LARGE);
00577 ttCreateTime = (time_t) (dEndTime + 0.5);
00578 strftime(cpTimeBuf, 23, "%Y/%m/%d %H:%M:%S", localtime(&ttCreateTime));
00579 sprintf(cpTextBuf, "Spectrogram %s", cpTimeBuf);
00580 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight, &iAdvanceY);
00581 ImgDst->draw(DrawableText(1, iAdvanceY + 1, cpTextBuf));
00582 sprintf(cpTextBuf, "Band: %g - %g Hz",
00583 uPicInfo.sSGram.dLowFreq, uPicInfo.sSGram.dHighFreq);
00584 ImgDst->draw(DrawableText(1, iAdvanceY * 2 + 1, cpTextBuf));
00585
00586 ImgDst->fontPointsize(CP_FONT_SMALL);
00587 iMarkCount = 10;
00588 dTickStep = dDeltaTime / 10.0;
00589 for (iMarkCntr = 0; iMarkCntr < iMarkCount; iMarkCntr++)
00590 {
00591 if (iMarkCntr % 1)
00592 {
00593 iMarkPos = CP_MARGIN_L +
00594 (int) ((double) iMarkCntr * dTickStep /
00595 uPicInfo.sSGram.dLineTime + 0.5);
00596 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00597 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKS_LEN));
00598 }
00599 else
00600 {
00601 ttTickTime = (time_t)
00602 (dStartTime + (double) iMarkCntr * dTickStep);
00603 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00604 sprintf(cpTextBuf, "%s.%03i", cpTimeBuf, (int)
00605 ((dStartTime + (double) iMarkCntr * (double) dTickStep -
00606 (double) ttTickTime) * 1000.0 + 0.5));
00607 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00608 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00609 iMarkPos = CP_MARGIN_L +
00610 (int) ((double) iMarkCntr * dTickStep /
00611 uPicInfo.sSGram.dLineTime + 0.5);
00612 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00613 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00614 cpTextBuf));
00615 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00616 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00617 }
00618 }
00619 ttTickTime = (time_t) dEndTime;
00620 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00621 sprintf(cpTextBuf, "%s.%03i", cpTimeBuf, (int)
00622 ((dEndTime - (double) ttTickTime) * 1000.0 + 0.5));
00623 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00624 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00625 iMarkPos = CP_MARGIN_L + iSrcWidth;
00626 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00627 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00628 cpTextBuf));
00629 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00630 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00631
00632 dDeltaFreq = uPicInfo.sSGram.dHighFreq - uPicInfo.sSGram.dLowFreq;
00633 dFreqScale = (double) iSrcHeight / dDeltaFreq;
00634 dRoundStep = pow(10.0, floor(log10(dDeltaFreq)));
00635 dRoundedRange = dDeltaFreq - fmod(dDeltaFreq, dRoundStep);
00636 dCountScale = 0.1;
00637 iMarkCount = (int) (dDeltaFreq / (dRoundStep * dCountScale) + 0.5);
00638 dTickStep = dRoundStep * dCountScale;
00639 for (iMarkCntr = 0; iMarkCntr < iMarkCount; iMarkCntr++)
00640 {
00641 dTickFreq = uPicInfo.sSGram.dLowFreq +
00642 (double) iMarkCntr * dTickStep;
00643 iMarkPos = CP_MARGIN_T + iSrcHeight -
00644 (int) ((double) iMarkCntr * dTickStep * dFreqScale + 0.5);
00645 if (iMarkCntr % 5)
00646 {
00647 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKS_LEN, iMarkPos,
00648 CP_MARGIN_L, iMarkPos));
00649 }
00650 else
00651 {
00652 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00653 CP_MARGIN_L, iMarkPos));
00654 sprintf(cpTextBuf, "%g", dTickFreq);
00655 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00656 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00657 ImgDst->draw(DrawableText(
00658 CP_MARGIN_L - CP_TICKL_LEN - iTextWidth - 1,
00659 iMarkPos + TextMetrics.descent() - 1,
00660 cpTextBuf));
00661 }
00662 }
00663 iMarkPos = CP_MARGIN_T;
00664 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00665 CP_MARGIN_L, iMarkPos));
00666 sprintf(cpTextBuf, "%g", uPicInfo.sSGram.dHighFreq);
00667 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00668 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00669 ImgDst->draw(DrawableText(CP_MARGIN_L - CP_TICKL_LEN - iTextWidth - 1,
00670 iMarkPos + TextMetrics.descent() - 1,
00671 cpTextBuf));
00672 }
00673 catch (Exception &X)
00674 {
00675 fprintf(stderr, "exception: %s\n", X.what());
00676 return false;
00677 }
00678
00679 return true;
00680 }
00681
00682
00683 bool clConvPic::DrawTBearInfo ()
00684 {
00685 time_t ttCreateTime;
00686 time_t ttTickTime;
00687 int iMarkCntr;
00688 int iMarkCount;
00689 int iMarkPos;
00690 int iTextWidth;
00691 int iTextHeight;
00692 int iAdvanceY;
00693 double dStartTime;
00694 double dEndTime;
00695 double dDeltaTime;
00696 double dDeltaDir;
00697 double dDirScale;
00698 double dTickStep;
00699 double dTickDir;
00700 char cpTimeBuf[24];
00701 char cpTextBuf[4096];
00702 TypeMetric TextMetrics;
00703
00704 try
00705 {
00706 ImgDst->fontPointsize(CP_FONT_NORMAL);
00707 ImgDst->strokeColor(ColorRGB(0, 0, 0));
00708
00709 dStartTime = (double) uPicInfo.sTBear.ttTime;
00710 dEndTime = dStartTime + uPicInfo.sTBear.dIntTime * (double) iSrcHeight;
00711 dDeltaTime = dEndTime - dStartTime;
00712
00713 ImgDst->fontPointsize(CP_FONT_LARGE);
00714 ttCreateTime = (time_t) (dEndTime + 0.5);
00715 strftime(cpTimeBuf, 23, "%Y/%m/%d %H:%M:%S", localtime(&ttCreateTime));
00716 sprintf(cpTextBuf, "Bearing-time %s", cpTimeBuf);
00717 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight, &iAdvanceY);
00718 ImgDst->draw(DrawableText(1, iAdvanceY + 1, cpTextBuf));
00719 sprintf(cpTextBuf,
00720 "Sector: %g - %g deg, %i beams, integration time %g s",
00721 RadToDeg(uPicInfo.sTBear.dLeftDir),
00722 RadToDeg(uPicInfo.sTBear.dRightDir),
00723 uPicInfo.sTBear.iSectors,
00724 uPicInfo.sTBear.dIntTime);
00725 ImgDst->draw(DrawableText(1, iAdvanceY * 2 + 1, cpTextBuf));
00726
00727 ImgDst->fontPointsize(CP_FONT_SMALL);
00728 iMarkCount = (int) (dDeltaTime / 60.0);
00729 for (iMarkCntr = 0; iMarkCntr <= iMarkCount; iMarkCntr++)
00730 {
00731 ttTickTime = (time_t)
00732 (dStartTime + (double) iMarkCntr * 60.0 + 0.5);
00733 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00734 GetTextSize(cpTimeBuf, &iTextWidth, &iTextHeight);
00735 ImgDst->fontTypeMetrics(cpTimeBuf, &TextMetrics);
00736 iMarkPos = CP_MARGIN_T + iSrcHeight -
00737 (int) ((double) iMarkCntr * 60.0 /
00738 uPicInfo.sTBear.dIntTime + 0.5);
00739 if (iMarkPos < (CP_MARGIN_T + iTextHeight))
00740 continue;
00741 ImgDst->draw(DrawableText(CP_MARGIN_L - iTextWidth - 1,
00742 iMarkPos + TextMetrics.descent() - 1, cpTimeBuf));
00743 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00744 CP_MARGIN_L, iMarkPos));
00745 }
00746 ttTickTime = (time_t) (dEndTime + 0.5);
00747 strftime(cpTimeBuf, 9, "%H:%M:%S", localtime(&ttTickTime));
00748 GetTextSize(cpTimeBuf, &iTextWidth, &iTextHeight);
00749 ImgDst->fontTypeMetrics(cpTimeBuf, &TextMetrics);
00750 iMarkPos = CP_MARGIN_T;
00751 ImgDst->draw(DrawableText(CP_MARGIN_L - iTextWidth - 1,
00752 iMarkPos + TextMetrics.descent() - 1, cpTimeBuf));
00753 ImgDst->draw(DrawableLine(CP_MARGIN_L - CP_TICKL_LEN, iMarkPos,
00754 CP_MARGIN_L, iMarkPos));
00755
00756 dDeltaDir = RadToDeg(uPicInfo.sTBear.dRightDir) -
00757 RadToDeg(uPicInfo.sTBear.dLeftDir);
00758 dDirScale = (double) iSrcWidth / dDeltaDir;
00759 iMarkCount = 90;
00760 dTickStep = dDeltaDir / (double) iMarkCount;
00761 for (iMarkCntr = 0; iMarkCntr < iMarkCount; iMarkCntr++)
00762 {
00763 dTickDir = RadToDeg(uPicInfo.sTBear.dLeftDir) +
00764 (double) iMarkCntr * dTickStep;
00765 iMarkPos = CP_MARGIN_L +
00766 (int) ((double) iMarkCntr * dTickStep * dDirScale + 0.5);
00767 if (iMarkCntr % 5)
00768 {
00769 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00770 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKS_LEN));
00771 }
00772 else
00773 {
00774 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00775 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00776 sprintf(cpTextBuf, "%0.0f", dTickDir);
00777 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00778 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00779 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00780 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00781 cpTextBuf));
00782 }
00783 }
00784 iMarkPos = CP_MARGIN_L + (int) (dDeltaDir * dDirScale + 0.5);
00785 ImgDst->draw(DrawableLine(iMarkPos, CP_MARGIN_T + iSrcHeight,
00786 iMarkPos, CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN));
00787 sprintf(cpTextBuf, "%g", RadToDeg(uPicInfo.sTBear.dRightDir));
00788 GetTextSize(cpTextBuf, &iTextWidth, &iTextHeight);
00789 ImgDst->fontTypeMetrics(cpTextBuf, &TextMetrics);
00790 ImgDst->draw(DrawableText(iMarkPos - iTextWidth / 2,
00791 CP_MARGIN_T + iSrcHeight + CP_TICKL_LEN + TextMetrics.ascent() + 1,
00792 cpTextBuf));
00793 }
00794 catch (Exception &X)
00795 {
00796 fprintf(stderr, "exception: %s\n", X.what());
00797 return false;
00798 }
00799
00800 return true;
00801 }
00802
00803
00804 bool clConvPic::ConvertColors ()
00805 {
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826 try
00827 {
00828 ImgDst->quantizeColors(2);
00829 ImgDst->type(BilevelType);
00830 }
00831 catch (Exception &X)
00832 {
00833 fprintf(stderr, "exception: %s\n", X.what());
00834 return false;
00835 }
00836
00837 return true;
00838 }
00839
00840
00841 bool clConvPic::SaveResult (const char *cpDstFileName)
00842 {
00843 try
00844 {
00845
00846 if (cpPageSize)
00847 {
00848 ImgDst->rotate(270);
00849
00850
00851 }
00852 ImgDst->write(cpDstFileName);
00853 }
00854 catch (Exception &X)
00855 {
00856 fprintf(stderr, "exception: %s\n", X.what());
00857 return false;
00858 }
00859
00860 return true;
00861 }
00862
00863
00864 void clConvPic::Clean ()
00865 {
00866 try
00867 {
00868 delete ImgSrc;
00869 delete ImgDst;
00870 }
00871 catch (Exception &X)
00872 {
00873 fprintf(stderr, "exception: %s\n", X.what());
00874 }
00875 }
00876
00877
00878 void clConvPic::SplitLine (const char *cpSource, string &strFirst,
00879 string &strSecond)
00880 {
00881 char *cpSrcCopy;
00882 char *cpParsePtr;
00883
00884 cpSrcCopy = strdup(cpSource);
00885 cpParsePtr = strtok(cpSrcCopy, " \t\n");
00886 if (cpParsePtr != NULL)
00887 strFirst = cpParsePtr;
00888 cpParsePtr = strtok(NULL, "\n");
00889 if (cpParsePtr != NULL)
00890 strSecond = cpParsePtr;
00891 free(cpSrcCopy);
00892 }
00893
00894
00895 time_t clConvPic::ParseTime (const char *cpTimeString)
00896 {
00897 int iYear;
00898 int iMonth;
00899 int iDay;
00900 int iHour;
00901 int iMin;
00902 int iSec;
00903 struct tm sTM;
00904
00905 sscanf(cpTimeString, "%d/%d/%d %d:%d:%d",
00906 &iYear, &iMonth, &iDay, &iHour, &iMin, &iSec);
00907
00908 memset(&sTM, 0x00, sizeof(sTM));
00909 sTM.tm_year = iYear - 1900;
00910 sTM.tm_mon = iMonth - 1;
00911 sTM.tm_mday = iDay;
00912 sTM.tm_hour = iHour;
00913 sTM.tm_min = iMin;
00914 sTM.tm_sec = iSec;
00915 # ifdef LINUXSYS
00916 sTM.tm_isdst = daylight;
00917 # endif
00918
00919 return mktime(&sTM);
00920 }
00921
00922
00923 inline double clConvPic::RadToDeg (double dRad)
00924 {
00925 return (180.0 / acos(-1.0) * dRad);
00926 }
00927
00928
00929 void clConvPic::GetTextSize (const char *cpText, int *ipWidth, int *ipHeight,
00930 int *ipAdvanceY)
00931 {
00932 try
00933 {
00934 TypeMetric TextMetrics;
00935
00936 ImgDst->fontTypeMetrics(cpText, &TextMetrics);
00937 *ipWidth = (int) (TextMetrics.textWidth() + 0.5);
00938 *ipHeight = (int) (TextMetrics.textHeight() + 0.5);
00939 if (ipAdvanceY)
00940 *ipAdvanceY = (int)
00941 (TextMetrics.ascent() - TextMetrics.descent() + 0.5);
00942 }
00943 catch (Exception &X)
00944 {
00945 fprintf(stderr, "exception: %s\n", X.what());
00946 }
00947 }
00948
00949
00950 clConvPic::clConvPic ()
00951 {
00952 bTwoColor = false;
00953 iType = -1;
00954 cpPageSize = NULL;
00955 }
00956
00957
00958 clConvPic::~clConvPic ()
00959 {
00960 }
00961
00962
00963 int clConvPic::Main (int *ipArgC, char ***cpppArgV)
00964 {
00965 int iArgCntr = 1;
00966 int iArgC = *ipArgC;
00967 char **cppArgV = *cpppArgV;
00968
00969 if (iArgC < 4)
00970 {
00971 printf("%s <-l|-d|-s|-b> [-2] [-pagesize] <input> <output>\n",
00972 cppArgV[0]);
00973 puts("\t-l LOFAR");
00974 puts("\t-d DEMON");
00975 puts("\t-s spectrogram");
00976 puts("\t-b time-bearing");
00977 puts("\t-2 convert to 2-colors");
00978 return 1;
00979 }
00980
00981 while (iArgCntr < (iArgC - 2))
00982 {
00983 if (strcmp(cppArgV[iArgCntr], "-l") == 0)
00984 iType = CP_TYPE_LOFAR;
00985 else if (strcmp(cppArgV[iArgCntr], "-d") == 0)
00986 iType = CP_TYPE_DEMON;
00987 else if (strcmp(cppArgV[iArgCntr], "-s") == 0)
00988 iType = CP_TYPE_SGRAM;
00989 else if (strcmp(cppArgV[iArgCntr], "-b") == 0)
00990 iType = CP_TYPE_TBEAR;
00991 else if (strcmp(cppArgV[iArgCntr], "-2") == 0)
00992 bTwoColor = true;
00993 else if (cppArgV[iArgCntr][0] == '-')
00994 cpPageSize = strdup(&cppArgV[iArgCntr][1]);
00995 if (cppArgV[iArgCntr][0] != '-')
00996 break;
00997 iArgCntr++;
00998 }
00999 if (iType < 0)
01000 {
01001 puts("Type not specified!");
01002 return 2;
01003 }
01004
01005 if (!Initialize())
01006 return 3;
01007
01008 switch (iType)
01009 {
01010 case CP_TYPE_LOFAR:
01011 if (!LoadLOFARInfo(cppArgV[iArgCntr]))
01012 return 4;
01013 break;
01014 case CP_TYPE_DEMON:
01015 if (!LoadDEMONInfo(cppArgV[iArgCntr]))
01016 return 4;
01017 break;
01018 case CP_TYPE_SGRAM:
01019 if (!LoadSGramInfo(cppArgV[iArgCntr]))
01020 return 4;
01021 break;
01022 case CP_TYPE_TBEAR:
01023 if (!LoadTBearInfo(cppArgV[iArgCntr]))
01024 return 4;
01025 break;
01026 }
01027
01028 if (!LoadAndCreate(cppArgV[iArgCntr]))
01029 return 5;
01030
01031 iArgCntr++;
01032
01033 if (!CopySource())
01034 return 6;
01035
01036 switch (iType)
01037 {
01038 case CP_TYPE_LOFAR:
01039 if (!DrawLOFARInfo())
01040 return 7;
01041 break;
01042 case CP_TYPE_DEMON:
01043 if (!DrawDEMONInfo())
01044 return 7;
01045 break;
01046 case CP_TYPE_SGRAM:
01047 if (!DrawSGramInfo())
01048 return 7;
01049 break;
01050 case CP_TYPE_TBEAR:
01051 if (!DrawTBearInfo())
01052 return 7;
01053 break;
01054 }
01055
01056 if (bTwoColor)
01057 {
01058 if (!ConvertColors())
01059 return 8;
01060 }
01061
01062 if (!SaveResult(cppArgV[iArgCntr]))
01063 return 10;
01064
01065 Clean();
01066
01067 return 0;
01068 }