Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
libvncserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
libvncserver
Commits
e68063f2
Commit
e68063f2
authored
Mar 24, 2004
by
dscho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for pgm and pbm (8-bit and 1-bit grayscale images)
parent
6a1a59f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
14 deletions
+50
-14
pnmshow.c
examples/pnmshow.c
+50
-14
No files found.
examples/pnmshow.c
View file @
e68063f2
...
...
@@ -11,9 +11,11 @@ void HandleKey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
int
main
(
int
argc
,
char
**
argv
)
{
FILE
*
in
=
stdin
;
int
i
,
j
,
k
,
width
,
height
,
paddedWidth
;
int
i
,
j
,
k
,
l
,
width
,
height
,
paddedWidth
;
char
buffer
[
1024
];
rfbScreenInfoPtr
rfbScreen
;
enum
{
BW
,
GRAY
,
TRUECOLOUR
}
picType
=
TRUECOLOUR
;
int
bytesPerPixel
,
bitsPerPixelInFile
;
if
(
argc
>
1
)
{
in
=
fopen
(
argv
[
1
],
"rb"
);
...
...
@@ -24,7 +26,16 @@ int main(int argc,char** argv)
}
fgets
(
buffer
,
1024
,
in
);
if
(
strncmp
(
buffer
,
"P6"
,
2
))
{
if
(
!
strncmp
(
buffer
,
"P6"
,
2
))
{
picType
=
TRUECOLOUR
;
bytesPerPixel
=
4
;
bitsPerPixelInFile
=
3
*
8
;
}
else
if
(
!
strncmp
(
buffer
,
"P5"
,
2
))
{
picType
=
GRAY
;
bytesPerPixel
=
1
;
bitsPerPixelInFile
=
1
*
8
;
}
else
if
(
!
strncmp
(
buffer
,
"P4"
,
2
))
{
picType
=
BW
;
bytesPerPixel
=
1
;
bitsPerPixelInFile
=
1
;
}
else
{
printf
(
"Not a ppm.
\n
"
);
exit
(
2
);
}
...
...
@@ -37,7 +48,10 @@ int main(int argc,char** argv)
/* get width & height */
sscanf
(
buffer
,
"%d %d"
,
&
width
,
&
height
);
rfbLog
(
"Got width %d and height %d.
\n
"
,
width
,
height
);
fgets
(
buffer
,
1024
,
in
);
if
(
picType
!=
BW
)
fgets
(
buffer
,
1024
,
in
);
else
width
=
1
+
((
width
-
1
)
|
7
);
/* vncviewers have problems with widths which are no multiple of 4. */
paddedWidth
=
width
;
...
...
@@ -45,7 +59,7 @@ int main(int argc,char** argv)
paddedWidth
+=
4
-
(
width
&
3
);
/* initialize data for vnc server */
rfbScreen
=
rfbGetScreen
(
&
argc
,
argv
,
paddedWidth
,
height
,
8
,
3
,
4
);
rfbScreen
=
rfbGetScreen
(
&
argc
,
argv
,
paddedWidth
,
height
,
8
,
(
bitsPerPixelInFile
+
7
)
/
8
,
bytesPerPixel
);
if
(
argc
>
1
)
rfbScreen
->
desktopName
=
argv
[
1
];
else
...
...
@@ -57,18 +71,40 @@ int main(int argc,char** argv)
rfbScreen
->
httpDir
=
"./classes"
;
/* allocate picture and read it */
rfbScreen
->
frameBuffer
=
(
char
*
)
malloc
(
paddedWidth
*
4
*
height
);
fread
(
rfbScreen
->
frameBuffer
,
width
*
3
,
height
,
in
);
rfbScreen
->
frameBuffer
=
(
char
*
)
malloc
(
paddedWidth
*
bytesPerPixel
*
height
);
fread
(
rfbScreen
->
frameBuffer
,
width
*
bitsPerPixelInFile
/
8
,
height
,
in
);
fclose
(
in
);
/* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */
for
(
j
=
height
-
1
;
j
>=
0
;
j
--
)
{
for
(
i
=
width
-
1
;
i
>=
0
;
i
--
)
for
(
k
=
2
;
k
>=
0
;
k
--
)
rfbScreen
->
frameBuffer
[(
j
*
paddedWidth
+
i
)
*
4
+
k
]
=
rfbScreen
->
frameBuffer
[(
j
*
width
+
i
)
*
3
+
k
];
for
(
i
=
width
*
4
;
i
<
paddedWidth
*
4
;
i
++
)
rfbScreen
->
frameBuffer
[
j
*
paddedWidth
*
4
+
i
]
=
0
;
if
(
picType
!=
TRUECOLOUR
)
{
rfbScreen
->
rfbServerFormat
.
trueColour
=
FALSE
;
rfbScreen
->
colourMap
.
count
=
256
;
rfbScreen
->
colourMap
.
is16
=
FALSE
;
rfbScreen
->
colourMap
.
data
.
bytes
=
malloc
(
256
*
3
);
for
(
i
=
0
;
i
<
256
;
i
++
)
memset
(
rfbScreen
->
colourMap
.
data
.
bytes
+
3
*
i
,
i
,
3
);
}
switch
(
picType
)
{
case
TRUECOLOUR
:
/* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */
for
(
j
=
height
-
1
;
j
>=
0
;
j
--
)
{
for
(
i
=
width
-
1
;
i
>=
0
;
i
--
)
for
(
k
=
2
;
k
>=
0
;
k
--
)
rfbScreen
->
frameBuffer
[(
j
*
paddedWidth
+
i
)
*
4
+
k
]
=
rfbScreen
->
frameBuffer
[(
j
*
width
+
i
)
*
3
+
k
];
for
(
i
=
width
*
4
;
i
<
paddedWidth
*
4
;
i
++
)
rfbScreen
->
frameBuffer
[
j
*
paddedWidth
*
4
+
i
]
=
0
;
}
break
;
case
BW
:
/* correct the format from 1 bit to 8 bits */
for
(
j
=
height
-
1
;
j
>=
0
;
j
--
)
for
(
i
=
width
-
1
;
i
>=
0
;
i
-=
8
)
{
l
=
(
unsigned
char
)
rfbScreen
->
frameBuffer
[(
j
*
width
+
i
)
/
8
];
for
(
k
=
7
;
k
>=
0
;
k
--
)
rfbScreen
->
frameBuffer
[
j
*
paddedWidth
+
i
+
7
-
k
]
=
(
l
&
(
1
<<
k
))
?
0
:
255
;
}
break
;
}
/* initialize server */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment