You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ImageRasterPattern.java 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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. /* $Id$ */
  18. package org.apache.fop.afp.ioca;
  19. /**
  20. * Raster data is a grid of cells covering an area of interest.
  21. * Each pixel, the smallest unit of information in the grid, displays
  22. * a unique attribute. This static class generates raster data for different
  23. * shades of grey (betweeen 0 and 16) the lower the number being the
  24. * darker the shade. The image data dimensions are 64 x 8.
  25. */
  26. public final class ImageRasterPattern {
  27. private ImageRasterPattern() {
  28. }
  29. /**
  30. * The Raster Pattern for Greyscale 16
  31. */
  32. private static final byte[] GREYSCALE16 = new byte[] {
  33. 0x00,
  34. 0x00,
  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. };
  66. /**
  67. * The Raster Pattern for Greyscale 15
  68. */
  69. private static final byte[] GREYSCALE15 = new byte[] {
  70. 0x00,
  71. 0x00,
  72. 0x00,
  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. 0x11,
  95. 0x11,
  96. 0x11,
  97. 0x11,
  98. 0x11,
  99. 0x11,
  100. 0x11,
  101. 0x11,
  102. };
  103. /**
  104. * The Raster Pattern for Greyscale 14
  105. */
  106. private static final byte[] GREYSCALE14 = new byte[] {
  107. 0x00,
  108. 0x00,
  109. 0x00,
  110. 0x00,
  111. 0x00,
  112. 0x00,
  113. 0x00,
  114. 0x00,
  115. 0x11,
  116. 0x11,
  117. 0x11,
  118. 0x11,
  119. 0x11,
  120. 0x11,
  121. 0x11,
  122. 0x11,
  123. 0x00,
  124. 0x00,
  125. 0x00,
  126. 0x00,
  127. 0x00,
  128. 0x00,
  129. 0x00,
  130. 0x00,
  131. 0x44,
  132. 0x44,
  133. 0x44,
  134. 0x44,
  135. 0x44,
  136. 0x44,
  137. 0x44,
  138. 0x44,
  139. };
  140. /**
  141. * The Raster Pattern for Greyscale 13
  142. */
  143. private static final byte[] GREYSCALE13 = new byte[] {
  144. 0x00,
  145. 0x00,
  146. 0x00,
  147. 0x00,
  148. 0x00,
  149. 0x00,
  150. 0x00,
  151. 0x00,
  152. 0x11,
  153. 0x11,
  154. 0x11,
  155. 0x11,
  156. 0x11,
  157. 0x11,
  158. 0x11,
  159. 0x11,
  160. 0x00,
  161. 0x00,
  162. 0x00,
  163. 0x00,
  164. 0x00,
  165. 0x00,
  166. 0x00,
  167. 0x00,
  168. (byte)0xAA,
  169. (byte)0xAA,
  170. (byte)0xAA,
  171. (byte)0xAA,
  172. (byte)0xAA,
  173. (byte)0xAA,
  174. (byte)0xAA,
  175. (byte)0xAA,
  176. };
  177. /**
  178. * The Raster Pattern for Greyscale 12
  179. */
  180. private static final byte[] GREYSCALE12 = new byte[] {
  181. 0x00,
  182. 0x00,
  183. 0x00,
  184. 0x00,
  185. 0x00,
  186. 0x00,
  187. 0x00,
  188. 0x00,
  189. 0x55,
  190. 0x55,
  191. 0x55,
  192. 0x55,
  193. 0x55,
  194. 0x55,
  195. 0x55,
  196. 0x55,
  197. 0x00,
  198. 0x00,
  199. 0x00,
  200. 0x00,
  201. 0x00,
  202. 0x00,
  203. 0x00,
  204. 0x00,
  205. (byte)0xAA,
  206. (byte)0xAA,
  207. (byte)0xAA,
  208. (byte)0xAA,
  209. (byte)0xAA,
  210. (byte)0xAA,
  211. (byte)0xAA,
  212. (byte)0xAA,
  213. };
  214. /**
  215. * The Raster Pattern for Greyscale 11
  216. */
  217. private static final byte[] GREYSCALE11 = new byte[] {
  218. 0x11,
  219. 0x11,
  220. 0x11,
  221. 0x11,
  222. 0x11,
  223. 0x11,
  224. 0x11,
  225. 0x11,
  226. 0x44,
  227. 0x44,
  228. 0x44,
  229. 0x44,
  230. 0x44,
  231. 0x44,
  232. 0x44,
  233. 0x44,
  234. 0x11,
  235. 0x11,
  236. 0x11,
  237. 0x11,
  238. 0x11,
  239. 0x11,
  240. 0x11,
  241. 0x11,
  242. (byte)0xAA,
  243. (byte)0xAA,
  244. (byte)0xAA,
  245. (byte)0xAA,
  246. (byte)0xAA,
  247. (byte)0xAA,
  248. (byte)0xAA,
  249. (byte)0xAA,
  250. };
  251. /**
  252. * The Raster Pattern for Greyscale 10
  253. */
  254. private static final byte[] GREYSCALE10 = new byte[] {
  255. 0x11,
  256. 0x11,
  257. 0x11,
  258. 0x11,
  259. 0x11,
  260. 0x11,
  261. 0x11,
  262. 0x11,
  263. (byte)0xAA,
  264. (byte)0xAA,
  265. (byte)0xAA,
  266. (byte)0xAA,
  267. (byte)0xAA,
  268. (byte)0xAA,
  269. (byte)0xAA,
  270. (byte)0xAA,
  271. 0x44,
  272. 0x44,
  273. 0x44,
  274. 0x44,
  275. 0x44,
  276. 0x44,
  277. 0x44,
  278. 0x44,
  279. (byte)0xAA,
  280. (byte)0xAA,
  281. (byte)0xAA,
  282. (byte)0xAA,
  283. (byte)0xAA,
  284. (byte)0xAA,
  285. (byte)0xAA,
  286. (byte)0xAA,
  287. };
  288. /**
  289. * The Raster Pattern for Greyscale 9
  290. */
  291. private static final byte[] GREYSCALE09 = new byte[] {
  292. 0x11,
  293. 0x11,
  294. 0x11,
  295. 0x11,
  296. 0x11,
  297. 0x11,
  298. 0x11,
  299. 0x11,
  300. (byte)0xAA,
  301. (byte)0xAA,
  302. (byte)0xAA,
  303. (byte)0xAA,
  304. (byte)0xAA,
  305. (byte)0xAA,
  306. (byte)0xAA,
  307. (byte)0xAA,
  308. 0x55,
  309. 0x55,
  310. 0x55,
  311. 0x55,
  312. 0x55,
  313. 0x55,
  314. 0x55,
  315. 0x55,
  316. (byte)0xAA,
  317. (byte)0xAA,
  318. (byte)0xAA,
  319. (byte)0xAA,
  320. (byte)0xAA,
  321. (byte)0xAA,
  322. (byte)0xAA,
  323. (byte)0xAA,
  324. };
  325. /**
  326. * The Raster Pattern for Greyscale 8
  327. */
  328. private static final byte[] GREYSCALE08 = new byte[] {
  329. (byte)0xAA,
  330. (byte)0xAA,
  331. (byte)0xAA,
  332. (byte)0xAA,
  333. (byte)0xAA,
  334. (byte)0xAA,
  335. (byte)0xAA,
  336. (byte)0xAA,
  337. (byte)0xAA,
  338. (byte)0xAA,
  339. (byte)0xAA,
  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. };
  362. /**
  363. * The Raster Pattern for Greyscale 7
  364. */
  365. private static final byte[] GREYSCALE07 = new byte[] {
  366. 0x55,
  367. 0x55,
  368. 0x55,
  369. 0x55,
  370. 0x55,
  371. 0x55,
  372. 0x55,
  373. 0x55,
  374. (byte)0xAA,
  375. (byte)0xAA,
  376. (byte)0xAA,
  377. (byte)0xAA,
  378. (byte)0xAA,
  379. (byte)0xAA,
  380. (byte)0xAA,
  381. (byte)0xAA,
  382. 0x55,
  383. 0x55,
  384. 0x55,
  385. 0x55,
  386. 0x55,
  387. 0x55,
  388. 0x55,
  389. 0x55,
  390. (byte)0xBB,
  391. (byte)0xBB,
  392. (byte)0xBB,
  393. (byte)0xBB,
  394. (byte)0xBB,
  395. (byte)0xBB,
  396. (byte)0xBB,
  397. (byte)0xBB,
  398. };
  399. /**
  400. * The Raster Pattern for Greyscale 6
  401. */
  402. private static final byte[] GREYSCALE06 = new byte[] {
  403. 0x55,
  404. 0x55,
  405. 0x55,
  406. 0x55,
  407. 0x55,
  408. 0x55,
  409. 0x55,
  410. 0x55,
  411. (byte)0xBB,
  412. (byte)0xBB,
  413. (byte)0xBB,
  414. (byte)0xBB,
  415. (byte)0xBB,
  416. (byte)0xBB,
  417. (byte)0xBB,
  418. (byte)0xBB,
  419. 0x55,
  420. 0x55,
  421. 0x55,
  422. 0x55,
  423. 0x55,
  424. 0x55,
  425. 0x55,
  426. 0x55,
  427. (byte)0xEE,
  428. (byte)0xEE,
  429. (byte)0xEE,
  430. (byte)0xEE,
  431. (byte)0xEE,
  432. (byte)0xEE,
  433. (byte)0xEE,
  434. (byte)0xEE,
  435. };
  436. /**
  437. * The Raster Pattern for Greyscale 5
  438. */
  439. private static final byte[] GREYSCALE05 = new byte[] {
  440. 0x55,
  441. 0x55,
  442. 0x55,
  443. 0x55,
  444. 0x55,
  445. 0x55,
  446. 0x55,
  447. 0x55,
  448. (byte)0xBB,
  449. (byte)0xBB,
  450. (byte)0xBB,
  451. (byte)0xBB,
  452. (byte)0xBB,
  453. (byte)0xBB,
  454. (byte)0xBB,
  455. (byte)0xBB,
  456. (byte)0xEE,
  457. (byte)0xEE,
  458. (byte)0xEE,
  459. (byte)0xEE,
  460. (byte)0xEE,
  461. (byte)0xEE,
  462. (byte)0xEE,
  463. (byte)0xEE,
  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. };
  473. /**
  474. * The Raster Pattern for Greyscale 4
  475. */
  476. private static final byte[] GREYSCALE04 = new byte[] {
  477. 0x55,
  478. 0x55,
  479. 0x55,
  480. 0x55,
  481. 0x55,
  482. 0x55,
  483. 0x55,
  484. 0x55,
  485. (byte)0xFF,
  486. (byte)0xFF,
  487. (byte)0xFF,
  488. (byte)0xFF,
  489. (byte)0xFF,
  490. (byte)0xFF,
  491. (byte)0xFF,
  492. (byte)0xFF,
  493. (byte)0xAA,
  494. (byte)0xAA,
  495. (byte)0xAA,
  496. (byte)0xAA,
  497. (byte)0xAA,
  498. (byte)0xAA,
  499. (byte)0xAA,
  500. (byte)0xAA,
  501. (byte)0xFF,
  502. (byte)0xFF,
  503. (byte)0xFF,
  504. (byte)0xFF,
  505. (byte)0xFF,
  506. (byte)0xFF,
  507. (byte)0xFF,
  508. (byte)0xFF,
  509. };
  510. /**
  511. * The Raster Pattern for Greyscale 3
  512. */
  513. private static final byte[] GREYSCALE03 = new byte[] {
  514. 0x55,
  515. 0x55,
  516. 0x55,
  517. 0x55,
  518. 0x55,
  519. 0x55,
  520. 0x55,
  521. 0x55,
  522. (byte)0xFF,
  523. (byte)0xFF,
  524. (byte)0xFF,
  525. (byte)0xFF,
  526. (byte)0xFF,
  527. (byte)0xFF,
  528. (byte)0xFF,
  529. (byte)0xFF,
  530. (byte)0xBB,
  531. (byte)0xBB,
  532. (byte)0xBB,
  533. (byte)0xBB,
  534. (byte)0xBB,
  535. (byte)0xBB,
  536. (byte)0xBB,
  537. (byte)0xBB,
  538. (byte)0xFF,
  539. (byte)0xFF,
  540. (byte)0xFF,
  541. (byte)0xFF,
  542. (byte)0xFF,
  543. (byte)0xFF,
  544. (byte)0xFF,
  545. (byte)0xFF,
  546. };
  547. /**
  548. * The Raster Pattern for Greyscale 2
  549. */
  550. private static final byte[] GREYSCALE02 = new byte[] {
  551. 0x77,
  552. 0x77,
  553. 0x77,
  554. 0x77,
  555. 0x77,
  556. 0x77,
  557. 0x77,
  558. 0x77,
  559. (byte)0xFF,
  560. (byte)0xFF,
  561. (byte)0xFF,
  562. (byte)0xFF,
  563. (byte)0xFF,
  564. (byte)0xFF,
  565. (byte)0xFF,
  566. (byte)0xFF,
  567. (byte)0xDD,
  568. (byte)0xDD,
  569. (byte)0xDD,
  570. (byte)0xDD,
  571. (byte)0xDD,
  572. (byte)0xDD,
  573. (byte)0xDD,
  574. (byte)0xDD,
  575. (byte)0xFF,
  576. (byte)0xFF,
  577. (byte)0xFF,
  578. (byte)0xFF,
  579. (byte)0xFF,
  580. (byte)0xFF,
  581. (byte)0xFF,
  582. (byte)0xFF,
  583. };
  584. /**
  585. * The Raster Pattern for Greyscale 1
  586. */
  587. private static final byte[] GREYSCALE01 = new byte[] {
  588. 0x77,
  589. 0x77,
  590. 0x77,
  591. 0x77,
  592. 0x77,
  593. 0x77,
  594. 0x77,
  595. 0x77,
  596. (byte)0xFF,
  597. (byte)0xFF,
  598. (byte)0xFF,
  599. (byte)0xFF,
  600. (byte)0xFF,
  601. (byte)0xFF,
  602. (byte)0xFF,
  603. (byte)0xFF,
  604. (byte)0xFF,
  605. (byte)0xFF,
  606. (byte)0xFF,
  607. (byte)0xFF,
  608. (byte)0xFF,
  609. (byte)0xFF,
  610. (byte)0xFF,
  611. (byte)0xFF,
  612. (byte)0xFF,
  613. (byte)0xFF,
  614. (byte)0xFF,
  615. (byte)0xFF,
  616. (byte)0xFF,
  617. (byte)0xFF,
  618. (byte)0xFF,
  619. (byte)0xFF,
  620. };
  621. /**
  622. * The Raster Pattern for Greyscale 00
  623. */
  624. private static final byte[] GREYSCALE00 = new byte[] {
  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. (byte)0xFF,
  643. (byte)0xFF,
  644. (byte)0xFF,
  645. (byte)0xFF,
  646. (byte)0xFF,
  647. (byte)0xFF,
  648. (byte)0xFF,
  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. };
  658. /**
  659. * Static method to return the raster image data for the
  660. * grey scale specified. The scale should be between 0 (darkest)
  661. * and 16 (lightest).
  662. * @param greyscale The grey scale value (0 - 16)
  663. * @return the raster data byte array for the given greyscale value
  664. */
  665. public static byte[] getRasterData(int greyscale) {
  666. int repeat = 16;
  667. byte[] greypattern = new byte[32];
  668. byte[] rasterdata = new byte[32 * repeat];
  669. switch (greyscale) {
  670. case 0:
  671. System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32);
  672. break;
  673. case 1:
  674. System.arraycopy(GREYSCALE01, 0, greypattern, 0, 32);
  675. break;
  676. case 2:
  677. System.arraycopy(GREYSCALE02, 0, greypattern, 0, 32);
  678. break;
  679. case 3:
  680. System.arraycopy(GREYSCALE03, 0, greypattern, 0, 32);
  681. break;
  682. case 4:
  683. System.arraycopy(GREYSCALE04, 0, greypattern, 0, 32);
  684. break;
  685. case 5:
  686. System.arraycopy(GREYSCALE05, 0, greypattern, 0, 32);
  687. break;
  688. case 6:
  689. System.arraycopy(GREYSCALE06, 0, greypattern, 0, 32);
  690. break;
  691. case 7:
  692. System.arraycopy(GREYSCALE07, 0, greypattern, 0, 32);
  693. break;
  694. case 8:
  695. System.arraycopy(GREYSCALE08, 0, greypattern, 0, 32);
  696. break;
  697. case 9:
  698. System.arraycopy(GREYSCALE09, 0, greypattern, 0, 32);
  699. break;
  700. case 10:
  701. System.arraycopy(GREYSCALE10, 0, greypattern, 0, 32);
  702. break;
  703. case 11:
  704. System.arraycopy(GREYSCALE11, 0, greypattern, 0, 32);
  705. break;
  706. case 12:
  707. System.arraycopy(GREYSCALE12, 0, greypattern, 0, 32);
  708. break;
  709. case 13:
  710. System.arraycopy(GREYSCALE13, 0, greypattern, 0, 32);
  711. break;
  712. case 14:
  713. System.arraycopy(GREYSCALE14, 0, greypattern, 0, 32);
  714. break;
  715. case 15:
  716. System.arraycopy(GREYSCALE15, 0, greypattern, 0, 32);
  717. break;
  718. case 16:
  719. System.arraycopy(GREYSCALE16, 0, greypattern, 0, 32);
  720. break;
  721. default :
  722. System.arraycopy(GREYSCALE00, 0, greypattern, 0, 32);
  723. break;
  724. }
  725. for (int i = 0; i < repeat; i++) {
  726. System.arraycopy(greypattern, 0, rasterdata, i * 32, 32);
  727. }
  728. return rasterdata;
  729. }
  730. }