Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit774962a

Browse files
committed
Adds video support
ImageIcon(xxx,"jsvideo")where xxx isbyte[] video dataString video filenameURL video URL
1 parent63f31b8 commit774962a

File tree

20 files changed

+379
-106
lines changed

20 files changed

+379
-106
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200417142842
1+
20200419115937
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200417142842
1+
20200419115937

‎sources/net.sf.j2s.java.core/src/java/awt/image/BufferedImage.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
importswingjs.JSGraphics2D;
5151
importswingjs.JSGraphicsCompositor;
5252
importswingjs.JSUtil;
53+
importswingjs.api.JSUtilI;
5354
importswingjs.api.js.DOMNode;
5455
importswingjs.api.js.HTML5Canvas;
5556

@@ -250,7 +251,7 @@ public class BufferedImage extends Image implements RenderedImage, Transparency
250251
* in a single byte array in the order B, G, R, A from lower to higher byte
251252
* addresses within each pixel.
252253
*/
253-
publicstaticfinalintTYPE_4BYTE_HTML5 =-6;
254+
publicstaticfinalintTYPE_4BYTE_HTML5 =JSUtilI.TYPE_4BYTE_HTML5;
254255
/**
255256
* Represents an image with 8-bit RGBA color components with the colors Blue,
256257
* Green, and Red stored in 3 bytes and 1 byte of alpha. The image has a
@@ -389,6 +390,9 @@ public class BufferedImage extends Image implements RenderedImage, Transparency
389390
* @see #TYPE_USHORT_555_RGB
390391
*/
391392
publicBufferedImage(intwidth,intheight,intimageType) {
393+
秘init(width,height,imageType);
394+
}
395+
protectedvoid秘init(intwidth,intheight,intimageType) {
392396
this.width =width;
393397
this.height =height;
394398
秘wxh =width *height;

‎sources/net.sf.j2s.java.core/src/java/io/File.java‎

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,7 @@ private static File generateFile(String prefix, String suffix, File dir)
17531753
f.秘isTempFile =true;
17541754
returnf;
17551755
}
1756+
17561757
//
17571758
// private static boolean checkAndCreate(String filename, SecurityManager sm,
17581759
// boolean restrictive)
@@ -1771,29 +1772,19 @@ private static File generateFile(String prefix, String suffix, File dir)
17711772
// return fs.createFileExclusively(filename, restrictive);
17721773
// }
17731774
//
1774-
// The resulting temporary file may have more restrictive access permission
1775-
// on some platforms, if restrictive is true.
1776-
privatestaticFilecreateTempFile0(Stringprefix,Stringsuffix,
1777-
Filedirectory,booleanrestrictive)
1778-
throwsIOException
1779-
{
1780-
if (prefix ==null)thrownewNullPointerException();
1781-
if (prefix.length() <3)
1782-
thrownewIllegalArgumentException("Prefix string too short");
1783-
Strings = (suffix ==null) ?".tmp" :suffix;
1784-
directory =newFile(temporaryDirectory + (directory ==null ?"" :directory));
1785-
// we ensure that there is a clear marker for a temporary directory in SwingJS
1786-
// if (directory == null) {
1787-
// String tmpDir = temporaryDirectory();
1788-
// directory = new File(tmpDir);//, fs.prefixLength(tmpDir));
1789-
// }
1790-
// SecurityManager sm = System.getSecurityManager();
1791-
Filef;
1792-
// do {
1793-
f =generateFile(prefix,s,directory);
1794-
// } while (!checkAndCreate(f.getPath(), sm, restrictive));
1795-
returnf;
1796-
}
1775+
// The resulting temporary file may have more restrictive access permission
1776+
// on some platforms, if restrictive is true.
1777+
privatestaticFilecreateTempFile0(Stringprefix,Stringsuffix,Filedirectory,booleanrestrictive)
1778+
throwsIOException {
1779+
if (prefix ==null)
1780+
thrownewNullPointerException();
1781+
if (prefix.length() <3)
1782+
thrownewIllegalArgumentException("Prefix string too short");
1783+
Strings = (suffix ==null) ?".tmp" :suffix;
1784+
directory =newFile(temporaryDirectory + (directory ==null ?"" :directory));
1785+
// we ensure that there is a clear marker for a temporary directory in SwingJS
1786+
returngenerateFile(prefix,s,directory);
1787+
}
17971788

17981789
/**
17991790
* <p> Creates a new empty file in the specified directory, using the

‎sources/net.sf.j2s.java.core/src/java/net/URL.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,9 +1007,11 @@ public String toExternalForm() {
10071007
* @return a URI instance equivalent to this URL.
10081008
* @since 1.5
10091009
*/
1010-
// public URI toURI() throws URISyntaxException {
1011-
// return new URI (toString());
1012-
// }
1010+
publicURItoURI()throwsURISyntaxException {
1011+
URIuri =newURI (toString());
1012+
uri.秘bytes = (byte[])_streamData;
1013+
returnuri;
1014+
}
10131015

10141016
/**
10151017
* Returns a <code>URLConnection</code> object that represents a connection to

‎sources/net.sf.j2s.java.core/src/javax/swing/ImageIcon.java‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
importjava.awt.image.BufferedImage;
3737
importjava.awt.image.ImageObserver;
3838
importswingjs.JSGraphics2D;
39+
importswingjs.JSToolkit;
3940

4041
/**
4142
* An implementation of the Icon interface that paints Icons
@@ -148,7 +149,11 @@ public class ImageIcon implements Icon {
148149
* @see #ImageIcon(String)
149150
*/
150151
publicImageIcon(Stringfilename,Stringdescription) {
151-
image =Toolkit.getDefaultToolkit().getImage(filename);
152+
if (description !=null &&description.indexOf("jsvideo") >=0) {
153+
image = ((JSToolkit)Toolkit.getDefaultToolkit()).getVideo(filename);
154+
}else {
155+
image =Toolkit.getDefaultToolkit().getImage(filename);
156+
}
152157
if (image ==null) {
153158
return;
154159
}
@@ -186,7 +191,11 @@ public ImageIcon (String filename) {
186191
* @see #ImageIcon(String)
187192
*/
188193
publicImageIcon(URLlocation,Stringdescription) {
189-
image =Toolkit.getDefaultToolkit().getImage(location);
194+
if (description !=null &&description.indexOf("jsvideo") >=0) {
195+
image = ((JSToolkit)Toolkit.getDefaultToolkit()).getVideo(location);
196+
}else {
197+
image =Toolkit.getDefaultToolkit().getImage(location);
198+
}
190199
if (image ==null) {
191200
return;
192201
}
@@ -249,7 +258,11 @@ public ImageIcon (Image image) {
249258
* @see java.awt.Toolkit#createImage
250259
*/
251260
publicImageIcon (byte[]imageData,Stringdescription) {
252-
this.image =Toolkit.getDefaultToolkit().createImage(imageData);
261+
if (description !=null &&description.indexOf("jsvideo") >=0) {
262+
image = ((JSToolkit)Toolkit.getDefaultToolkit()).createVideo(imageData);
263+
}else {
264+
this.image =Toolkit.getDefaultToolkit().createImage(imageData);
265+
}
253266
if (image ==null) {
254267
return;
255268
}
@@ -315,6 +328,16 @@ protected void loadImage(Image image) {
315328
// }
316329
}
317330

331+
/**
332+
* SwingJS delayed video size
333+
*
334+
* @param w
335+
* @param h
336+
*/
337+
publicvoid秘setIconSize(intw,inth) {
338+
width =w;
339+
height =h;
340+
}
318341
// /**
319342
// * Returns an ID to use with the MediaTracker in loading an image.
320343
// */

‎sources/net.sf.j2s.java.core/src/swingjs/JSImage.java‎

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
importjava.awt.Component;
44
importjava.awt.Image;
55
importjava.awt.image.BufferedImage;
6+
importjava.io.File;
7+
importjava.io.IOException;
8+
importjava.nio.file.Path;
9+
10+
importjavax.swing.ImageIcon;
11+
importjavax.swing.JLabel;
12+
importjavax.swing.SwingUtilities;
613

714
importjavajs.util.Base64;
15+
importswingjs.JSFileSystem.JSPath;
816
importswingjs.api.js.DOMNode;
17+
importswingjs.plaf.JSComponentUI;
918

1019
/**
1120
* A JavaScript version of BufferedImage.
@@ -61,14 +70,63 @@ public JSImage(byte[] pixelBytes, int width, int height, String src) {
6170
* @param type
6271
*/
6372
@SuppressWarnings("unused")
64-
publicvoidgetDOMImage(byte[]b,Stringtype) {
65-
Stringdataurl ="data:image/" +type +";base64," +Base64.getBase64(b).toString();
73+
voidsetImageNode(JSPathsource,byte[]b,Stringtype) {
6674
DOMNodeimg =null;
67-
/**
68-
* @j2sNative img = new Image(this.width, this.height); //if (this.callback)
69-
* img.onload = this.callback; img.src = dataurl;
70-
*/
75+
if (type =="video") {
76+
try {
77+
Stringsrc = (source ==null ?null :JSUtil.getWebPathFor(source.toString()));
78+
if (b ==null &&source !=null)
79+
b =source.秘bytes;
80+
System.out.println("JSImage video " +src +" " + (b ==null ?0 :b.length));
81+
img =DOMNode.createElement("video",File.createTempFile("video_","").getName());
82+
DOMNodenode =img;
83+
Runnabler =newRunnable() {
84+
// set dimension when available
85+
@Override
86+
publicvoidrun() {
87+
intw =0,h =0;
88+
DOMNoden =node;
89+
/**
90+
* @j2sNative
91+
*
92+
* w = n.width = n.videoWidth; h = n.height = n.videoHeight;
93+
*
94+
*/
95+
JSComponentUIui = (JSComponentUI)DOMNode.getAttr(node,"data-ui");
96+
System.out.println("JSImage w,h " +w +" " +h);
97+
秘init(w,h,TYPE_INT_ARGB);
98+
if (ui !=null &&ui.jcinstanceofJLabel) {
99+
JLabellabel = (JLabel)ui.jc;
100+
w =label.getWidth();
101+
h =label.getHeight();
102+
n.setAttribute("width",w +"");
103+
n.setAttribute("height",h +"");
104+
ui.setTainted();
105+
ImageIconicon = (ImageIcon)label.getIcon();
106+
if (icon !=null) {
107+
icon.秘setIconSize(w,h);
108+
}
109+
}
110+
}
111+
};
112+
/**
113+
* @j2sNative
114+
*
115+
* //document.body.appendChild(img);
116+
* img.src = (b == null ? src : URL.createObjectURL(new Blob([b])));
117+
* img.onloadedmetadata = function(){ r.run$()};
118+
* img.load();
119+
*/
120+
121+
}catch (IOExceptione) {
122+
}
123+
}else {
124+
Stringdataurl ="data:image/" +type +";base64," +Base64.getBase64(b).toString();
125+
/**
126+
* @j2sNative img = new Image(this.width, this.height); img.src = dataurl;
127+
*/
71128

129+
}
72130
秘imgNode =img;
73131
}
74132

‎sources/net.sf.j2s.java.core/src/swingjs/JSImagekit.java‎

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
importjava.awt.image.ColorModel;
1616
importjava.awt.image.ImageConsumer;
1717
importjava.awt.image.WritableRaster;
18+
importjava.nio.file.Path;
1819

20+
importswingjs.JSFileSystem.JSPath;
1921
importswingjs.api.Interface;
2022
importswingjs.api.js.DOMNode;
2123
importswingjs.api.js.HTML5Canvas;
@@ -36,6 +38,7 @@ public class JSImagekit implements ImageConsumer {
3638
privatestaticfinalintJPG =1;
3739
privatestaticfinalintGIF =2;
3840
privatestaticfinalintBMP =3;
41+
privatestaticfinalintVIDEO =4;
3942
privatestaticfinalintJPG_SOF0 =0xC0FF;
4043
privatestaticfinalintJPG_SOF2 =0xC2FF;
4144

@@ -52,7 +55,7 @@ public class JSImagekit implements ImageConsumer {
5255
*/
5356
publicJSImagecreateImageFromBytes(byte[]data,intimageoffset,
5457
intimagelength,Stringname) {
55-
returncreateImageFromBytesStatic(data,imageoffset,imagelength,name);
58+
returncreateImageFromBytesStatic(data,imageoffset,imagelength,name,UNK);
5659
}
5760

5861
privateintwidth;
@@ -153,8 +156,8 @@ public void setPixels(int x, int y, int w, int h, ColorModel model,
153156
JSUtil.notImplemented("byte-based image pixels");
154157
}
155158

156-
privatestaticJSImagecreateImageFromBytesStatic(byte[]data,intimageoffset,
157-
intimagelength,Stringname) {
159+
privatestaticJSImagecreateImageFromBytesStatic(byte[]data,intimageoffset,intimagelength,Stringname,
160+
intimageType) {
158161
intw =0,h =0;
159162
int[]argb =null;
160163
byte[]b =null;
@@ -163,20 +166,24 @@ private static JSImage createImageFromBytesStatic(byte[] data, int imageoffset,
163166
// this is from Component.createImage();
164167
w =imageoffset;
165168
h =imagelength;
169+
}elseif (imageType ==VIDEO){
170+
b =data;
171+
w =imageoffset;
172+
h =imagelength;
173+
type ="video";
166174
}else {
167175
if (imagelength <0)
168176
imagelength =data.length;
169-
// not implemented in #"diff-f40e6e080d1af08c877ee8821b4f49b343eb285449c341b310cf06913acefcb8-169-177-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">
177+
// not implemented in #"diff-f40e6e080d1af08c877ee8821b4f49b343eb285449c341b310cf06913acefcb8-170-178-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">170
178
// b = Arrays.copyOfRange(data, imageoffset, imagelength);
171179
intn =imagelength -imageoffset;
172-
System.arraycopy(data,imageoffset,b =newbyte[n],0,n);
173-
if (b.length <10)//was 54??? I have no recollection of why that might be.
180+
System.arraycopy(data,imageoffset,b =newbyte[n],0,n);
181+
if (b.length <10)//was 54??? I have no recollection of why that might be.
174182
returnnull;
175-
switch (getSourceType(b)) {
183+
switch (imageType ==UNK ?getSourceType(b) :imageType) {
176184
caseBMP:
177185
// just get bytes directly
178-
BMPDecoderie = (BMPDecoder)Interface.getInstance(
179-
"javajs.img.BMPDecoder",true);
186+
BMPDecoderie = (BMPDecoder)Interface.getInstance("javajs.img.BMPDecoder",true);
180187
Object[]o =ie.decodeWindowsBMP(b);
181188
if (o ==null ||o[0] ==null)
182189
returnnull;
@@ -212,17 +219,16 @@ private static JSImage createImageFromBytesStatic(byte[] data, int imageoffset,
212219
type ="gif";
213220
break;
214221
caseUNK:
215-
System.out.println("JSImagekit: Unknown image type: " +b[0] +" "
216-
+b[1] +" " +b[2] +" " +b[3]);
222+
System.out.println("JSImagekit: Unknown image type: " +b[0] +" " +b[1] +" " +b[2] +" " +b[3]);
217223
data =null;
218224
break;
219225
}
220226
}
221227
if (w ==0 ||h ==0)
222228
returnnull;
223-
JSImagejsimage =newJSImage(argb,w,h,name);
229+
JSImagejsimage =newJSImage(argb,w,h,name);
224230
if (data !=null &&argb ==null)
225-
jsimage.getDOMImage(b,type);
231+
jsimage.setImageNode(null,b,type);
226232
returnjsimage;
227233
}
228234

@@ -298,5 +304,15 @@ public static JSGraphics2D createCanvasGraphics(int width, int height, String id
298304
returnnewJSGraphics2D(canvas);
299305
}
300306

307+
publicImagecreateVideo(Pathpath) {
308+
JSImagejsimage =newJSImage((byte[])null,1,1,path.toString());
309+
jsimage.setImageNode((JSPath)path,null,"video");
310+
returnjsimage;
311+
}
312+
313+
publicImagecreateVideo(byte[]bytes) {
314+
returncreateImageFromBytesStatic(bytes,1,1,null,VIDEO);
315+
}
316+
301317

302318
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp