<<>> <> <> <> DIRECTORY Basics, Checksum, Imager, ImagerBackdoor, ImagerBitmapContext, ImagerBrick, ImagerMaskCache, ImagerPath, ImagerPixel, ImagerPixelArray, ImagerSample, ImagerTransformation, SF; ImagerSelfTestImpl: CEDAR PROGRAM IMPORTS Checksum, Imager, ImagerBackdoor, ImagerBitmapContext, ImagerMaskCache, ImagerPath, ImagerPixel, ImagerPixelArray, ImagerSample, ImagerTransformation ~ BEGIN SelfTestFailed: SIGNAL ~ CODE; nTests: NAT = 31; checksums: ARRAY [0..nTests) OF INT ¬ [0, 16065, 39594, 2142, 15076, 43569, 37361, 26459, 5570, 5602, 28378, 24833, 19088, 47172, 712, 48377, 1673, 56381, 38476, 18014, 0, 64182, 47451, 17930, 4914, 57252, 20195, 54074, 19979, 47113, 43438]; generate: BOOL ¬ FALSE; Check: PROC [bitmap: ImagerSample.RasterSampleMap, testNum: NAT] ~ TRUSTED { block: Basics.UnsafeBlock ~ ImagerSample.GetUnsafeBlock[map: bitmap]; zero: [0..0] ~ block.startIndex; chksum: CARD16 ~ Checksum.ComputeChecksum[0, block.count/2, block.base]; IF NOT generate AND CARD16[checksums[testNum]]#chksum THEN { SIGNAL SelfTestFailed; generate ¬ TRUE; }; IF generate THEN checksums[testNum] ¬ chksum; }; sizes: LIST OF NAT ¬ LIST[1, 2, 3, 5, 8, 13, 15, 16, 17, 23, 31, 32, 33, 50, 61, 62, 63, 101, 900]; th: LIST OF NAT ¬ LIST[254, 215, 100, 82, 172, 217, 138, 27, 9, 78, 161, 117, 29, 23, 128, 224, 211, 122, 89, 190, 250, 231, 125, 52, 113, 194, 162, 38, 0, 44, 145, 150, 56, 26, 97, 221, 234, 164, 91, 147, 237, 242, 139, 46, 62, 156, 181, 60, 3, 22, 132, 185, 106, 42, 81, 209, 248, 201, 103, 115, 213, 239, 172, 46, 34, 111, 174, 93, 13, 13, 101, 197, 168, 70, 71, 191, 254, 228, 132, 85, 178, 226, 188, 51, 16, 64, 151, 134, 32, 7, 76, 201, 206, 120, 75, 158, 245, 244, 154, 72, 121, 205, 199, 73, 6, 33, 136, 148, 62, 17, 54, 192, 227, 175, 86, 135, 229, 252, 186, 67, 68, 169, 197, 98, 11, 15, 96, 176, 108, 36, 49, 179, 240, 210, 115, 105, 203, 247, 207, 79, 38, 109, 183, 130, 19, 4, 65, 181, 155, 58, 48, 142, 243, 236, 146, 91, 166, 233, 221, 95, 24, 58, 153, 143, 42, 1, 40, 164, 195, 111, 55, 127, 232, 250, 187, 87, 124, 212, 223, 126, 21, 30, 119, 160, 77, 9, 28, 141, 217, 170, 84, 102, 219, 255, 215, 99, 83, 171, 216, 138, 26, 10, 79, 160, 117, 30, 23, 129, 225, 211, 123, 89, 189, 251, 230, 125, 52, 113, 193, 162, 37, 1, 44, 144, 150, 56, 25, 97, 222, 235, 165, 92, 148, 238, 241, 140, 45, 61, 157, 180, 60, 3, 21, 131, 184, 107, 41, 81, 208, 248, 202, 104, 116, 214, 238, 173, 47, 35, 110, 174, 93, 14, 12, 101, 198, 167, 69, 70, 191, 253, 229, 133, 85, 178, 225, 189, 50, 17, 64, 152, 134, 32, 7, 76, 200, 205, 119, 74, 158, 246, 244, 154, 72, 121, 204, 199, 74, 5, 34, 137, 149, 63, 18, 53, 193, 227, 176, 87, 136, 230, 252, 185, 66, 68, 168, 196, 99, 11, 15, 95, 177, 107, 36, 50, 179, 240, 209, 114, 105, 203, 246, 207, 80, 39, 109, 183, 130, 19, 5, 66, 182, 156, 59, 48, 142, 242, 236, 146, 90, 166, 234, 220, 94, 25, 57, 152, 144, 43, 2, 40, 163, 195, 112, 54, 128, 232, 249, 187, 88, 123, 213, 223, 127, 20, 31, 118, 159, 77, 8, 28, 140, 218, 170, 83, 103, 219]; MakePattern: PROC [box: SF.Box, bps: [0..16], init: LIST OF NAT] RETURNS [map: ImagerSample.RasterSampleMap] ~ { src: LIST OF NAT ¬ init; map ¬ ImagerSample.NewSampleMap[box: box, bitsPerSample: bps]; FOR s: INTEGER IN [box.min.s..box.max.s) DO FOR f: INTEGER IN [box.min.f..box.max.f) DO IF src = NIL THEN src ¬ init; ImagerSample.Put[map, [s, f], src.first]; src ¬ src.rest; ENDLOOP; ENDLOOP; }; Run: PROC ~ { bitmap: ImagerSample.RasterSampleMap ~ ImagerSample.NewSampleMap[box: [max: [200, 1280]], bitsPerSample: 1]; brick: ImagerBrick.Brick ~ [ maxSample: 255, sampleMap: MakePattern[box: [max: [1, 386]], bps: 8, init: th], phase: 305 ]; testNo: NAT ¬ 0; context: Imager.Context ¬ NIL; bpa: ImagerPixelArray.PixelArray ~ ImagerPixelArray.FromPixelMap[pixelMap: ImagerPixel.MakePixelMap[MakePattern[[max: [5, 3]], 1, LIST [1,1,1, 1,0,0, 1,0,0, 1,0,0, 1,0,0]]], box: [max: [5, 3]], scanMode: [slow: down, fast: right], immutable: TRUE]; ImagerSample.Clear[bitmap]; Check[bitmap, 0]; FOR each: LIST OF NAT ¬ sizes, each.rest UNTIL each = NIL DO fSize: NAT ~ each.first; FOR f: NAT IN [0..40) DO ImagerSample.Fill[map: bitmap, box: [[2*f, f], [2*f+5, f+fSize]], value: 1, function: [(SELECT f MOD 3 FROM 0 => null, 1 => or, 2 => xor, ENDCASE => ERROR), null]] ENDLOOP; Check[bitmap, testNo ¬ testNo + 1]; ENDLOOP; context ¬ ImagerBitmapContext.Create[deviceSpaceSize: [200, 1280], scanMode: [slow: down, fast: right], surfaceUnitsPerInch: [100, 100], pixelUnits: TRUE, fontCacheName: $Bitmap]; ImagerBitmapContext.SetBitmap[context: context, bitmap: bitmap]; ImagerBitmapContext.SetBrick[context: context, brick: brick]; Imager.SetGray[context, 0]; Imager.MaskRectangle[context, ImagerBackdoor.GetBounds[context]]; Imager.SetGray[context, 1]; Check[bitmap, testNo ¬ testNo + 1]; Imager.SetStrokeWidth[context, 4]; Imager.SetStrokeEnd[context, round]; Imager.MaskVector[context, [3, 3], [90, 197]]; Check[bitmap, testNo ¬ testNo + 1]; Imager.SetStrokeEnd[context, square]; Imager.MaskVector[context, [95, 197], [200, 3]]; Check[bitmap, testNo ¬ testNo + 1]; Imager.SetGray[context, 0.3]; Imager.MaskRectangle[context, [40, 80, 1000, 40]]; Check[bitmap, testNo ¬ testNo + 1]; Imager.SetGray[context, 0.7]; Imager.TranslateT[context, [100, 0]]; Imager.SetStrokeWidth[context, 8]; Imager.SetStrokeEnd[context, round]; Imager.MaskVector[context, [8, 8], [90, 192]]; Check[bitmap, testNo ¬ testNo + 1]; Imager.SetGray[context, 0.9]; Imager.SetStrokeEnd[context, square]; Imager.MaskVector[context, [95, 197], [200, 5]]; Check[bitmap, testNo ¬ testNo + 1]; FOR k: NAT IN [2..6] DO Imager.SetSampledBlack[context: context, pa: bpa, m: ImagerTransformation.Scale[k/3.0], clear: VAL[k MOD 2]]; Imager.MaskRectangle[context, [k*100, 60, 100, 100]]; Check[bitmap, testNo ¬ testNo + 1]; ENDLOOP; Imager.SetGray[context, 0.7]; Imager.MaskFillTrajectory[context: context, trajectory: ImagerPath.MoveTo[[50, 100]].ArcTo[[200, 100], [50, 100]], oddWrap: FALSE]; Imager.SetGray[context, 1]; Imager.MaskStrokeTrajectory[context: context, trajectory: ImagerPath.MoveTo[[50, 100]].ArcTo[[200, 100], [50, 100]], closed: TRUE]; ImagerMaskCache.FlushAll[]; testNo ¬ (testNo+testNo)/2; -- place to set breakpoint }; Run[]; END.