1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114
|
/*****************************************************************************\
job.cpp : Implimentation for the Job class
Copyright (c) 1996 - 2015, HP Co.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of HP nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*****************************************************************************/
#include "header.h"
#include "halftoner.h"
#include "colormatch.h"
#include "scaler_open.h"
#include "scaler_prop.h"
APDK_BEGIN_NAMESPACE
extern Halftoner* Create_Halftoner( SystemServices* pSys, PrintMode* pPM,
unsigned int iInputWidth, unsigned int iNumRows[], unsigned int HiResFactor,
BOOL usematrix);
extern Scaler* Create_Scaler(SystemServices* pSys,int inputwidth,
int numerator,int denominator,BOOL vip,unsigned int BytesPerPixel);
extern ColorMatcher* Create_ColorMatcher( SystemServices* pSys,
ColorMap cm,unsigned int DyeCount,
unsigned int iInputWidth);
extern BOOL ProprietaryImaging();
extern BOOL ProprietaryScaling();
APDK_END_NAMESPACE
APDK_BEGIN_NAMESPACE
extern float frac(float f);
#define InitialPixelSize 3 // means first data into pipeline is RGB24
#define Bytes(x) ((x/8)+(x%8))
//////////////////////////////////////////////////////////////////////////
// The Job object receives data for a contiguous set of pages targeted at
// a single printer, with a single group of settings encapsulated in the
// PrintContext.
// At least one page will be ejected for a job, if any data at all
// is printed (no half-page jobs). If settings are to be changed, this
// must be done between jobs.
//
/*!
constructor - must pass a valid PrintContext to create the job.
Check constructor_error for NO_ERROR before continuing.
*/
Job::Job
(
PrintContext* pPC
) :
thePrintContext(pPC),
pSS(pPC->pSS),
thePrinter(NULL),
thePipeline(NULL),
pText(NULL),
pSender(NULL),
pHalftoner(NULL),
pColorMatcher(NULL),
pResSynth(NULL),
pBlackPlaneReplicator(NULL),
pReplicator(NULL),
theCompressor(NULL),
pBlackPlaneCompressor(NULL),
pHead(NULL),
#if defined(APDK_VIP_COLORFILTERING)
pErnie(NULL),
#endif
#if defined(APDK_FONTS_NEEDED)
theTextManager(NULL),
#endif
CurrentMode(pPC->CurrentMode),
fcount(0),
skipcount(0),
RowsInput(0),
BlankRaster(NULL),
BlackRaster(NULL),
DataSent(FALSE)
#ifdef APDK_USAGE_LOG
, UText(0),
UTextCount(0)
#endif
{
#ifdef APDK_CAPTURE
Capture_Job(pPC);
#endif
unsigned int i;
constructor_error = NO_ERROR;
if (!thePrintContext->PrinterSelected())
{
constructor_error = NO_PRINTER_SELECTED;
return;
}
thePrinter = thePrintContext->thePrinter;
for (i=0; i<(unsigned)MAXCOLORPLANES; i++)
if (CurrentMode->MixedRes) // means res(K) !+ res(C,M,Y)
numrows[i] = CurrentMode->ResolutionX[i] / CurrentMode->BaseResX;
else numrows[i]=1;
ResBoost = CurrentMode->BaseResX / CurrentMode->BaseResY;
if (ResBoost==0) ResBoost=1; // safety
pHead = thePrinter->SelectHeader(thePrintContext);
CNEWCHECK(pHead);
// set up blank raster used by SendRasters
constructor_error=setblankraster();
CERRCHECK;
// flush any garbage out of the printer's buffer
constructor_error=thePrinter->Flush();
CERRCHECK;
// send the PCL header
constructor_error=pHead->Send();
CERRCHECK;
// set CAPy after sending header in case header used it
CAPy=pHead->CAPy;
constructor_error=Configure();
CERRCHECK;
#if defined(APDK_FONTS_NEEDED)
pText = new TextTranslator(thePrinter, pHead->QualityCode(),
thePrintContext->CurrentMode->dyeCount);
CNEWCHECK(pText);
theTextManager = NULL;
if (CurrentMode->bFontCapable)
{
unsigned int pixelsX = (unsigned int) (int) (thePrintContext->printablewidth() *
CurrentMode->BaseResX);
unsigned int pixelsY = (unsigned int) (int) (thePrintContext->printableheight() *
CurrentMode->BaseResY);
theTextManager=new TextManager( pText, pixelsX,pixelsY );
CNEWCHECK(theTextManager);
constructor_error = theTextManager->constructor_error;
CERRCHECK;
}
#endif
if (!thePrintContext->ModeAgreesWithHardware(TRUE))
constructor_error = WARN_MODE_MISMATCH;
#ifdef APDK_USAGE_LOG
UHeader[0]='\0';
#endif
} //Job
DRIVER_ERROR Job::SetupHalftoning(HALFTONING_ALGORITHM eHT)
// Subroutine of Job constructor to handle ColorMatcher/Halftoner initialization.
// OutputWidth set in InitScaler (it is not the ultimate width if horizontal doubling is needed)
// Has to decide whether to use matrix or fast-error-diffusion, open or proprietary.
{
// first level of decision on matrix-vs.FED is the printmode setting itself
BOOL usematrix = (eHT == MATRIX);
// but this is overridden in speed-optimized builds
// we also can simulate the build-switch at runtime in the test harness
#ifdef APDK_OPTIMIZE_FOR_SPEED
usematrix = TRUE;
#endif
pHalftoner = Create_Halftoner(thePrintContext->pSS, CurrentMode,
OutputWidth, numrows,ResBoost,usematrix);
NEWCHECK(pHalftoner);
return pHalftoner->constructor_error;
} //SetupHalftoning
DRIVER_ERROR Job::SetupColorMatching()
{
unsigned int cmWidth=InputWidth;
if (pResSynth) // if 2X scaling happens before ColorMatching
cmWidth *= 2;
pColorMatcher = Create_ColorMatcher(thePrintContext->pSS, CurrentMode->cmap,
CurrentMode->dyeCount, cmWidth);
NEWCHECK(pColorMatcher);
return pColorMatcher->constructor_error;
} //SetupColorMatching
Job::~Job()
{
#ifdef APDK_CAPTURE
Capture_dJob();
#endif
// Client isn't required to call NewPage at end of last page, so
// we may need to eject a page now.
if (DataSent)
{
MediaSource mSource = thePrintContext->GetMediaSource ();
if (mSource == sourceBanner)
{
thePrintContext->SetMediaSource (sourceTrayAuto);
}
newpage();
thePrintContext->SetMediaSource (mSource);
}
// Tell printer that job is over.
if(pHead)
{
pHead->EndJob();
}//end if
// Delete the 4 components created in Job constructor.
#if defined(APDK_FONTS_NEEDED)
DBG1("deleting TextManager\n");
if (theTextManager)
{
delete theTextManager;
}
#endif
DBG1("deleting RasterSender\n");
if (pSender)
{
delete pSender;
}
if (pHalftoner)
{
delete pHalftoner;
}
if (pColorMatcher)
{
delete pColorMatcher;
}
if (BlankRaster)
{
pSS->FreeMemory(BlankRaster);
}
if (BlackRaster)
{
pSS->FreeMemory(BlackRaster);
}
if (pBlackPlaneReplicator)
{
delete pBlackPlaneReplicator;
}
if (pReplicator)
{
delete pReplicator;
}
if (pResSynth)
{
delete pResSynth;
}
if (thePipeline)
{
delete thePipeline;
}
if (pHead)
{
delete pHead;
}
#if defined(APDK_VIP_COLORFILTERING)
if (pErnie)
{
delete pErnie;
}
#endif
if (theCompressor)
{
delete theCompressor;
}
if (pBlackPlaneCompressor)
{
delete pBlackPlaneCompressor;
}
#if defined(APDK_FONTS_NEEDED)
if (pText)
{
delete pText;
}
#endif // defined(APDK_FONTS_NEEDED)
if(thePrinter)
{
BYTE temp = 0;
thePrinter->EndJob = TRUE; // the Job is done -
thePrinter->Send(&temp,0); // call Send to dump any buffered data
}//end if
DBG1("done with ~Job\n");
} //~Job
DRIVER_ERROR Job::SendCAPy()
{
return pHead->SendCAPy(CAPy++);
} //SendCAPy
///////////////////////////////////////////////////////////////////////////////////
//
/*!
This is the fundamental method for the driver, by means of which graphics data
is sent to the printer.
*/
DRIVER_ERROR Job::SendRasters(BYTE* ImageData) // RGB24 data for one raster
// This is how graphical data is sent to the driver.
// We do not check for rasters where data is supplied but happens
// to be all blank (white); caller should have used NULL in this case.
{
#ifdef APDK_CAPTURE
Capture_SendRasters(NULL, ImageData);
#endif
return sendrasters(NULL, ImageData);
} //SendRasters
///////////////////////////////////////////////////////////////////////////////////
//
/*!
This is the fundamental method for the driver, by means of which graphics data
is sent to the printer.
*/
DRIVER_ERROR Job::SendRasters(BYTE* BlackImageData, BYTE* ColorImageData) // 1bit K data and RGB24 data for one raster
// This is how graphical data is sent to the driver.
// We do not check for rasters where data is supplied but happens
// to be all blank (white); caller should have used NULL in this case.
{
#ifdef APDK_CAPTURE
Capture_SendRasters(BlackImageData, ColorImageData);
#endif
return sendrasters(BlackImageData, ColorImageData);
} //SendRasters
/*!
This is the method for use to check if they can send a separate 1 bit black channel
*/
DRIVER_ERROR Job::SupportSeparateBlack(BOOL* bSeparateBlack)
{
*bSeparateBlack = thePrinter->SupportSeparateBlack(CurrentMode);
return NO_ERROR;
}
// internal entry point, used by newpage
DRIVER_ERROR Job::sendrasters(BYTE* BlackImageData, BYTE* ColorImageData)
{
DRIVER_ERROR err = NO_ERROR;
if (thePipeline == NULL)
{
return SYSTEM_ERROR;
}
// need to put out some data occasionally in case of all-text page,
// so printer will go ahead and start printing the text before end of page
if (BlackImageData == NULL && ColorImageData == NULL)
{
if (thePrinter->GetDataFormat() == RASTER_STRIP)
{
skipcount=0;
ColorImageData=BlankRaster;
}
else
{
skipcount++;
if (skipcount >= 200)
{
skipcount=0;
ColorImageData=BlankRaster;
}
else
{
fcount += ScaleFactor;
}
err = thePipeline->Flush();
ERRCHECK;
}
}
else
{
skipcount=0;
DataSent=TRUE; // so we know we need a formfeed when job ends
}
RowsInput++; // needed in case res > 300
if (BlackImageData || ColorImageData)
{
if (fcount > 1000)
{
CAPy += fcount/1000;
err = thePrinter->SkipRasters ((fcount / 1000)); // needed for DJ3320
ERRCHECK;
fcount =fcount % 1000;
}
if (BlackImageData && CurrentMode->dyeCount != 3 && CurrentMode->dyeCount != 6)
{
err = setblackraster();
ERRCHECK;
for (unsigned int i = 0; i < thePrintContext->InputWidth / 8; i++)
{
unsigned char bitflag = 0x80;
for (unsigned int j = 0; j < 8; j++)
{
if (BlackImageData[i] & bitflag)
BlackRaster[i*8+j] = 1;
bitflag = bitflag >> 1;
}
}
if (thePrintContext->InputWidth % 8 > 0)
{
unsigned int i = thePrintContext->InputWidth / 8;
unsigned char bitflag = 0x80;
for (unsigned int j = 0; j < thePrintContext->InputWidth % 8; j++)
{
if (BlackImageData[i] & bitflag)
BlackRaster[i*8+j] = 1;
bitflag = bitflag >> 1;
}
}
thePipeline->Exec->raster.rastersize[COLORTYPE_BLACK] = thePrintContext->InputWidth;
thePipeline->Exec->raster.rasterdata[COLORTYPE_BLACK] = BlackRaster;
}
else
{
thePipeline->Exec->raster.rastersize[COLORTYPE_BLACK] = 0;
thePipeline->Exec->raster.rasterdata[COLORTYPE_BLACK] = NULL;
}
if (ColorImageData)
{
thePipeline->Exec->raster.rastersize[COLORTYPE_COLOR] = thePrintContext->InputWidth*3;
thePipeline->Exec->raster.rasterdata[COLORTYPE_COLOR] = ColorImageData;
}
else
{
thePipeline->Exec->raster.rastersize[COLORTYPE_COLOR] = 0;
thePipeline->Exec->raster.rasterdata[COLORTYPE_COLOR] = NULL;
}
err = thePipeline->Execute(&(thePipeline->Exec->raster));
}
return err;
} //sendrasters
DRIVER_ERROR Job::newpage()
// (for internal use, called by external NewPage)
{
DRIVER_ERROR err;
if (thePrinter->GetDataFormat() == RASTER_STRIP)
{
pHead->SetLastBand(TRUE);
}
sendrasters(); // flush pipeline
if ((thePrintContext->GetMediaSource ()) == sourceBanner)
{
CAPy = 0;
}
else
{
err = pHead->FormFeed();
ERRCHECK;
// reset vertical cursor counter
if (thePrinter->UseGUIMode(thePrintContext->CurrentMode) &&
((int) (thePrintContext->PrintableStartY () * 100)) != 0)
// DJ895 in GUImode doesn't accept top-margin setting, so we use CAP for topmargin
// Start at the top for full-bleed printing - PhotoSmart 100 for now
{
CAPy = thePrintContext->GUITopMargin();
}
else
{
CAPy = 0;
}
}
skipcount = RowsInput = 0;
fcount = 0;
// reset flag used to see if formfeed needed
DataSent = FALSE;
if (!thePrintContext->ModeAgreesWithHardware(TRUE))
{
return WARN_MODE_MISMATCH;
}
#ifdef APDK_USAGE_LOG
theTranslator->PrintDotCount(UHeader);
theTranslator->NextPage();
UTextCount=UText=0;
#endif
return NO_ERROR;
} //newpage
/*!
This method forces the associated printer to flush the remaining buffered
data and tells it that the job is ended.
Calling this method is not mandatory, since the object destructor already
performs this action. It may be required, however, if the destructor is not
called for some reason (for instance, when the call depends on the execution
of a "finalize" method of a Java wrapper.
*/
DRIVER_ERROR Job::Flush()
{
if(thePrinter)
{
BYTE temp = 0;
thePrinter->EndJob = TRUE; // the Job is done -
return thePrinter->Send(&temp,0); // call Send to dump any buffered data
}//end if
return NO_PRINTER_SELECTED;
}
/*!
Resets counters, flushes buffers, and sends a form feed to the printer.
*/
DRIVER_ERROR Job::NewPage()
// External entry point
{
#ifdef APDK_CAPTURE
Capture_NewPage();
#endif
return newpage();
} //NewPage
void Job::SetOutputWidth()
// set OutputWidth -- this is local and may not agree with PrintContext
// in cases where horizontal doubling is needed
{
OutputWidth = thePrintContext->OutputWidth;
InputWidth = thePrintContext->InputWidth;
if (CurrentMode->BaseResX != CurrentMode->BaseResY) // if horizontal expansion needed
{
int mixedfactor = CurrentMode->BaseResX / CurrentMode->BaseResY;
int widthfactor = OutputWidth / InputWidth;
if (widthfactor >= mixedfactor)
{
OutputWidth = OutputWidth / mixedfactor;
}
}
} //SetOutputWidth
DRIVER_ERROR Job::InitScaler()
// sets pResSynth & pReplicator
{
unsigned int numerator, denominator;
// set OutputWidth -- this is local and may not agree with PrintContext
// in cases where horizontal doubling is needed (see next if clause)
SetOutputWidth();
if ((OutputWidth % InputWidth) == 0)
{
numerator = OutputWidth / InputWidth;
denominator = 1;
}
else
{
numerator = OutputWidth;
denominator = InputWidth;
}
float tempfactor = (float)numerator / (float)denominator;
tempfactor *= 1000.0f;
ScaleFactor = (unsigned int) (int) tempfactor;
// Two paths: if ResSynth included (proprietary path), then use it for the first doubling;
// otherwise do it all in PixelReplication phase
// but don't use ResSynth anyway if printer-res=600 and scale<4 (i.e. original-res<150),
// or printer-res=300 and scale<2.33 (i.e. original-res<133)
BOOL RSok;
BOOL speedy=FALSE;
#ifdef APDK_OPTIMIZE_FOR_SPEED
speedy = TRUE;
#endif // APDK_OPTIMIZE_FOR_SPEED
if (speedy)
{
RSok = FALSE;
}
else
{
if (thePrintContext->EffectiveResolutionX()>300)
{
// I don't know about 1200dpi, so I'm doing it this way
RSok = ScaleFactor >= 4000;
}
else
{
RSok = ScaleFactor >= 2333;
}
}
unsigned int ReplFormat; // how many bytes per pixel
if (CurrentMode->Config.bColorImage)
{
ReplFormat = CurrentMode->dyeCount; // dealing with colormatching output
}
else
{
ReplFormat = 3; // RGB only
}
BOOL vip = !CurrentMode->Config.bColorImage;
if ((!ProprietaryScaling()) || !RSok )
// everything happens at Replication phase; input may be KCMY (or K, CMY, etc.) or RGB
{
pResSynth=NULL;
pReplicator = new Scaler_Open(pSS,InputWidth,numerator,denominator,vip,ReplFormat);
NEWCHECK(pReplicator);
return pReplicator->constructor_error;
}
// Proprietary path and scalefactor>=2, so break it up into 2 parts
// first give ResSynth a factor of 2, which is all it really does anyway.
// Scaler_Prop only operates on RGB, so it doesn't need the last two parameters
pResSynth = Create_Scaler(pSS,InputWidth,2,1,
TRUE, // as if VIP since it is working on RGB only at this phase
3); // 3 bytes per pixel
NEWCHECK(pResSynth);
pResSynth->myplane = COLORTYPE_COLOR;
if (pResSynth->constructor_error != NO_ERROR)
{
return pResSynth->constructor_error;
}
pBlackPlaneReplicator = new Scaler_Open(pSS,InputWidth,2,1,FALSE,1);
NEWCHECK(pBlackPlaneReplicator);
pBlackPlaneReplicator->myplane = COLORTYPE_BLACK;
if (pBlackPlaneReplicator->constructor_error != NO_ERROR)
{
return pBlackPlaneReplicator->constructor_error;
}
// now replicate the rest of the way -- only half as much left
pReplicator = new Scaler_Open(pSS,2*InputWidth,numerator,2*denominator,vip,ReplFormat);
NEWCHECK(pReplicator);
return pReplicator->constructor_error;
} //InitScaler
DRIVER_ERROR Job::Configure()
// mode has been set -- now set up rasterwidths and pipeline
{
DRIVER_ERROR err;
Pipeline* p=NULL;
unsigned int width;
BOOL useRS=FALSE;
err = InitScaler(); // create pReplicator and maybe pResSynth
ERRCHECK;
if ((CurrentMode->Config.bResSynth) && ProprietaryScaling()
&& pResSynth) // pResSynth==NULL if no scaling required
{
p = new Pipeline(pBlackPlaneReplicator);
NEWCHECK(p);
if (thePipeline)
thePipeline->AddPhase(p);
else thePipeline=p;
p = new Pipeline(pResSynth);
NEWCHECK(p);
if (thePipeline)
thePipeline->AddPhase(p);
else thePipeline=p;
useRS=TRUE;
}
#if (defined(APDK_DJ9xxVIP) || defined(APDK_LJJETREADY)) && defined(APDK_VIP_COLORFILTERING)
if (CurrentMode->Config.bErnie)
{
// create Ernie (need pixelwidth for constructor)
if (p)
{
width = p->GetMaxOutputWidth(COLORTYPE_COLOR) / 3; // GetOutputWidth returns # of bytes
}
else
{
width = thePrintContext->InputWidth;
}
// calculate Ernie threshold value
//Normal: threshold = (resolution) * (0.0876) - 2
// roughly: image at original 300 implies threshold=24; 600=>48, 150=>12, 75=>6
// to get resolution of "original" image, divide target resolution by scalefactor
float scale = (float)thePrintContext->OutputWidth / (float)thePrintContext->InputWidth;
float original_res = ((float)thePrintContext->EffectiveResolutionX()) / scale;
if (useRS && (scale >= 2.0f))
{
// image already doubled by ResSynth so consider the resolution as of now
original_res *= 2.0f;
}
float fthreshold = original_res * 0.0876f;
int threshold = (int)fthreshold - 2;
pErnie = new TErnieFilter(width, eBGRPixelData, threshold);
p = new Pipeline(pErnie);
NEWCHECK(p);
if (thePipeline)
{
thePipeline->AddPhase(p);
}
else
{
thePipeline = p;
}
}
#endif //APDK_DJ9xxVIP && APDK_VIP_COLORFILTERING
if (CurrentMode->Config.bColorImage)
{
err = SetupColorMatching(); // create pColorMatcher
ERRCHECK;
p = new Pipeline(pColorMatcher);
NEWCHECK(p);
if (thePipeline)
{
thePipeline->AddPhase(p);
}
else
{
thePipeline = p;
}
}
if (CurrentMode->Config.bPixelReplicate)
{
// create Replicator
p = new Pipeline(pReplicator);
NEWCHECK(p);
if (thePipeline)
{
thePipeline->AddPhase(p);
}
else
{
thePipeline = p;
}
}
if (CurrentMode->Config.bColorImage)
{
err = SetupHalftoning(CurrentMode->Config.eHT); // create pHalftoner
ERRCHECK;
p = new Pipeline(pHalftoner);
NEWCHECK(p);
if (thePipeline)
{
thePipeline->AddPhase(p);
}
else
{
thePipeline = p;
}
}
if (CurrentMode->Config.bCompress)
{
if (p)
{
width = p->GetMaxOutputWidth(COLORTYPE_COLOR);
}
else
{
width = thePrintContext->InputWidth;
}
unsigned int SeedBufferSize;
if (pHalftoner) // if data is halftoned-output
{
// format is 1 bit-per-pixel for each ink,drop,pass
SeedBufferSize = MAXCOLORPLANES * MAXCOLORDEPTH * MAXCOLORROWS * width;
}
else // VIP data is just RGB24 here
{
SeedBufferSize = width;
}
theCompressor = thePrinter->CreateCompressor(SeedBufferSize);
NEWCHECK(theCompressor);
err = theCompressor->constructor_error;
ERRCHECK;
theCompressor->myplane = COLORTYPE_COLOR;
p = new Pipeline(theCompressor);
NEWCHECK(p);
if (thePipeline)
{
thePipeline->AddPhase(p);
}
else
{
thePipeline = p;
}
if (thePrinter->VIPPrinter())
{
width = (width/3+7)/8;
if (width > 0)
{
// VIP black data is 1 bit here
unsigned int SeedBufferSize;
SeedBufferSize = width;
pBlackPlaneCompressor = thePrinter->CreateBlackPlaneCompressor(SeedBufferSize, TRUE);
NEWCHECK(pBlackPlaneCompressor);
err = pBlackPlaneCompressor->constructor_error;
ERRCHECK;
pBlackPlaneCompressor->myplane = COLORTYPE_BLACK;
p = new Pipeline(pBlackPlaneCompressor);
NEWCHECK(p);
if (thePipeline)
{
thePipeline->AddPhase(p);
}
else
{
thePipeline = p;
}
}
}
}
// always end pipeline with RasterSender
// create RasterSender object
pSender = new RasterSender(thePrinter,thePrintContext,this,pHalftoner);
NEWCHECK(pSender);
err = pSender->constructor_error;
ERRCHECK;
p = new Pipeline(pSender);
if (thePipeline)
{
thePipeline->AddPhase(p);
}
else
{
thePipeline = p;
}
return NO_ERROR;
} //Configure
DRIVER_ERROR Job::setblankraster()
{
if (BlankRaster)
{
pSS->FreeMemory(BlankRaster);
}
size_t BlankRasterSize = thePrintContext->OutputWidth * 3; // Raghu
BlankRaster = (BYTE*)pSS->AllocMem (BlankRasterSize);
NEWCHECK(BlankRaster);
memset (BlankRaster, 0xFF, BlankRasterSize); // Raghu
return NO_ERROR;
} //setblankraster
DRIVER_ERROR Job::setblackraster()
{
size_t BlackRasterSize = thePrintContext->InputWidth;
if (!BlackRaster)
{
BlackRaster = (BYTE*)pSS->AllocMem (BlackRasterSize);
NEWCHECK(BlackRaster);
}
memset (BlackRaster, 0, BlackRasterSize);
return NO_ERROR;
} //setblankraster
//////////////////////////////////////////////////////////////////////
#if defined(APDK_FONTS_NEEDED)
/*!
This method is used to send ASCII data to the printer, which it will render
as determined by the Font object.
*/
DRIVER_ERROR Job::TextOut
(
const char* pTextString,
unsigned int iLenString,
const Font& font,
int iAbsX,
int iAbsY
)
// This is how ASCII data is sent to the driver.
// Everything is really handled by the TextManager, including error checking.
{
#ifdef APDK_CAPTURE
Capture_TextOut(pTextString, iLenString, font, iAbsX, iAbsY);
#endif
// Map coordinates (assumed to be in the graphical space) to the text-placement grid,
// which may be of lower resolution, indicated by TextRes
//
// using floats to cover the unusual case where graphical res is lower than text
float xfactor = ((float)CurrentMode->BaseResX) / ((float)CurrentMode->TextRes);
float yfactor = ((float)CurrentMode->BaseResY) / ((float)CurrentMode->TextRes);
float x = (float)iAbsX / xfactor;
float y = (float)iAbsY / yfactor;
iAbsX = (unsigned int)(int)x; // double cast for webtv compiler
iAbsY = (unsigned int)(int)y;
DRIVER_ERROR err = theTextManager->TextOut(pTextString,iLenString,font,iAbsX,iAbsY);
ERRCHECK;
DataSent=TRUE;
#ifdef APDK_USAGE_LOG
if (iLenString > UTextSize)
{
iLenString = UTextSize-1;
UHeader[iLenString] = '\0';
}
if (UTextCount<2)
{
strcpy(UHeader,pTextString);
UText += iLenString;
}
if (UTextCount==1)
{
UHeader[UText] = '\0';
}
UTextCount++;
#endif
return err;
} //TextOut
#endif
///////////////////////////////////////////////////////////
// Pipeline management
Pipeline::Pipeline
(
Processor* E
) :
next(NULL),
prev(NULL)
{
Exec = E;
Exec->myphase = this;
} //Pipeline
void Pipeline::AddPhase(Pipeline* newp)
{
Pipeline* p = this;
while (p->next)
{
p = p->next;
}
p->next = newp;
newp->prev = p;
} //AddPhase
Pipeline::~Pipeline()
{
if (next)
{
delete next;
}
} //~Pipeline
BOOL Pipeline::Process(RASTERDATA* raster)
{
return Exec->Process(raster);
} //Process
DRIVER_ERROR Pipeline::Execute(RASTERDATA* InputRaster)
{
err=NO_ERROR;
if (Process(InputRaster) // true if output ready; may set err
&& (err==NO_ERROR))
{
if (next)
{
next->Exec->raster.rasterdata[COLORTYPE_BLACK] = NextOutputRaster(COLORTYPE_BLACK);
next->Exec->raster.rasterdata[COLORTYPE_COLOR] = NextOutputRaster(COLORTYPE_COLOR);
while (next->Exec->raster.rasterdata[COLORTYPE_COLOR] ||
next->Exec->raster.rasterdata[COLORTYPE_BLACK])
{
next->Exec->raster.rastersize[COLORTYPE_COLOR] = GetOutputWidth(COLORTYPE_COLOR);
next->Exec->raster.rastersize[COLORTYPE_BLACK] = GetOutputWidth(COLORTYPE_BLACK);
err = next->Execute(&(next->Exec->raster));
ERRCHECK;
next->Exec->raster.rasterdata[COLORTYPE_BLACK] = NextOutputRaster(COLORTYPE_BLACK);
next->Exec->raster.rasterdata[COLORTYPE_COLOR] = NextOutputRaster(COLORTYPE_COLOR);
}
}
}
return err;
} //Execute
DRIVER_ERROR Pipeline::Flush()
{
err=NO_ERROR;
Exec->Flush();
if (next && (err == NO_ERROR))
{
next->Exec->raster.rasterdata[COLORTYPE_BLACK] = NextOutputRaster(COLORTYPE_BLACK);
next->Exec->raster.rasterdata[COLORTYPE_COLOR] = NextOutputRaster(COLORTYPE_COLOR);
while (next->Exec->raster.rasterdata[COLORTYPE_COLOR] || next->Exec->raster.rasterdata[COLORTYPE_BLACK])
{
next->Exec->raster.rastersize[COLORTYPE_BLACK] = GetOutputWidth(COLORTYPE_BLACK);
next->Exec->raster.rastersize[COLORTYPE_COLOR] = GetOutputWidth(COLORTYPE_COLOR);
err = next->Execute(&(next->Exec->raster));
next->Exec->raster.rasterdata[COLORTYPE_BLACK] = NextOutputRaster(COLORTYPE_BLACK);
next->Exec->raster.rasterdata[COLORTYPE_COLOR] = NextOutputRaster(COLORTYPE_COLOR);
ERRCHECK;
}
// one more to continue flushing downstream
err = next->Flush();
}
return err;
} //Flush
Processor::Processor() :
iRastersReady(0),
iRastersDelivered(0),
myphase(NULL),
myplane(COLORTYPE_BOTH)
{
for (int i = COLORTYPE_COLOR; i < MAX_COLORTYPE; i++)
{
raster.rasterdata[i] = NULL;
raster.rastersize[i] = 0;
}
} //Processor
Processor::~Processor()
{
} //~Processor
APDK_END_NAMESPACE
|