KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > render > afp > modca > ImageRasterPattern


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 /* $Id: ImageRasterPattern.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.render.afp.modca;
21
22 /**
23  * Raster data is a grid of cells covering an area of interest.
24  * Each pixel, the smallest unit of information in the grid, displays
25  * a unique attribute. This static class generates raster data for different
26  * shades of grey (betweeen 0 and 16) the lower the number being the
27  * darker the shade. The image data dimensions are 64 x 8.
28  */

29 public class ImageRasterPattern {
30
31     /**
32      * The Raster Pattern for Greyscale 16
33      */

34     private static final byte[] GREYSCALE16 = new byte[] {
35             0x00,
36             0x00,
37             0x00,
38             0x00,
39             0x00,
40             0x00,
41             0x00,
42             0x00,
43             0x00,
44             0x00,
45             0x00,
46             0x00,
47             0x00,
48             0x00,
49             0x00,
50             0x00,
51             0x00,
52             0x00,
53             0x00,
54             0x00,
55             0x00,
56             0x00,
57             0x00,
58             0x00,
59             0x00,
60             0x00,
61             0x00,
62             0x00,
63             0x00,
64             0x00,
65             0x00,
66             0x00,
67     };
68
69     /**
70      * The Raster Pattern for Greyscale 15
71      */

72     private static final byte[] GREYSCALE15 = new byte[] {
73             0x00,
74             0x00,
75             0x00,
76             0x00,
77             0x00,
78             0x00,
79             0x00,
80             0x00,
81             0x00,
82             0x00,
83             0x00,
84             0x00,
85             0x00,
86             0x00,
87             0x00,
88             0x00,
89             0x00,
90             0x00,
91             0x00,
92             0x00,
93             0x00,
94             0x00,
95             0x00,
96             0x00,
97             0x11,
98             0x11,
99             0x11,
100             0x11,
101             0x11,
102             0x11,
103             0x11,
104             0x11,
105     };
106
107     /**
108      * The Raster Pattern for Greyscale 14
109      */

110     private static final byte[] GREYSCALE14 = new byte[] {
111             0x00,
112             0x00,
113             0x00,
114             0x00,
115             0x00,
116             0x00,
117             0x00,
118             0x00,
119             0x11,
120             0x11,
121             0x11,
122             0x11,
123             0x11,
124             0x11,
125             0x11,
126             0x11,
127             0x00,
128             0x00,
129             0x00,
130             0x00,
131             0x00,
132             0x00,
133             0x00,
134             0x00,
135             0x44,
136             0x44,
137             0x44,
138             0x44,
139             0x44,
140             0x44,
141             0x44,
142             0x44,
143     };
144
145
146     /**
147      * The Raster Pattern for Greyscale 13
148      */

149     private static final byte[] GREYSCALE13 = new byte[] {
150             0x00,
151             0x00,
152             0x00,
153             0x00,
154             0x00,
155             0x00,
156             0x00,
157             0x00,
158             0x11,
159             0x11,
160             0x11,
161             0x11,
162             0x11,
163             0x11,
164             0x11,
165             0x11,
166             0x00,
167             0x00,
168             0x00,
169             0x00,
170             0x00,
171             0x00,
172             0x00,
173             0x00,
174             (byte)0xAA,
175             (byte)0xAA,
176             (byte)0xAA,
177             (byte)0xAA,
178             (byte)0xAA,
179             (byte)0xAA,
180             (byte)0xAA,
181             (byte)0xAA,
182     };
183
184     /**
185      * The Raster Pattern for Greyscale 12
186      */

187     private static final byte[] GREYSCALE12 = new byte[] {
188             0x00,
189             0x00,
190             0x00,
191             0x00,
192             0x00,
193             0x00,
194             0x00,
195             0x00,
196             0x55,
197             0x55,
198             0x55,
199             0x55,
200             0x55,
201             0x55,
202             0x55,
203             0x55,
204             0x00,
205             0x00,
206             0x00,
207             0x00,
208             0x00,
209             0x00,
210             0x00,
211             0x00,
212             (byte)0xAA,
213             (byte)0xAA,
214             (byte)0xAA,
215             (byte)0xAA,
216             (byte)0xAA,
217             (byte)0xAA,
218             (byte)0xAA,
219             (byte)0xAA,
220     };
221
222     /**
223      * The Raster Pattern for Greyscale 11
224      */

225     private static final byte[] GREYSCALE11 = new byte[] {
226             0x11,
227             0x11,
228             0x11,
229             0x11,
230             0x11,
231             0x11,
232             0x11,
233             0x11,
234             0x44,
235             0x44,
236             0x44,
237             0x44,
238             0x44,
239             0x44,
240             0x44,
241             0x44,
242             0x11,
243             0x11,
244             0x11,
245             0x11,
246             0x11,
247             0x11,
248             0x11,
249             0x11,
250             (byte)0xAA,
251             (byte)0xAA,
252             (byte)0xAA,
253             (byte)0xAA,
254             (byte)0xAA,
255             (byte)0xAA,
256             (byte)0xAA,
257             (byte)0xAA,
258     };
259
260     /**
261      * The Raster Pattern for Greyscale 10
262      */

263     private static final byte[] GREYSCALE10 = new byte[] {
264             0x11,
265             0x11,
266             0x11,
267             0x11,
268             0x11,
269             0x11,
270             0x11,
271             0x11,
272             (byte)0xAA,
273             (byte)0xAA,
274             (byte)0xAA,
275             (byte)0xAA,
276             (byte)0xAA,
277             (byte)0xAA,
278             (byte)0xAA,
279             (byte)0xAA,
280             0x44,
281             0x44,
282             0x44,
283             0x44,
284             0x44,
285             0x44,
286             0x44,
287             0x44,
288             (byte)0xAA,
289             (byte)0xAA,
290             (byte)0xAA,
291             (byte)0xAA,
292             (byte)0xAA,
293             (byte)0xAA,
294             (byte)0xAA,
295             (byte)0xAA,
296     };
297
298     /**
299      * The Raster Pattern for Greyscale 9
300      */

301     private static final byte[] GREYSCALE09 = new byte[] {
302             0x11,
303             0x11,
304             0x11,
305             0x11,
306             0x11,
307             0x11,
308             0x11,
309             0x11,
310             (byte)0xAA,
311             (byte)0xAA,
312             (byte)0xAA,
313             (byte)0xAA,
314             (byte)0xAA,
315             (byte)0xAA,
316             (byte)0xAA,
317             (byte)0xAA,
318             0x55,
319             0x55,
320             0x55,
321             0x55,
322             0x55,
323             0x55,
324             0x55,
325             0x55,
326             (byte)0xAA,
327             (byte)0xAA,
328             (byte)0xAA,
329             (byte)0xAA,
330             (byte)0xAA,
331             (byte)0xAA,
332             (byte)0xAA,
333             (byte)0xAA,
334     };
335
336     /**
337      * The Raster Pattern for Greyscale 8
338      */

339     private static final byte[] GREYSCALE08 = new byte[] {
340             (byte)0xAA,
341             (byte)0xAA,
342             (byte)0xAA,
343             (byte)0xAA,
344             (byte)0xAA,
345             (byte)0xAA,
346             (byte)0xAA,
347             (byte)0xAA,
348             (byte)0xAA,
349             (byte)0xAA,
350             (byte)0xAA,
351             (byte)0xAA,
352             (byte)0xAA,
353             (byte)0xAA,
354             (byte)0xAA,
355             (byte)0xAA,
356             (byte)0xAA,
357             (byte)0xAA,
358             (byte)0xAA,
359             (byte)0xAA,
360             (byte)0xAA,
361             (byte)0xAA,
362             (byte)0xAA,
363             (byte)0xAA,
364             (byte)0xAA,
365             (byte)0xAA,
366             (byte)0xAA,
367             (byte)0xAA,
368             (byte)0xAA,
369             (byte)0xAA,
370             (byte)0xAA,
371             (byte)0xAA,
372     };
373
374
375     /**
376      * The Raster Pattern for Greyscale 7
377      */

378     private static final byte[] GREYSCALE07 = new byte[] {
379             0x55,
380             0x55,
381             0x55,
382             0x55,
383             0x55,
384             0x55,
385             0x55,
386             0x55,
387             (byte)0xAA,
388             (byte)0xAA,
389             (byte)0xAA,
390             (byte)0xAA,
391             (byte)0xAA,
392             (byte)0xAA,
393             (byte)0xAA,
394             (byte)0xAA,
395             0x55,
396             0x55,
397             0x55,
398             0x55,
399             0x55,
400             0x55,
401             0x55,
402             0x55,
403             (byte)0xBB,
404             (byte)0xBB,
405             (byte)0xBB,
406             (byte)0xBB,
407             (byte)0xBB,
408             (byte)0xBB,
409             (byte)0xBB,
410             (byte)0xBB,
411     };
412
413
414     /**
415      * The Raster Pattern for Greyscale 6
416      */

417     private static final byte[] GREYSCALE06 = new byte[] {
418             0x55,
419             0x55,
420             0x55,
421             0x55,
422             0x55,
423             0x55,
424             0x55,
425             0x55,
426             (byte)0xBB,
427             (byte)0xBB,
428             (byte)0xBB,
429             (byte)0xBB,
430             (byte)0xBB,
431             (byte)0xBB,
432             (byte)0xBB,
433             (byte)0xBB,
434             0x55,
435             0x55,
436             0x55,
437             0x55,
438             0x55,
439             0x55,
440             0x55,
441             0x55,
442             (byte)0xEE,
443             (byte)0xEE,
444             (byte)0xEE,
445             (byte)0xEE,
446             (byte)0xEE,
447             (byte)0xEE,
448             (byte)0xEE,
449             (byte)0xEE,
450     };
451
452     /**
453      * The Raster Pattern for Greyscale 5
454      */

455     private static final byte[] GREYSCALE05 = new byte[] {
456             0x55,
457             0x55,
458             0x55,
459             0x55,
460             0x55,
461             0x55,
462             0x55,
463             0x55,
464             (byte)0xBB,
465             (byte)0xBB,
466             (byte)0xBB,
467             (byte)0xBB,
468             (byte)0xBB,
469             (byte)0xBB,
470             (byte)0xBB,
471             (byte)0xBB,
472             (byte)0xEE,
473             (byte)0xEE,
474             (byte)0xEE,
475             (byte)0xEE,
476             (byte)0xEE,
477             (byte)0xEE,
478             (byte)0xEE,
479             (byte)0xEE,
480             (byte)0xBB,
481             (byte)0xBB,
482             (byte)0xBB,
483             (byte)0xBB,
484             (byte)0xBB,
485             (byte)0xBB,
486             (byte)0xBB,
487             (byte)0xBB,
488     };
489
490
491     /**
492      * The Raster Pattern for Greyscale 4
493      */

494     private static final byte[] GREYSCALE04 = new byte[] {
495             0x55,
496             0x55,
497             0x55,
498             0x55,
499             0x55,
500             0x55,
501             0x55,
502             0x55,
503             (byte)0xFF,
504             (byte)0xFF,
505             (byte)0xFF,
506             (byte)0xFF,
507             (byte)0xFF,
508             (byte)0xFF,
509             (byte)0xFF,
510             (byte)0xFF,
511             (byte)0xAA,
512             (byte)0xAA,
513             (byte)0xAA,
514             (byte)0xAA,
515             (byte)0xAA,
516             (byte)0xAA,
517             (byte)0xAA,
518             (byte)0xAA,
519             (byte)0xFF,
520             (byte)0xFF,
521             (byte)0xFF,
522             (byte)0xFF,
523             (byte)0xFF,
524             (byte)0xFF,
525             (byte)0xFF,
526             (byte)0xFF,
527     };
528
529     /**
530      * The Raster Pattern for Greyscale 3
531      */

532     private static final byte[] GREYSCALE03 = new byte[] {
533             0x55,
534             0x55,
535             0x55,
536             0x55,
537             0x55,
538             0x55,
539             0x55,
540             0x55,
541             (byte)0xFF,
542             (byte)0xFF,
543             (byte)0xFF,
544             (byte)0xFF,
545             (byte)0xFF,
546             (byte)0xFF,
547             (byte)0xFF,
548             (byte)0xFF,
549             (byte)0xBB,
550             (byte)0xBB,
551             (byte)0xBB,
552             (byte)0xBB,
553             (byte)0xBB,
554             (byte)0xBB,
555             (byte)0xBB,
556             (byte)0xBB,
557             (byte)0xFF,
558             (byte)0xFF,
559             (byte)0xFF,
560             (byte)0xFF,
561             (byte)0xFF,
562             (byte)0xFF,
563             (byte)0xFF,
564             (byte)0xFF,
565     };
566
567     /**
568      * The Raster Pattern for Greyscale 2
569      */

570     private static final byte[] GREYSCALE02 = new byte[] {
571             0x77,
572             0x77,
573             0x77,
574             0x77,
575             0x77,
576             0x77,
577             0x77,
578             0x77,
579             (byte)0xFF,
580             (byte)0xFF,
581             (byte)0xFF,
582             (byte)0xFF,
583             (byte)0xFF,
584             (byte)0xFF,
585             (byte)0xFF,
586             (byte)0xFF,
587             (byte)0xDD,
588             (byte)0xDD,
589             (byte)0xDD,
590             (byte)0xDD,
591             (byte)0xDD,
592             (byte)0xDD,
593             (byte)0xDD,
594             (byte)0xDD,
595             (byte)0xFF,
596             (byte)0xFF,
597             (byte)0xFF,
598             (byte)0xFF,
599             (byte)0xFF,
600             (byte)0xFF,
601             (byte)0xFF,
602             (byte)0xFF,
603     };
604
605
606     /**
607      * The Raster Pattern for Greyscale 1
608      */

609     private static final byte[] GREYSCALE01 = new byte[] {
610             0x77,
611             0x77,
612             0x77,
613             0x77,
614             0x77,
615             0x77,
616             0x77,
617             0x77,
618             (byte)0xFF,
619             (byte)0xFF,
620             (byte)0xFF,
621             (byte)0xFF,
622             (byte)0xFF,
623             (byte)0xFF,
624             (byte)0xFF,
625             (byte)0xFF,
626             (byte)0xFF,
627             (byte)0xFF,
628             (byte)0xFF,
629             (byte)0xFF,
630             (byte)0xFF,
631             (byte)0xFF,
632             (byte)0xFF,
633             (byte)0xFF,
634             (byte)0xFF,
635             (byte)0xFF,
636             (byte)0xFF,
637             (byte)0xFF,
638             (byte)0xFF,
639             (byte)0xFF,
640             (byte)0xFF,
641             (byte)0xFF,
642     };
643
644
645     /**
646      * The Raster Pattern for Greyscale 00
647      */

648     private static final byte[] GREYSCALE00 = new byte[] {
649             (byte)0xFF,
650             (byte)0xFF,
651             (byte)0xFF,
652             (byte)0xFF,
653             (byte)0xFF,
654             (byte)0xFF,
655             (byte)0xFF,
656             (byte)0xFF,
657             (byte)0xFF,
658             (byte)0xFF,
659             (byte)0xFF,
660             (byte)0xFF,
661             (byte)0xFF,
662             (byte)0xFF,
663             (byte)0xFF,
664             (byte)0xFF,
665             (byte)0xFF,
666             (byte)0xFF,
667             (byte)0xFF,
668             (byte)0xFF,
669             (byte)0xFF,
670             (byte)0xFF,
671             (byte)0xFF,
672             (byte)0xFF,
673             (byte)0xFF,
674             (byte)0xFF,
675             (byte)0xFF,
676             (byte)0xFF,
677             (byte)0xFF,
678             (byte)0xFF,
679             (byte)0xFF,
680             (byte)0xFF,
681     };
682
683     /**
684      * Static method to return the raster image data for the
685      * grey scale specified. The scale should be between 0 (darkest)
686      * and 16 (lightest).
687      * @param greyscale The grey scale value (0 - 16)
688      */

689     public static byte[] getRasterData(int greyscale) {
690
691         int repeat = 16;
692
693         byte[] greypattern = new byte[32];
694         byte[] rasterdata = new byte[32 * repeat];
695
696         switch (greyscale) {
697             case 0:
698                 System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32);
699                 break;
700             case 1:
701                 System.arraycopy(GREYSCALE01, 0, greypattern, 0, 32);
702                 break;
703             case 2:
704                 System.arraycopy(GREYSCALE02, 0, greypattern, 0, 32);
705                 break;
706             case 3:
707                 System.arraycopy(GREYSCALE03, 0, greypattern, 0, 32);
708                 break;
709             case 4:
710                 System.arraycopy(GREYSCALE04, 0, greypattern, 0, 32);
711                 break;
712             case 5:
713                 System.arraycopy(GREYSCALE05, 0, greypattern, 0, 32);
714                 break;
715             case 6:
716                 System.arraycopy(GREYSCALE06, 0, greypattern, 0, 32);
717                 break;
718             case 7:
719                 System.arraycopy(GREYSCALE07, 0, greypattern, 0, 32);
720                 break;
721             case 8:
722                 System.arraycopy(GREYSCALE08, 0, greypattern, 0, 32);
723                 break;
724             case 9:
725                 System.arraycopy(GREYSCALE09, 0, greypattern, 0, 32);
726                 break;
727             case 10:
728                 System.arraycopy(GREYSCALE10, 0, greypattern, 0, 32);
729                 break;
730             case 11:
731                 System.arraycopy(GREYSCALE11, 0, greypattern, 0, 32);
732                 break;
733             case 12:
734                 System.arraycopy(GREYSCALE12, 0, greypattern, 0, 32);
735                 break;
736             case 13:
737                 System.arraycopy(GREYSCALE13, 0, greypattern, 0, 32);
738                 break;
739             case 14:
740                 System.arraycopy(GREYSCALE14, 0, greypattern, 0, 32);
741                 break;
742             case 15:
743                 System.arraycopy(GREYSCALE15, 0, greypattern, 0, 32);
744                 break;
745             case 16:
746                 System.arraycopy(GREYSCALE16, 0, greypattern, 0, 32);
747                 break;
748             default :
749                 System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32);
750                 break;
751         }
752
753         for (int i = 0; i < repeat; i++) {
754
755             System.arraycopy(greypattern, 0, rasterdata, i * 32, 32);
756
757         }
758
759         return rasterdata;
760
761     }
762
763 }
764
Popular Tags