Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netrunner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Sharinigma
netrunner
Commits
b24ae929
Commit
b24ae929
authored
7 years ago
by
Odilitime
Browse files
Options
Downloads
Patches
Plain Diff
anime.h => pnm work
parent
d60312a9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
anime.pnm
+0
-0
0 additions, 0 deletions
anime.pnm
src/pnm.cpp
+137
-0
137 additions, 0 deletions
src/pnm.cpp
src/pnm.h
+14
-0
14 additions, 0 deletions
src/pnm.h
with
151 additions
and
0 deletions
anime.pnm
0 → 100644
+
0
−
0
View file @
b24ae929
File added
This diff is collapsed.
Click to expand it.
src/pnm.cpp
0 → 100644
+
137
−
0
View file @
b24ae929
#include
"pnm.h"
#include
<iostream>
// pnm
// The PNM format is just an abstraction of the PBM, PGM, and PPM formats. I.e. the name "PNM" refers collectively to PBM, PGM, and PPM.
// pam has the advanced header
RGBAPNMObject
*
readPPM
(
const
char
*
fileName
)
{
RGBAPNMObject
*
data
=
new
RGBAPNMObject
;
// open the file to read just the header reading
FILE
*
fr
=
fopen
(
fileName
,
"r"
);
if
(
!
fr
)
{
std
::
cout
<<
"Can't open "
<<
fileName
<<
std
::
endl
;
return
nullptr
;
}
// formatted read of header
char
fileType
[
11
];
fscanf
(
fr
,
"%9s"
,
fileType
);
data
->
magicNum
=
fileType
;
std
::
cout
<<
"fileType:"
<<
fileType
<<
std
::
endl
;
unsigned
char
bits
=
0
;
// check to see if it's a PPM image file
if
(
strncmp
(
fileType
,
"P4"
,
2
)
==
0
)
{
bits
=
1
;
// PBM
}
else
if
(
strncmp
(
fileType
,
"P5"
,
2
)
==
0
)
{
bits
=
8
;
// PGM
}
else
if
(
strncmp
(
fileType
,
"P6"
,
2
)
==
0
)
{
bits
=
24
;
// PPM
}
else
if
(
strncmp
(
fileType
,
"P8"
,
2
)
==
0
)
{
bits
=
32
;
// PPM
}
std
::
cout
<<
"bits:"
<<
bits
<<
std
::
endl
;
// read the rest of header
unsigned
int
width
,
height
;
fscanf
(
fr
,
"%u
\n
%u
\n
"
,
&
width
,
&
height
);
data
->
width
=
width
;
data
->
height
=
height
;
// read maximum
data
->
maxColVal
=
255
;
// just set a default
if
(
bits
!=
1
)
{
unsigned
int
maximum
;
fscanf
(
fr
,
"%u
\n
"
,
&
maximum
);
data
->
maxColVal
=
height
;
}
int
size
=
width
*
height
;
if
(
bits
!=
1
)
{
size
*=
bits
/
8
;
}
// allocate array for pixels
char
*
pixels
=
new
char
[
size
];
// unformatted read of binary pixel data
fread
(
pixels
,
sizeof
(
int
),
size
,
fr
);
data
->
m_Ptr
=
pixels
;
// close file
fclose
(
fr
);
// return the array
return
data
;
}
// end of readPPM
void
writePBM4
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
)
{
FILE
*
fp
=
fopen
(
filename
,
"wb"
);
/* b - binary mode */
fprintf
(
fp
,
"P6
\n
%d %d
\n
255
\n
"
,
data
.
width
,
data
.
height
);
for
(
int
j
=
0
;
j
<
data
.
height
;
++
j
)
{
for
(
int
i
=
0
;
i
<
data
.
width
;
++
i
)
{
static
unsigned
char
color
[
1
];
unsigned
int
pos
=
((
i
*
4
)
+
(
j
*
4
*
1024
));
//color[0] = data.m_Ptr[pos + 0]; /* red */
//color[1] = data.m_Ptr[pos + 1]; /* green */
//color[2] = data.m_Ptr[pos + 2]; /* blue */
color
[
0
]
=
data
.
m_Ptr
[
pos
+
3
];
/* alpha */
fwrite
(
color
,
1
,
1
,
fp
);
}
}
fclose
(
fp
);
}
void
writePGM5
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
)
{
FILE
*
fp
=
fopen
(
filename
,
"wb"
);
/* b - binary mode */
fprintf
(
fp
,
"P5
\n
%d %d
\n
255
\n
"
,
data
.
width
,
data
.
height
);
for
(
int
j
=
0
;
j
<
data
.
height
;
++
j
)
{
for
(
int
i
=
0
;
i
<
data
.
width
;
++
i
)
{
static
unsigned
char
color
[
1
];
unsigned
int
pos
=
((
i
*
4
)
+
(
j
*
4
*
1024
));
color
[
0
]
=
data
.
m_Ptr
[
pos
+
0
];
/* red */
//color[1] = data.m_Ptr[pos + 1]; /* green */
//color[2] = data.m_Ptr[pos + 2]; /* blue */
//color[3] = data.m_Ptr[pos + 3]; /* alpha */
fwrite
(
color
,
1
,
1
,
fp
);
}
}
fclose
(
fp
);
}
void
writePPM6
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
)
{
FILE
*
fp
=
fopen
(
filename
,
"wb"
);
/* b - binary mode */
fprintf
(
fp
,
"P6
\n
%d %d
\n
255
\n
"
,
data
.
width
,
data
.
height
);
for
(
int
j
=
0
;
j
<
data
.
height
;
++
j
)
{
for
(
int
i
=
0
;
i
<
data
.
width
;
++
i
)
{
static
unsigned
char
color
[
3
];
unsigned
int
pos
=
((
i
*
4
)
+
(
j
*
4
*
1024
));
color
[
0
]
=
data
.
m_Ptr
[
pos
+
0
];
/* red */
color
[
1
]
=
data
.
m_Ptr
[
pos
+
1
];
/* green */
color
[
2
]
=
data
.
m_Ptr
[
pos
+
2
];
/* blue */
//color[3] = data.m_Ptr[pos + 3]; /* alpha */
fwrite
(
color
,
1
,
3
,
fp
);
}
}
fclose
(
fp
);
}
void
writePPM8
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
)
{
FILE
*
fp
=
fopen
(
filename
,
"wb"
);
/* b - binary mode */
fprintf
(
fp
,
"P8
\n
%d %d
\n
255
\n
"
,
data
.
width
,
data
.
height
);
for
(
int
j
=
0
;
j
<
data
.
height
;
++
j
)
{
for
(
int
i
=
0
;
i
<
data
.
width
;
++
i
)
{
static
unsigned
char
color
[
4
];
unsigned
int
pos
=
((
i
*
4
)
+
(
j
*
4
*
1024
));
color
[
0
]
=
data
.
m_Ptr
[
pos
+
0
];
/* red */
color
[
1
]
=
data
.
m_Ptr
[
pos
+
1
];
/* green */
color
[
2
]
=
data
.
m_Ptr
[
pos
+
2
];
/* blue */
color
[
3
]
=
data
.
m_Ptr
[
pos
+
3
];
/* alpha */
fwrite
(
color
,
1
,
4
,
fp
);
}
}
fclose
(
fp
);
}
This diff is collapsed.
Click to expand it.
src/pnm.h
0 → 100644
+
14
−
0
View file @
b24ae929
#include
<string>
// this structure expects RGBA
struct
RGBAPNMObject
{
std
::
string
magicNum
;
int
width
,
height
,
maxColVal
;
char
*
m_Ptr
;
};
RGBAPNMObject
*
readPPM
(
const
char
*
fileName
);
void
writePBM4
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
);
void
writePGM5
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
);
void
writePPM6
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
);
void
writePPM8
(
const
char
*
filename
,
const
RGBAPNMObject
&
data
);
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