930 /* Scale and translate the unit image. 931 */ 932 mPSStream.println("[" + destWidth + " 0 " 933 + "0 " + destHeight 934 + " " + destX + " " + destY 935 +"]concat"); 936 937 /* Color Image invocation. 938 */ 939 mPSStream.println(intSrcWidth + " " + intSrcHeight + " " + 8 + "[" 940 + intSrcWidth + " 0 " 941 + "0 " + intSrcHeight 942 + " 0 " + 0 + "]" 943 + "/imageSrc load false 3 colorimage"); 944 945 /* Image data. 946 */ 947 int index = 0; 948 byte[] rgbData = new byte[intSrcWidth * 3]; 949 950 try { 951 /* Skip the parts of the image that are not part 952 * of the source rectangle. 953 */ 954 index = (int) srcY * srcBitMapWidth; 955 956 for(int i = 0; i < intSrcHeight; i++) { 957 958 /* Skip the left part of the image that is not 959 * part of the source rectangle. 960 */ 961 index += (int) srcX; 962 963 index = swapBGRtoRGB(bgrData, index, rgbData); 964 byte[] encodedData = rlEncode(rgbData); 965 byte[] asciiData = ascii85Encode(encodedData); 966 mPSStream.write(asciiData); 967 mPSStream.println(""); 968 } 969 970 /* 971 * If there is an IOError we subvert it to a PrinterException. 972 * Fix: There has got to be a better way, maybe define 973 * a PrinterIOException and then throw that? 974 */ 975 } catch (IOException e) { 976 //throw new PrinterException(e.toString()); 977 } 978 979 mPSStream.println(IMAGE_RESTORE); 980 } 981 982 /** 983 * Prints the contents of the array of ints, 'data' 984 * to the current page. The band is placed at the 985 * location (x, y) in device coordinates on the 986 * page. The width and height of the band is 987 * specified by the caller. Currently the data 988 * is 24 bits per pixel in BGR format. 989 */ 990 protected void printBand(byte[] bgrData, int x, int y, 991 int width, int height) 992 throws PrinterException 993 { 994 995 mPSStream.println(IMAGE_SAVE); 996 997 /* Create a PS string big enough to hold a row of pixels. 998 */ 1006 /* Scale and translate the unit image. 1007 */ 1008 mPSStream.println("[" + width + " 0 " 1009 + "0 " + height 1010 + " " + x + " " + y 1011 +"]concat"); 1012 1013 /* Color Image invocation. 1014 */ 1015 mPSStream.println(width + " " + height + " " + 8 + "[" 1016 + width + " 0 " 1017 + "0 " + -height 1018 + " 0 " + height + "]" 1019 + "/imageSrc load false 3 colorimage"); 1020 1021 /* Image data. 1022 */ 1023 int index = 0; 1024 byte[] rgbData = new byte[width*3]; 1025 1026 try { 1027 for(int i = 0; i < height; i++) { 1028 index = swapBGRtoRGB(bgrData, index, rgbData); 1029 byte[] encodedData = rlEncode(rgbData); 1030 byte[] asciiData = ascii85Encode(encodedData); 1031 mPSStream.write(asciiData); 1032 mPSStream.println(""); 1033 } 1034 1035 } catch (IOException e) { 1036 throw new PrinterIOException(e); 1037 } 1038 1039 mPSStream.println(IMAGE_RESTORE); 1040 } 1041 1042 /** 1043 * Examine the metrics captured by the 1044 * {@code PeekGraphics} instance and 1045 * if capable of directly converting this 1046 * print job to the printer's control language 1047 * or the native OS's graphics primitives, then 1048 * return a {@code PSPathGraphics} to perform 1049 * that conversion. If there is not an object 1050 * capable of the conversion then return 1051 * {@code null}. Returning {@code null} 1052 * causes the print job to be rasterized. 1053 */ 1054 1055 protected Graphics2D createPathGraphics(PeekGraphics peekGraphics, 1056 PrinterJob printerJob, | 930 /* Scale and translate the unit image. 931 */ 932 mPSStream.println("[" + destWidth + " 0 " 933 + "0 " + destHeight 934 + " " + destX + " " + destY 935 +"]concat"); 936 937 /* Color Image invocation. 938 */ 939 mPSStream.println(intSrcWidth + " " + intSrcHeight + " " + 8 + "[" 940 + intSrcWidth + " 0 " 941 + "0 " + intSrcHeight 942 + " 0 " + 0 + "]" 943 + "/imageSrc load false 3 colorimage"); 944 945 /* Image data. 946 */ 947 int index = 0; 948 byte[] rgbData = new byte[intSrcWidth * 3]; 949 950 /* Skip the parts of the image that are not part 951 * of the source rectangle. 952 */ 953 index = (int) srcY * srcBitMapWidth; 954 955 for(int i = 0; i < intSrcHeight; i++) { 956 957 /* Skip the left part of the image that is not 958 * part of the source rectangle. 959 */ 960 index += (int) srcX; 961 962 index = swapBGRtoRGB(bgrData, index, rgbData); 963 byte[] encodedData = rlEncode(rgbData); 964 byte[] asciiData = ascii85Encode(encodedData); 965 mPSStream.write(asciiData); 966 mPSStream.println(""); 967 } 968 969 mPSStream.println(IMAGE_RESTORE); 970 } 971 972 /** 973 * Prints the contents of the array of ints, 'data' 974 * to the current page. The band is placed at the 975 * location (x, y) in device coordinates on the 976 * page. The width and height of the band is 977 * specified by the caller. Currently the data 978 * is 24 bits per pixel in BGR format. 979 */ 980 protected void printBand(byte[] bgrData, int x, int y, 981 int width, int height) 982 throws PrinterException 983 { 984 985 mPSStream.println(IMAGE_SAVE); 986 987 /* Create a PS string big enough to hold a row of pixels. 988 */ 996 /* Scale and translate the unit image. 997 */ 998 mPSStream.println("[" + width + " 0 " 999 + "0 " + height 1000 + " " + x + " " + y 1001 +"]concat"); 1002 1003 /* Color Image invocation. 1004 */ 1005 mPSStream.println(width + " " + height + " " + 8 + "[" 1006 + width + " 0 " 1007 + "0 " + -height 1008 + " 0 " + height + "]" 1009 + "/imageSrc load false 3 colorimage"); 1010 1011 /* Image data. 1012 */ 1013 int index = 0; 1014 byte[] rgbData = new byte[width*3]; 1015 1016 for(int i = 0; i < height; i++) { 1017 index = swapBGRtoRGB(bgrData, index, rgbData); 1018 byte[] encodedData = rlEncode(rgbData); 1019 byte[] asciiData = ascii85Encode(encodedData); 1020 mPSStream.write(asciiData); 1021 mPSStream.println(""); 1022 } 1023 1024 if (mPSStream.checkError()) { 1025 throw new PrinterException("Error in PrintStream"); 1026 } 1027 1028 mPSStream.println(IMAGE_RESTORE); 1029 } 1030 1031 /** 1032 * Examine the metrics captured by the 1033 * {@code PeekGraphics} instance and 1034 * if capable of directly converting this 1035 * print job to the printer's control language 1036 * or the native OS's graphics primitives, then 1037 * return a {@code PSPathGraphics} to perform 1038 * that conversion. If there is not an object 1039 * capable of the conversion then return 1040 * {@code null}. Returning {@code null} 1041 * causes the print job to be rasterized. 1042 */ 1043 1044 protected Graphics2D createPathGraphics(PeekGraphics peekGraphics, 1045 PrinterJob printerJob, |