Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Probyygolova Daniil
assignment-image-rotation
Commits
c3be1b66
Commit
c3be1b66
authored
4 years ago
by
Probyygolova Daniil
Browse files
Options
Download
Email Patches
Plain Diff
fix mistakes part 3
parent
8efd9af0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
19 deletions
+22
-19
view-header/bmp.c
view-header/bmp.c
+15
-17
view-header/image-rotation.exe
view-header/image-rotation.exe
+0
-0
view-header/main.c
view-header/main.c
+7
-2
view-header/out.bmp
view-header/out.bmp
+0
-0
No files found.
view-header/bmp.c
View file @
c3be1b66
...
...
@@ -18,6 +18,7 @@
void
bmp_header_print
(
struct
bmp_header
const
*
header
,
FILE
*
f
)
{
FOR_BMP_HEADER
(
PRINT_FIELD
)
}
uint32_t
padding
(
const
uint64_t
width
){
...
...
@@ -53,20 +54,13 @@ static bool write_header( FILE* f, struct bmp_header *const header ) {
return
fwrite
(
header
,
sizeof
(
struct
bmp_header
),
1
,
f
);
}
enum
status_valid_header
{
VALID
,
NO_VALID
,
};
enum
status_valid_header
valid_header
(
struct
bmp_header
*
header
){
if
(
header
->
bfType
!=
BMP_TYPE
)
return
NO_VALID
;
if
(
header
->
biBitCount
!=
BIT_COUNT
)
return
NO_VALID
;
if
(
header
->
biCompression
!=
0
)
return
NO_VALID
;
bool
valid_header
(
struct
bmp_header
*
header
){
return
VALID
;
return
header
->
bfType
==
BMP_TYPE
&&
header
->
biBitCount
==
BIT_COUNT
&&
header
->
biCompression
==
0
;
}
enum
read_status
from_bmp
(
FILE
*
in
,
struct
image
*
img
){
...
...
@@ -76,8 +70,8 @@ enum read_status from_bmp( FILE* in, struct image* img ){
//fread(header, sizeof( struct bmp_header), 1, file);
// Valid header
enum
status_valid_header
valid_h
=
valid_header
(
&
header
);
if
(
valid_h
==
NO_VALID
)
return
READ_INVALID_HEADER
;
bool
valid_h
=
valid_header
(
&
header
);
if
(
!
valid_h
)
return
READ_INVALID_HEADER
;
struct
pixel
*
data
=
malloc
(
sizeof
(
struct
pixel
)
*
(
header
.
biWidth
)
*
(
header
.
biHeight
));
...
...
@@ -92,7 +86,10 @@ enum read_status from_bmp( FILE* in, struct image* img ){
fseek
(
in
,
pad
,
SEEK_CUR
);
}
if
(
count
<
img
->
height
)
return
READ_ERROR
;
if
(
count
<
img
->
height
)
{
free
(
img
->
data
);
return
READ_ERROR
;
}
return
READ_OK
;
}
...
...
@@ -108,7 +105,7 @@ enum write_status to_bmp( FILE* out, struct image const* img ){
size_t
count
=
0
;
const
uint8_t
dump
=
0
;
if
(
!
write_header
(
out
,
&
header
))
return
WRITE_HEADER_ERROR
;
if
(
!
write_header
(
out
,
&
header
))
{
free
(
img
->
data
);
return
WRITE_HEADER_ERROR
;
}
fseek
(
out
,
sizeof
(
struct
bmp_header
),
SEEK_SET
);
...
...
@@ -118,6 +115,7 @@ enum write_status to_bmp( FILE* out, struct image const* img ){
}
if
(
count
<
height
){
free
(
img
->
data
);
return
WRITE_ERROR
;
}
return
WRITE_OK
;
...
...
This diff is collapsed.
Click to expand it.
view-header/image-rotation.exe
View file @
c3be1b66
No preview for this file type
This diff is collapsed.
Click to expand it.
view-header/main.c
View file @
c3be1b66
#include <stdbool.h>
#include <stdio.h>
#include <malloc.h>
#include "rotation.h"
#include "bmp.h"
#include "bmp_read_write.h"
#include "util.h"
const
char
*
array_read_status
[]
=
{
static
const
char
*
array_read_status
[]
=
{
[
READ_OK
]
=
"ok"
,
[
READ_INVALID_HEADER
]
=
"Invalid header bmp"
,
[
READ_NOT_NAME
]
=
"Wrong file name"
,
...
...
@@ -15,7 +16,7 @@ const char* array_read_status[] = {
[
READ_ERROR
]
=
"Reading error"
};
const
char
*
array_write_status
[]
=
{
static
const
char
*
array_write_status
[]
=
{
[
WRITE_OK
]
=
"ok"
,
[
WRITE_ERROR
]
=
"error while writing"
,
[
WRITE_HEADER_ERROR
]
=
"write header error"
,
...
...
@@ -41,6 +42,7 @@ int main( int argc, char** argv ) {
err
(
"Failed to open BMP file or reading header.
\n
"
);
}
//START
struct
image
img
=
{
0
};
...
...
@@ -59,5 +61,8 @@ int main( int argc, char** argv ) {
err
(
array_write_status
[
write_status
]);
}
free
(
img
.
data
);
free
(
rot_img
.
data
);
return
0
;
}
This diff is collapsed.
Click to expand it.
view-header/out.bmp
View replaced file @
8efd9af0
View file @
c3be1b66
2.13 MB
|
W:
0px
|
H:
0px
2.13 MB
|
W:
0px
|
H:
0px
2-up
Swipe
Onion skin
This diff is collapsed.
Click to expand it.
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