00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <math.h>
00027 #include <float.h>
00028 #include <time.h>
00029 #include <unistd.h>
00030 #include <tiffio.h>
00031 #include <gtk/gtk.h>
00032 #include <gdk/gdkrgb.h>
00033 #include <freetype2/freetype/freetype.h>
00034
00035 #include "Config.h"
00036 #include "FrameBuf.hh"
00037
00038
00039 void clFrameBuf::RGBA2RGB(unsigned char *ucpDest, const unsigned int *upSrc,
00040 int iCXPos, int iCYPos, int iDestWidth, int iDestHeight,
00041 int iSrcWidth, int iSrcHeight)
00042 {
00043 int iYCntr;
00044 int iXCntr;
00045 int iSrcIdx = 0;
00046 int iDestIdx = 0;
00047
00048 for (iYCntr = 0; iYCntr < iSrcHeight; iYCntr++)
00049 {
00050 iDestIdx = ((iYCntr + iCYPos) * iDestWidth + iCXPos) * 3;
00051 for (iXCntr = 0; iXCntr < iSrcWidth; iXCntr++)
00052 {
00053 ucpDest[iDestIdx++] = (unsigned char)
00054 (upSrc[iSrcIdx] & 0xff);
00055 ucpDest[iDestIdx++] = (unsigned char)
00056 ((upSrc[iSrcIdx] >> 8) & 0xff);
00057 ucpDest[iDestIdx++] = (unsigned char)
00058 ((upSrc[iSrcIdx] >> 16) & 0xff);
00059 iSrcIdx++;
00060 }
00061 }
00062 }
00063
00064
00065 bool clFrameBuf::SetTiffTags(const char *cpFileName, int iCompression,
00066 int iJPEGQuality, const char *cpDescription, int iContinuous,
00067 int iTWidth, int iTHeight)
00068 {
00069 time_t ttTime;
00070 gchar *cpConv;
00071 char cpHostName[256];
00072
00073 if (!TIFFSetField(tiffImg, TIFFTAG_IMAGEWIDTH, iTWidth))
00074 return false;
00075 if (iContinuous == FB_TIFF_CONT_NO)
00076 {
00077 if (!TIFFSetField(tiffImg, TIFFTAG_IMAGELENGTH, iTHeight))
00078 return false;
00079 }
00080 else
00081 {
00082 if (!TIFFSetField(tiffImg, TIFFTAG_IMAGELENGTH, 0))
00083 return false;
00084 }
00085 if (!TIFFSetField(tiffImg, TIFFTAG_BITSPERSAMPLE, 8))
00086 return false;
00087 if (!TIFFSetField(tiffImg, TIFFTAG_COMPRESSION, iCompression))
00088 return false;
00089 if (!TIFFSetField(tiffImg, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB))
00090 return false;
00091 if (!TIFFSetField(tiffImg, TIFFTAG_DOCUMENTNAME, cpFileName))
00092 return false;
00093 if (!TIFFSetField(tiffImg, TIFFTAG_IMAGEDESCRIPTION, cpDescription))
00094 return false;
00095 if (iContinuous == FB_TIFF_CONT_VERTICAL)
00096 {
00097 if (!TIFFSetField(tiffImg, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT))
00098 return false;
00099 }
00100 else if (iContinuous == FB_TIFF_CONT_HORIZONTAL)
00101 {
00102 if (!TIFFSetField(tiffImg, TIFFTAG_ORIENTATION, ORIENTATION_LEFTBOT))
00103 return false;
00104 }
00105 else
00106 {
00107 if (!TIFFSetField(tiffImg, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT))
00108 return false;
00109 }
00110 if (!TIFFSetField(tiffImg, TIFFTAG_SAMPLESPERPIXEL, 3))
00111 return false;
00112 if (iContinuous == FB_TIFF_CONT_NO)
00113 {
00114 uiStripSize = TIFFDefaultStripSize(tiffImg, 0);
00115 if (!TIFFSetField(tiffImg, TIFFTAG_ROWSPERSTRIP, uiStripSize))
00116 return false;
00117 }
00118 else
00119 {
00120 uiStripSize = 1;
00121 if (!TIFFSetField(tiffImg, TIFFTAG_ROWSPERSTRIP, uiStripSize))
00122 return false;
00123 }
00124 if (!TIFFSetField(tiffImg, TIFFTAG_MINSAMPLEVALUE, 0))
00125 return false;
00126 if (!TIFFSetField(tiffImg, TIFFTAG_MAXSAMPLEVALUE, 0xff))
00127 return false;
00128 if (!TIFFSetField(tiffImg, TIFFTAG_XRESOLUTION, FB_TIFF_RESOLUTION))
00129 return false;
00130 if (!TIFFSetField(tiffImg, TIFFTAG_YRESOLUTION, FB_TIFF_RESOLUTION))
00131 return false;
00132 if (!TIFFSetField(tiffImg, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG))
00133 return false;
00134 if (!TIFFSetField(tiffImg, TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH))
00135 return false;
00136 cpConv = g_strdup_printf("HASAS %i.%i.%i",
00137 GLOBAL_VERSMAJ, GLOBAL_VERSMIN, GLOBAL_VERSPL);
00138 if (!TIFFSetField(tiffImg, TIFFTAG_SOFTWARE, cpConv))
00139 return false;
00140 if (!TIFFSetField(tiffImg, TIFFTAG_ARTIST, cpConv))
00141 return false;
00142 g_free(cpConv);
00143 ttTime = time(NULL);
00144 strftime(cpDateTime, FB_TIFF_DATELEN + 1,
00145 "%Y/%m/%d %H:%M:%S", localtime(&ttTime));
00146 if (!TIFFSetField(tiffImg, TIFFTAG_DATETIME, cpDateTime))
00147 return false;
00148 gethostname(cpHostName, 0xff);
00149 if (!TIFFSetField(tiffImg, TIFFTAG_HOSTCOMPUTER, cpHostName))
00150 return false;
00151
00152 if (!TIFFSetField(tiffImg, TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT))
00153 return false;
00154 if (iCompression == FB_TIFF_COMPRESS_JPEG)
00155 {
00156 if (!TIFFSetField(tiffImg, TIFFTAG_JPEGQUALITY, iJPEGQuality))
00157 return false;
00158 if (!TIFFSetField(tiffImg, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB))
00159 return false;
00160 }
00161 return true;
00162 }
00163
00164
00165 bool clFrameBuf::WriteTiffData()
00166 {
00167 uint32 uiStripMod;
00168 uint32 *upFrame;
00169 uint8 *ucpFrame24;
00170 tstrip_t uiStrip;
00171 tstrip_t uiStripCount;
00172 clAlloc Frame24;
00173
00174 ucpFrame24 = (uint8 *)
00175 Frame24.Size(iWidth * iHeight * 3 * sizeof(unsigned char));
00176 memset(ucpFrame24, 0xff, iWidth * iHeight * 3 * sizeof(unsigned char));
00177
00178 upFrame = (uint32 *) GetCurPtr(0, 0);
00179 RGBA2RGB((unsigned char *) ucpFrame24,
00180 (const unsigned int *) upFrame,
00181 0, 0, iWidth, iHeight, iWidth, iHeight);
00182 uiStripCount = iHeight / uiStripSize;
00183 for (uiStrip = 0; uiStrip < uiStripCount; uiStrip++)
00184 {
00185 if (TIFFWriteEncodedStrip(tiffImg, uiStrip,
00186 (tdata_t) &ucpFrame24[uiStrip * uiStripSize * iWidth * 3],
00187 uiStripSize * iWidth * 3 * sizeof(uint8)) < 0)
00188 {
00189 return false;
00190 }
00191 }
00192 uiStripMod = iHeight % uiStripSize;
00193 if (uiStripMod != 0)
00194 {
00195 if (TIFFWriteEncodedStrip(tiffImg, uiStripCount,
00196 (tdata_t) &ucpFrame24[uiStripCount * uiStripSize * iWidth * 3],
00197 uiStripMod * iWidth * 3 * sizeof(uint8)) < 0)
00198 {
00199 return false;
00200 }
00201 }
00202 return true;
00203 }
00204
00205
00206 bool clFrameBuf::WriteTiffData(int iLMarg, int iBMarg,
00207 double dXMin, double dXMax, double dYMin, double dYMax)
00208 {
00209 int iTWidth;
00210 int iTHeight;
00211 char *cpText;
00212 uint32 uiStripMod;
00213 uint32 *upFrame;
00214 uint8 *ucpFrame24;
00215 tstrip_t uiStrip;
00216 tstrip_t uiStripCount;
00217 clAlloc Frame24;
00218
00219 iTWidth = iWidth + iLMarg;
00220 iTHeight = iHeight + iBMarg;
00221 ucpFrame24 = (uint8 *)
00222 Frame24.Size(iTWidth * iTHeight * 3 * sizeof(unsigned char));
00223 memset(ucpFrame24, 0xff, iTWidth * iTHeight * 3 * sizeof(unsigned char));
00224
00225 DrawHLine((unsigned char *) ucpFrame24,
00226 iLMarg - iPixFontSize, iTWidth, 0, iTWidth, iTHeight);
00227 DrawHLine((unsigned char *) ucpFrame24,
00228 iLMarg - iPixFontSize, iTWidth, iHeight, iTWidth, iTHeight);
00229 DrawVLine((unsigned char *) ucpFrame24,
00230 iLMarg - 1, 0, iHeight + iPixFontSize, iTWidth, iTHeight);
00231 DrawVLine((unsigned char *) ucpFrame24,
00232 iTWidth - 1, 0, iHeight + iPixFontSize, iTWidth, iTHeight);
00233
00234 if (!DrawText((unsigned char *) ucpFrame24,
00235 1, iTHeight - iPixFontSize, iTWidth, iTHeight, cpDateTime))
00236 return false;
00237 cpText = g_strdup_printf("%g", dXMin);
00238 if (!DrawText((unsigned char *) ucpFrame24,
00239 iLMarg, iHeight + iPixFontSize, iTWidth, iTHeight, cpText))
00240 return false;
00241 g_free(cpText);
00242 cpText = g_strdup_printf("%g", dXMax);
00243 if (!DrawText((unsigned char *) ucpFrame24,
00244 iTWidth - strlen(cpText) * iMaxFontWidth, iHeight + iPixFontSize,
00245 iTWidth, iTHeight, cpText))
00246 return false;
00247 g_free(cpText);
00248 cpText = g_strdup_printf("%g", dYMin);
00249 if (!DrawText((unsigned char *) ucpFrame24,
00250 1, iHeight - iPixFontSize, iTWidth, iTHeight, cpText))
00251 return false;
00252 g_free(cpText);
00253 cpText = g_strdup_printf("%g", dYMax);
00254 if (!DrawText((unsigned char *) ucpFrame24,
00255 1, 1, iTWidth, iTHeight, cpText))
00256 return false;
00257 g_free(cpText);
00258
00259 upFrame = (uint32 *) GetCurPtr(0, 0);
00260 RGBA2RGB((unsigned char *) ucpFrame24,
00261 (const unsigned int *) upFrame,
00262 iLMarg, 0, iTWidth, iTHeight, iWidth, iHeight);
00263 uiStripCount = iTHeight / uiStripSize;
00264 for (uiStrip = 0; uiStrip < uiStripCount; uiStrip++)
00265 {
00266 if (TIFFWriteEncodedStrip(tiffImg, uiStrip,
00267 (tdata_t) &ucpFrame24[uiStrip * uiStripSize * iTWidth * 3],
00268 uiStripSize * iTWidth * 3 * sizeof(uint8)) < 0)
00269 {
00270 return false;
00271 }
00272 }
00273 uiStripMod = iTHeight % uiStripSize;
00274 if (uiStripMod != 0)
00275 {
00276 if (TIFFWriteEncodedStrip(tiffImg, uiStripCount,
00277 (tdata_t) &ucpFrame24[uiStripCount * uiStripSize * iTWidth * 3],
00278 uiStripMod * iTWidth * 3 * sizeof(uint8)) < 0)
00279 {
00280 return false;
00281 }
00282 }
00283 return true;
00284 }
00285
00286
00287 bool clFrameBuf::WriteTiffScanData()
00288 {
00289 uint8 *ucpScan24;
00290 clAlloc Scan24;
00291
00292 ucpScan24 = (uint8 *) Scan24.Size(iWidth * 3 * sizeof(unsigned char));
00293 if (!TIFFSetField(tiffImg, TIFFTAG_IMAGELENGTH, uiContStrip + 1))
00294 return false;
00295 RGBA2RGB((unsigned char *) ucpScan24,
00296 (const unsigned int *) upScanBuf,
00297 0, 0, iWidth, 1, iWidth, 1);
00298 if (TIFFWriteEncodedStrip(tiffImg, uiContStrip,
00299 (tdata_t) ucpScan24, iWidth * 3 * sizeof(uint8)) < 0)
00300 {
00301 return false;
00302 }
00303 uiContStrip++;
00304 return true;
00305 }
00306
00307
00308 void clFrameBuf::DrawHLine (unsigned char *ucpFrame24, int iXPos1, int iXPos2,
00309 int iYPos, int iTWidth, int iTHeight)
00310 {
00311 int iXCntr;
00312 int iPixIdx;
00313
00314 iPixIdx = (iYPos * iTWidth + iXPos1) * 3;
00315 for (iXCntr = iXPos1; iXCntr < iXPos2; iXCntr++)
00316 {
00317 ucpFrame24[iPixIdx++] = 0x00;
00318 ucpFrame24[iPixIdx++] = 0x00;
00319 ucpFrame24[iPixIdx++] = 0x00;
00320 }
00321 }
00322
00323
00324 void clFrameBuf::DrawVLine (unsigned char *ucpFrame24, int iXPos,
00325 int iYPos1, int iYPos2, int iTWidth, int iTHeight)
00326 {
00327 int iYCntr;
00328 int iPixIdx;
00329
00330 iPixIdx = (iYPos1 * iTWidth + iXPos) * 3;
00331 for (iYCntr = iYPos1; iYCntr < iYPos2; iYCntr++)
00332 {
00333 ucpFrame24[iPixIdx] = 0x00;
00334 ucpFrame24[iPixIdx + 1] = 0x00;
00335 ucpFrame24[iPixIdx + 2] = 0x00;
00336 iPixIdx += iTWidth * 3;
00337 }
00338 }
00339
00340
00341 bool clFrameBuf::DrawText (unsigned char *ucpFrame24,
00342 int iTXPos, int iTYPos, int iTWidth, int iTHeight,
00343 const char *cpTText)
00344 {
00345 int iCharCntr;
00346 int iCurXPos;
00347 int iGYCntr;
00348 int iGXCntr;
00349 int iPixPos;
00350 unsigned char ucGPix;
00351 double dPointSize;
00352
00353 dPointSize = 1.0 / 72.0;
00354 iCurXPos = iTXPos;
00355 for (iCharCntr = 0; iCharCntr < (int) strlen(cpTText); iCharCntr++)
00356 {
00357 if (FT_Load_Char(ftFace, cpTText[iCharCntr],
00358 FT_LOAD_RENDER|FT_LOAD_NO_HINTING) != 0)
00359 return false;
00360 if ((iCurXPos + ftFace->glyph->bitmap.width) > iTWidth)
00361 return true;
00362 for (iGYCntr = 0; iGYCntr < ftFace->glyph->bitmap.rows; iGYCntr++)
00363 {
00364 for (iGXCntr = 0; iGXCntr < ftFace->glyph->bitmap.width; iGXCntr++)
00365 {
00366 iPixPos =
00367 (iTYPos + iGYCntr +
00368 (iPixFontSize - ftFace->glyph->bitmap_top)) *
00369 iTWidth + iCurXPos + iGXCntr + ftFace->glyph->bitmap_left;
00370 iPixPos *= 3;
00371 ucGPix = *(ftFace->glyph->bitmap.buffer +
00372 iGYCntr * ftFace->glyph->bitmap.pitch + iGXCntr);
00373 ucpFrame24[iPixPos++] -= ucGPix;
00374 ucpFrame24[iPixPos++] -= ucGPix;
00375 ucpFrame24[iPixPos] -= ucGPix;
00376 }
00377 }
00378 if (ftFace->glyph->bitmap.width == 0)
00379 {
00380 iCurXPos += (int) ((ftFace->glyph->advance.x >> 6) * dPointSize *
00381 FB_TIFF_RESOLUTION + 0.5);
00382 }
00383 else
00384 {
00385 iCurXPos +=
00386 ftFace->glyph->bitmap.width + ftFace->glyph->bitmap_left + 2;
00387 }
00388 }
00389 return true;
00390 }
00391
00392
00393 clFrameBuf::clFrameBuf()
00394 {
00395 double dPhysFontSize;
00396
00397 bSaving = false;
00398 iType = FB_TYPE_NONE;
00399 iWidth = 0;
00400 iHeight = 0;
00401 iCurPos = 0;
00402 upFrameBuf = NULL;
00403 upScanBuf = NULL;
00404 if (FT_Init_FreeType(&ftLib) != 0)
00405 {
00406 fprintf(stderr, "clFrameBuf::clFrameBuf(): FT_Init_FreeType()\n");
00407 return;
00408 }
00409 if (FT_New_Face(ftLib, "fbfont.ttf", 0, &ftFace) != 0)
00410 {
00411 fprintf(stderr, "clFrameBuf::clFrameBuf(): FT_New_Face()\n");
00412 return;
00413 }
00414 if (!(ftFace->face_flags & FT_FACE_FLAG_SCALABLE))
00415 {
00416 fprintf(stderr, "clFrameBuf::clFrameBuf(): !FT_FACE_FLAG_SCALABLE\n");
00417 }
00418 if (FT_Set_Char_Size(ftFace, 0 * 64, FB_TIFF_FONTSIZE * 64,
00419 FB_TIFF_RESOLUTION, FB_TIFF_RESOLUTION) != 0)
00420 {
00421 fprintf(stderr, "clFrameBuf::clFrameBuf(): FT_Set_Char_Size()\n");
00422 return;
00423 }
00424 dPhysFontSize = 1.0 / 72.0 * FB_TIFF_FONTSIZE;
00425 iPixFontSize = (int) ceil(dPhysFontSize * FB_TIFF_RESOLUTION);
00426 iMaxFontWidth = (int) ftFace->size->metrics.x_ppem;
00427 }
00428
00429
00430 clFrameBuf::~clFrameBuf()
00431 {
00432 if (bSaving) StopSaveToFile();
00433 FT_Done_Face(ftFace);
00434 FT_Done_FreeType(ftLib);
00435 }
00436
00437
00438 void clFrameBuf::SetSize(int iReqWidth, int iReqHeight)
00439 {
00440 int iFBSize;
00441 int iScanSize;
00442
00443 iFBSize = iReqWidth * iReqHeight * 2 * sizeof(unsigned int);
00444 switch (iType)
00445 {
00446 case FB_TYPE_LINE:
00447 iScanSize = iReqWidth * sizeof(uint32);
00448 break;
00449 case FB_TYPE_COLUMN:
00450 iScanSize = iReqHeight * sizeof(uint32);
00451 break;
00452 case FB_TYPE_NONE:
00453 default:
00454 iScanSize =
00455 ((iReqWidth >= iReqHeight) ? iReqWidth : iReqHeight) *
00456 sizeof(uint32);
00457 }
00458 upFrameBuf = (unsigned int *) FrameBuf.Resize(iFBSize);
00459 upScanBuf = (uint32 *) ScanBuf.Size(iScanSize);
00460 iWidth = iReqWidth;
00461 iHeight = iReqHeight;
00462 if (iType == FB_TYPE_LINE && iCurPos >= iHeight) iCurPos = iHeight - 1;
00463 if (iType == FB_TYPE_COLUMN && iCurPos >= iWidth) iCurPos = 0;
00464 }
00465
00466
00467 void clFrameBuf::Clear()
00468 {
00469 int iPixCount;
00470 int iPixCntr;
00471
00472 iPixCount = iWidth * iHeight * 2;
00473 for (iPixCntr = 0; iPixCntr < iPixCount; iPixCntr++)
00474 {
00475 upFrameBuf[iPixCntr] = 0;
00476 }
00477 }
00478
00479
00480 guchar *clFrameBuf::GetCurPtr(int iXPos, int iYPos)
00481 {
00482 int iPixIdx;
00483
00484 if (iType == FB_TYPE_LINE)
00485 {
00486 iPixIdx = (iCurPos + iYPos) * iWidth + iXPos;
00487 return (guchar *) (&upFrameBuf[iPixIdx]);
00488 }
00489 else if (iType == FB_TYPE_COLUMN)
00490 {
00491 iPixIdx = iYPos * iWidth + iCurPos + iXPos;
00492 return (guchar *) (&upFrameBuf[iPixIdx]);
00493 }
00494 else return (guchar *) (&upFrameBuf[iYPos * iWidth + iXPos]);
00495 }
00496
00497
00498 void clFrameBuf::DrawLine(unsigned int *upLineBuf)
00499 {
00500 int iPixCntr;
00501 int iPixIdx1;
00502 int iPixIdx2;
00503
00504 if (iType != FB_TYPE_LINE)
00505 {
00506 iCurPos = iHeight;
00507 iType = FB_TYPE_LINE;
00508 }
00509 iCurPos--;
00510 if (iCurPos < 0) iCurPos = iHeight - 1;
00511 iPixIdx1 = iCurPos * iWidth;
00512 iPixIdx2 = iWidth * iHeight + iPixIdx1;
00513 for (iPixCntr = 0; iPixCntr < iWidth; iPixCntr++)
00514 {
00515 upFrameBuf[iPixIdx1] = upFrameBuf[iPixIdx2] = upScanBuf[iPixCntr] =
00516 upPalette[upLineBuf[iPixCntr]];
00517 iPixIdx1++;
00518 iPixIdx2++;
00519 }
00520 if (bSaving) WriteTiffScanData();
00521 }
00522
00523
00524 void clFrameBuf::DrawLine(GDT *fpDataBuf)
00525 {
00526 int iPixCntr;
00527 int iPixIdx1;
00528 int iPixIdx2;
00529 int iPalIdx;
00530
00531 if (iType != FB_TYPE_LINE)
00532 {
00533 iCurPos = iHeight;
00534 iType = FB_TYPE_LINE;
00535 }
00536 iCurPos--;
00537 if (iCurPos < 0) iCurPos = iHeight - 1;
00538 iPixIdx1 = iCurPos * iWidth;
00539 iPixIdx2 = iWidth * iHeight + iPixIdx1;
00540 for (iPixCntr = 0; iPixCntr < iWidth; iPixCntr++)
00541 {
00542 iPalIdx = (int) (fpDataBuf[iPixCntr] *
00543 (GDT) (iPalSize - 1) + (GDT) 0.5);
00544 if (iPalIdx < 0) iPalIdx = 0;
00545 if (iPalIdx >= iPalSize) iPalIdx = iPalSize - 1;
00546 upFrameBuf[iPixIdx1] = upFrameBuf[iPixIdx2] = upScanBuf[iPixCntr] =
00547 upPalette[iPalIdx];
00548 iPixIdx1++;
00549 iPixIdx2++;
00550 }
00551 if (bSaving) WriteTiffScanData();
00552 }
00553
00554
00555 void clFrameBuf::DrawColumn(unsigned int *upColumnBuf)
00556 {
00557 int iPixCntr;
00558 int iPixIdx1;
00559 int iPixIdx2;
00560
00561 if (iType != FB_TYPE_COLUMN)
00562 {
00563 iCurPos = 0;
00564 iType = FB_TYPE_COLUMN;
00565 }
00566 if (iCurPos >= iWidth) iCurPos = 0;
00567 iPixIdx1 = iCurPos;
00568 iPixIdx2 = iWidth * iHeight + iPixIdx1;
00569 for (iPixCntr = 0; iPixCntr < iHeight; iPixCntr++)
00570 {
00571 upFrameBuf[iPixIdx1] = upFrameBuf[iPixIdx2] = upScanBuf[iPixCntr] =
00572 upPalette[upColumnBuf[iPixCntr]];
00573 iPixIdx1 += iWidth;
00574 iPixIdx2 += iWidth;
00575 }
00576 iCurPos++;
00577 if (bSaving) WriteTiffScanData();
00578 }
00579
00580
00581 void clFrameBuf::DrawColumn(GDT *fpDataBuf)
00582 {
00583 int iPixCntr;
00584 int iPixIdx1;
00585 int iPixIdx2;
00586 int iPalIdx;
00587
00588 if (iType != FB_TYPE_COLUMN)
00589 {
00590 iCurPos = 0;
00591 iType = FB_TYPE_COLUMN;
00592 }
00593 if (iCurPos >= iWidth) iCurPos = 0;
00594 iPixIdx1 = iCurPos;
00595 iPixIdx2 = iWidth * iHeight + iPixIdx1;
00596 for (iPixCntr = 0; iPixCntr < iHeight; iPixCntr++)
00597 {
00598 iPalIdx = (int) (fpDataBuf[iHeight - 1 - iPixCntr] *
00599 (GDT) (iPalSize - 1) + (GDT) 0.5);
00600 if (iPalIdx < 0) iPalIdx = 0;
00601 if (iPalIdx >= iPalSize) iPalIdx = iPalSize - 1;
00602 upFrameBuf[iPixIdx1] = upFrameBuf[iPixIdx2] = upScanBuf[iPixCntr] =
00603 upPalette[iPalIdx];
00604 iPixIdx1 += iWidth;
00605 iPixIdx2 += iWidth;
00606 }
00607 iCurPos++;
00608 if (bSaving) WriteTiffScanData();
00609 }
00610
00611
00612 bool clFrameBuf::SaveToFile(const char *cpFileName, int iCompression,
00613 int iJPEGQuality, const char *cpDescription)
00614 {
00615 bool bRetVal = true;
00616
00617 if (bSaving) return false;
00618 tiffImg = TIFFOpen(cpFileName, FB_TIFF_MODE);
00619 if (tiffImg == NULL) return false;
00620 if (SetTiffTags(cpFileName, iCompression, iJPEGQuality, cpDescription,
00621 FB_TIFF_CONT_NO, iWidth, iHeight))
00622 {
00623 if (!WriteTiffData())
00624 bRetVal = false;
00625 }
00626 else bRetVal = false;
00627 TIFFClose(tiffImg);
00628 return bRetVal;
00629 }
00630
00631
00632 bool clFrameBuf::SaveToFile(const char *cpFileName, int iCompression,
00633 int iJPEGQuality, const char *cpDescription,
00634 double dXMin, double dXMax, double dYMin, double dYMax)
00635 {
00636 bool bRetVal = true;
00637 int iLeftMargin;
00638 int iBottomMargin;
00639
00640
00641 iLeftMargin = iMaxFontWidth * 8 + iPixFontSize;
00642 iBottomMargin = iPixFontSize * 4;
00643
00644 if (bSaving) return false;
00645 tiffImg = TIFFOpen(cpFileName, FB_TIFF_MODE);
00646 if (tiffImg == NULL) return false;
00647 if (SetTiffTags(cpFileName, iCompression, iJPEGQuality, cpDescription,
00648 FB_TIFF_CONT_NO, iWidth + iLeftMargin, iHeight + iBottomMargin))
00649 {
00650 if (!WriteTiffData(iLeftMargin, iBottomMargin,
00651 dXMin, dXMax, dYMin, dYMax))
00652 bRetVal = false;
00653 }
00654 else bRetVal = false;
00655 TIFFClose(tiffImg);
00656 return bRetVal;
00657 }
00658
00659
00660 bool clFrameBuf::StartSaveToFile(const char *cpFileName, int iCompression,
00661 int iJPEGQuality, const char *cpDescription, int iDirection)
00662 {
00663 tiffImg = TIFFOpen(cpFileName, FB_TIFF_MODE);
00664 if (tiffImg == NULL) return false;
00665 if (!SetTiffTags(cpFileName, iCompression, iJPEGQuality, cpDescription,
00666 iDirection, iWidth, iHeight))
00667 {
00668 return false;
00669 }
00670 uiContStrip = 0;
00671 bSaving = true;
00672 return true;
00673 }
00674
00675
00676 void clFrameBuf::StopSaveToFile()
00677 {
00678 bSaving = false;
00679 if (tiffImg != NULL) TIFFClose(tiffImg);
00680 }