Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
a44f2386
Commit
a44f2386
authored
5 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
add javadoc
parent
00475428
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Tools/Authoring/PixelTextureGenerator.java
+125
-100
125 additions, 100 deletions
Tools/Authoring/PixelTextureGenerator.java
with
125 additions
and
100 deletions
Tools/Authoring/PixelTextureGenerator.java
+
125
−
100
View file @
a44f2386
/*
/*
* PixelTextureGenerator.java
* PixelTextureGenerator.java
* http://web.nps.navy.mil/~brutzman/Savage/Tools/Authoring/PixelTextureGenerator.java
* https://savage.nps.edu/Savage/Tools/Authoring/PixelTextureGenerator.java
* https://savage.nps.edu/Savage/Tools/Authoring/PixelTextureGenerator.java
* Created on June 10, 2004, 12:24 AM
* Created on June 10, 2004, 12:24 AM
* Modified on June 17, 2004, 1:46 AM
* Modified on June 17, 2004, 1:46 AM
...
@@ -9,15 +8,15 @@
...
@@ -9,15 +8,15 @@
* Revised 4 January 2006, Don Brutzman
* Revised 4 January 2006, Don Brutzman
* Revised 3 January 2007, Don Brutzman
* Revised 3 January 2007, Don Brutzman
* Revised 10 November 2018, Don Brutzman
* Revised 10 November 2018, Don Brutzman
* Revised 14 June 2020, Don Brutzman
*/
*/
import
java.awt.*
;
import
java.awt.*
;
import
java.awt.event.*
;
import
java.awt.image.*
;
import
java.awt.image.*
;
import
java.io.*
;
import
java.io.*
;
/**
/**
*
*
Generate X3D PixelTexture values.
* @author Louis Gutierrez
* @author Louis Gutierrez
* @author Don Brutzman
* @author Don Brutzman
* References:
* References:
...
@@ -27,90 +26,98 @@ import java.io.*;
...
@@ -27,90 +26,98 @@ import java.io.*;
public
class
PixelTextureGenerator
extends
Frame
public
class
PixelTextureGenerator
extends
Frame
{
{
private
Image
image
;
private
Image
image
;
private
File
outputFile
;
private
File
outputFile
;
private
FileWriter
out
;
private
FileWriter
out
;
private
int
height
,
width
;
private
int
height
,
width
;
private
String
outputFilename
;
private
String
outputFilename
;
static
String
UsageMessage
=
"usage: java PixelTextureGenerator imageName.ext [outputSceneName.x3d]"
;
static
String
UsageMessage
=
"usage: java PixelTextureGenerator imageName.ext [outputSceneName.x3d]"
;
public
PixelTextureGenerator
(
String
imageFilename
,
String
pOutputFilename
)
throws
IOException
public
PixelTextureGenerator
(
String
imageFilename
,
String
pOutputFilename
)
throws
IOException
{
{
try
try
{
{
String
name
=
""
;
String
name
=
""
;
Toolkit
toolkit
=
Toolkit
.
getDefaultToolkit
();
Toolkit
toolkit
=
Toolkit
.
getDefaultToolkit
();
image
=
toolkit
.
getImage
(
imageFilename
);
image
=
toolkit
.
getImage
(
imageFilename
);
MediaTracker
mediaTracker
=
new
MediaTracker
(
this
);
MediaTracker
mediaTracker
=
new
MediaTracker
(
this
);
mediaTracker
.
addImage
(
image
,
0
);
mediaTracker
.
addImage
(
image
,
0
);
try
try
{
{
mediaTracker
.
waitForID
(
0
);
//makes sure image loads
mediaTracker
.
waitForID
(
0
);
//makes sure image loads
}
}
catch
(
InterruptedException
ie
)
catch
(
InterruptedException
ie
)
{
{
System
.
err
.
println
(
ie
);
System
.
err
.
println
(
ie
);
System
.
exit
(
1
);
System
.
exit
(
1
);
}
}
// string manipulation for output file and header
//string manipulation for output file and header
name
=
imageFilename
.
substring
(
imageFilename
.
lastIndexOf
(
"\\"
)+
1
,
imageFilename
.
lastIndexOf
(
"."
));
name
=
imageFilename
.
substring
(
imageFilename
.
lastIndexOf
(
"\\"
)+
1
,
imageFilename
.
lastIndexOf
(
"."
));
if
(
pOutputFilename
.
length
()
==
0
)
if
(
pOutputFilename
.
length
()
==
0
)
{
{
outputFilename
=
name
+
"PixelTexture.x3d"
;
outputFilename
=
name
+
"PixelTexture.x3d"
;
}
}
else
outputFilename
=
pOutputFilename
;
else
outputFilename
=
pOutputFilename
;
// System.out.println ("[outputFilename=" + outputFilename + "]");
// System.out.println ("[outputFilename=" + outputFilename + "]");
System
.
out
.
print
(
".."
);
System
.
out
.
print
(
".."
);
outputFile
=
new
File
(
outputFilename
);
outputFile
=
new
File
(
outputFilename
);
out
=
new
FileWriter
(
outputFile
);
out
=
new
FileWriter
(
outputFile
);
System
.
out
.
print
(
"."
);
System
.
out
.
print
(
"."
);
width
=
image
.
getWidth
(
null
);
width
=
image
.
getWidth
(
null
);
height
=
image
.
getHeight
(
null
);
height
=
image
.
getHeight
(
null
);
header
(
outputFilename
,
imageFilename
,
width
,
height
);
header
(
outputFilename
,
imageFilename
,
width
,
height
);
handlePixels
(
image
,
0
,
0
,
width
,
height
);
handlePixels
(
image
,
0
,
0
,
width
,
height
);
footer
(
width
,
height
);
footer
(
width
,
height
);
System
.
out
.
println
(
"created "
+
outputFile
);
System
.
out
.
println
(
"created "
+
outputFile
);
}
}
catch
(
Exception
e
)
catch
(
IO
Exception
io
e
)
{
{
System
.
err
.
println
(
e
);
System
.
err
.
println
(
io
e
);
System
.
exit
(
1
);
System
.
exit
(
1
);
}
}
}
}
/**
/**
* This method uses pixelGrabber to grab pixels from an image and then each pixel is
* This method uses pixelGrabber to grab pixels from an image and then each
* manipulated into a hex string and written to file.
* pixel is manipulated into a hex string and written to file.
*/
*
public
void
handlePixels
(
Image
img
,
int
x
,
int
y
,
int
imageWidth
,
int
imageHeight
)
throws
IOException
* @param inputImage image of interest
* @param x initial x pixel coordinate of interest
* @param y initial y pixel coordinate of interest
* @param imageWidth image width in pixels
* @param imageHeight image height in pixels
*/
public
void
handlePixels
(
Image
inputImage
,
int
x
,
int
y
,
int
imageWidth
,
int
imageHeight
)
throws
IOException
{
{
try
try
{
{
out
.
write
(
imageWidth
+
" "
+
imageHeight
+
" "
+
"3 "
);
//default is 256*256*256 colors
out
.
write
(
imageWidth
+
" "
+
imageHeight
+
" "
+
"3 "
);
//default is 256*256*256 colors
out
.
write
(
"\n"
);
out
.
write
(
"\n"
);
int
[]
pixels
=
new
int
[
imageWidth
*
imageHeight
];
//array of pixels to grab
int
[]
pixels
=
new
int
[
imageWidth
*
imageHeight
];
//array of pixels to grab
PixelGrabber
p
g
=
new
PixelGrabber
(
i
mg
,
x
,
y
,
imageWidth
,
imageHeight
,
pixels
,
0
,
imageWidth
);
PixelGrabber
p
ixelGrabber
=
new
PixelGrabber
(
i
nputImage
,
x
,
y
,
imageWidth
,
imageHeight
,
pixels
,
0
,
imageWidth
);
try
{
try
{
p
g
.
grabPixels
();
p
ixelGrabber
.
grabPixels
();
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
System
.
err
.
println
(
"[Error] interrupted waiting for pixels!"
);
System
.
err
.
println
(
"[Error] interrupted waiting for pixels!"
);
return
;
return
;
}
}
if
((
pg
.
getStatus
()
&
ImageObserver
.
ABORT
)
!=
0
)
{
if
((
pixelGrabber
.
getStatus
()
&
ImageObserver
.
ABORT
)
!=
0
)
{
System
.
err
.
println
(
"[Error] image fetch abort or error"
);
System
.
err
.
println
(
"[Error] image fetch abort or error"
);
return
;
return
;
}
}
//cycles through the array of pixels
//cycles through the array of pixels
// SFImage: Pixels are specified from left to right, bottom to top
// SFImage: Pixels are specified from left to right, bottom to top
// for (int j = 0; j < imageHeight; j++) {
// for (int j = 0; j < imageHeight; j++) {
for
(
int
j
=
imageHeight
-
1
;
j
>=
0
;
j
--)
{
for
(
int
j
=
imageHeight
-
1
;
j
>=
0
;
j
--)
for
(
int
i
=
0
;
i
<
imageWidth
;
i
++)
{
{
for
(
int
i
=
0
;
i
<
imageWidth
;
i
++)
{
handleSinglePixel
(
x
+
i
,
y
+
j
,
pixels
[
j
*
imageWidth
+
i
]);
handleSinglePixel
(
x
+
i
,
y
+
j
,
pixels
[
j
*
imageWidth
+
i
]);
}
}
// break long lines of pixels for countability and to help some parsers/editors
// break long lines of pixels for countability and to help some parsers/editors
...
@@ -118,18 +125,24 @@ public class PixelTextureGenerator extends Frame
...
@@ -118,18 +125,24 @@ public class PixelTextureGenerator extends Frame
}
}
out
.
flush
();
out
.
flush
();
}
}
catch
(
Exception
e
)
catch
(
IO
Exception
e
)
{
{
System
.
err
.
println
(
e
);
System
.
err
.
println
(
e
);
}
}
}
}
/**
/**
* This method translates the integer value passed by pixeGrabber into
* This method translates the integer value passed by pixeGrabber into
* alpha, red, green, and blue. It then converts these integers to a hex
* alpha, red, green, and blue.It then converts these integers to a hex
* string.
* string.
*/
*
public
void
handleSinglePixel
(
int
x
,
int
y
,
int
pixel
)
throws
IOException
{
* @param x x pixel coordinate of interest
* @param y y pixel coordinate of interest
* @param pixel pixel value
* @throws java.io.IOException file exception
*/
public
void
handleSinglePixel
(
int
x
,
int
y
,
int
pixel
)
throws
IOException
{
//translates pixel integer
//translates pixel integer
int
alpha
=
(
pixel
>>
24
)
&
0xff
;
int
alpha
=
(
pixel
>>
24
)
&
0xff
;
int
red
=
(
pixel
>>
16
)
&
0xff
;
int
red
=
(
pixel
>>
16
)
&
0xff
;
...
@@ -140,11 +153,17 @@ public class PixelTextureGenerator extends Frame
...
@@ -140,11 +153,17 @@ public class PixelTextureGenerator extends Frame
hexConverter
(
red
,
green
,
blue
);
hexConverter
(
red
,
green
,
blue
);
}
}
/**
/**
* This method produces a string that represents a 6 digit hex value
* This method produces a string that represents a 6 digit hex value and
* and writes it to file.
* writes it to file.
*/
*
public
void
hexConverter
(
int
r
,
int
g
,
int
b
)
throws
IOException
{
* @param r red value
* @param g green value
* @param b blue value
* @throws java.io.IOException file exception
*/
public
void
hexConverter
(
int
r
,
int
g
,
int
b
)
throws
IOException
{
String
temp
=
"0x"
;
String
temp
=
"0x"
;
temp
+=
hexCase
(
r
/
16
);
temp
+=
hexCase
(
r
/
16
);
...
@@ -159,41 +178,48 @@ public class PixelTextureGenerator extends Frame
...
@@ -159,41 +178,48 @@ public class PixelTextureGenerator extends Frame
}
}
/**
/**
*
p
This method simply changes standard form into hex
* This method simply changes standard form into hex
*/
*/
public
char
hexCase
(
int
c
)
{
public
char
hexCase
(
int
c
)
{
char
out
=
'Z'
;
char
out
=
'Z'
;
switch
(
c
)
{
switch
(
c
)
{
case
0
:
out
=
'0'
;
break
;
case
0
:
out
=
'0'
;
break
;
case
1
:
out
=
'1'
;
break
;
case
1
:
out
=
'1'
;
break
;
case
2
:
out
=
'2'
;
break
;
case
2
:
out
=
'2'
;
break
;
case
3
:
out
=
'3'
;
break
;
case
3
:
out
=
'3'
;
break
;
case
4
:
out
=
'4'
;
break
;
case
4
:
out
=
'4'
;
break
;
case
5
:
out
=
'5'
;
break
;
case
5
:
out
=
'5'
;
break
;
case
6
:
out
=
'6'
;
break
;
case
6
:
out
=
'6'
;
break
;
case
7
:
out
=
'7'
;
break
;
case
7
:
out
=
'7'
;
break
;
case
8
:
out
=
'8'
;
break
;
case
8
:
out
=
'8'
;
break
;
case
9
:
out
=
'9'
;
break
;
case
9
:
out
=
'9'
;
break
;
case
10
:
out
=
'A'
;
break
;
case
10
:
out
=
'A'
;
break
;
case
11
:
out
=
'B'
;
break
;
case
11
:
out
=
'B'
;
break
;
case
12
:
out
=
'C'
;
break
;
case
12
:
out
=
'C'
;
break
;
case
13
:
out
=
'D'
;
break
;
case
13
:
out
=
'D'
;
break
;
case
14
:
out
=
'E'
;
break
;
case
14
:
out
=
'E'
;
break
;
case
15
:
out
=
'F'
;
break
;
case
15
:
out
=
'F'
;
break
;
default
:
System
.
out
.
println
(
"incorrect color value"
);
default
:
System
.
out
.
println
(
"incorrect color value"
);
}
}
return
out
;
return
out
;
}
}
/**
/**
* This method writes the header information to file
* This method writes the header information to file
*/
*
* @param outputFileName
* @param imageFilename
* @param x initial x pixel coordinate of interest
* @param y initial y pixel coordinate of interest
* @throws java.io.IOException file exception
*/
public
void
header
(
String
outputFileName
,
String
imageFilename
,
int
x
,
int
y
)
throws
IOException
{
public
void
header
(
String
outputFileName
,
String
imageFilename
,
int
x
,
int
y
)
throws
IOException
{
out
.
write
(
"<?xml version='1.0' encoding='UTF-8'?>\n"
);
out
.
write
(
"<?xml version='1.0' encoding='UTF-8'?>\n"
);
// final DOCTYPE
// final DOCTYPE
out
.
write
(
"<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.
1
//EN\" \"http://www.web3d.org/specifications/x3d-3.
1
.dtd\">\n"
);
out
.
write
(
"<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.
3
//EN\" \"http://www.web3d.org/specifications/x3d-3.
3
.dtd\">\n"
);
out
.
write
(
"<X3D version='3.
1
' profile='Interactive'\n"
);
out
.
write
(
"<X3D version='3.
3
' profile='Interactive'\n"
);
out
.
write
(
" xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.
0
.xsd'>\n"
);
out
.
write
(
" xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' xsd:noNamespaceSchemaLocation='http://www.web3d.org/specifications/x3d-3.
3
.xsd'>\n"
);
out
.
write
(
" <head>\n"
);
out
.
write
(
" <head>\n"
);
out
.
write
(
" <meta content='"
+
outputFileName
+
"' name='title'/>\n"
);
out
.
write
(
" <meta content='"
+
outputFileName
+
"' name='title'/>\n"
);
out
.
write
(
" <meta content='"
+
imageFilename
+
"' name='image'/>\n"
);
out
.
write
(
" <meta content='"
+
imageFilename
+
"' name='image'/>\n"
);
...
@@ -280,6 +306,5 @@ public class PixelTextureGenerator extends Frame
...
@@ -280,6 +306,5 @@ public class PixelTextureGenerator extends Frame
System
.
out
.
println
(
UsageMessage
);
System
.
out
.
println
(
UsageMessage
);
System
.
exit
(-
1
);
System
.
exit
(-
1
);
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment