Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Ivan Nabiullin
assignment-image-rotation
Commits
dec235c0
Commit
dec235c0
authored
3 years ago
by
Ivan Nabiullin
Browse files
Options
Download
Email Patches
Plain Diff
fixed commented problems
parent
d2bd0ada
master
No related merge requests found
Pipeline
#16368
passed with stages
in 15 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
20 deletions
+41
-20
solution/include/image_io.h
solution/include/image_io.h
+5
-2
solution/src/bmp_format.c
solution/src/bmp_format.c
+25
-3
solution/src/image_io.c
solution/src/image_io.c
+10
-14
solution/src/main.c
solution/src/main.c
+1
-1
No files found.
solution/include/image_io.h
View file @
dec235c0
...
...
@@ -4,7 +4,8 @@
#include <stdio.h>
enum
read_status
{
READ_OK
=
0
,
READ_OK
,
READ_IMAGE_NULL
,
READ_FILE_CLOSED
,
READ_EOF
,
READ_INVALID_HEADER
...
...
@@ -13,7 +14,9 @@ enum read_status {
enum
read_status
read_image
(
const
char
*
path
,
struct
image
*
img
);
enum
write_status
{
WRITE_OK
=
0
,
WRITE_OK
,
WRITE_IMAGE_NULL
=
0xF
,
// чтобы коды ошибок отличались для чтения/записи
WRITE_EOF
,
WRITE_FILE_CLOSED
};
...
...
This diff is collapsed.
Click to expand it.
solution/src/bmp_format.c
View file @
dec235c0
...
...
@@ -13,6 +13,25 @@
#define DWORD_SIZE 4
#define BI_BIT_COUNT 24
struct
__attribute__
((
packed
))
bmp_header
{
uint16_t
bfType
;
uint32_t
bfileSize
;
uint32_t
bfReserved
;
uint32_t
bOffBits
;
uint32_t
biSize
;
uint32_t
biWidth
;
uint32_t
biHeight
;
uint16_t
biPlanes
;
uint16_t
biBitCount
;
uint32_t
biCompression
;
uint32_t
biSizeImage
;
uint32_t
biXPelsPerMeter
;
uint32_t
biYPelsPerMeter
;
uint32_t
biClrUsed
;
uint32_t
biClrImportant
;
};
size_t
get_padding
(
struct
image
const
*
img
)
{
return
4
-
(
img
->
width
*
sizeof
(
struct
pixel
))
%
4
;
}
...
...
@@ -49,6 +68,9 @@ struct bmp_header prepare_bmp_header(struct image const* img) {
return
header
;
}
// Проверка на валидность файла и указателя на картинку
// принципиально вынесена в другой уровень абстракции
// См. image_io.c
enum
read_status
from_bmp
(
FILE
*
in
,
struct
image
*
img
)
{
struct
bmp_header
header
;
if
(
!
fread
(
&
header
,
sizeof
(
header
),
1
,
in
))
return
READ_INVALID_HEADER
;
...
...
@@ -56,7 +78,7 @@ enum read_status from_bmp( FILE* in, struct image* img ) {
img
->
height
=
header
.
biHeight
;
img
->
data
=
(
struct
pixel
*
)
malloc
(
body_size
(
img
));
for
(
size_t
i
=
0
;
i
<
img
->
height
;
i
++
)
{
if
(
fread
(
&
img
->
data
[
i
*
img
->
width
],
sizeof
(
struct
pixel
),
img
->
width
,
in
)
<
img
->
width
)
return
READ_EOF
;
if
(
fread
(
&
img
->
data
[
i
*
img
->
width
],
sizeof
(
struct
pixel
),
img
->
width
,
in
)
!=
img
->
width
)
return
READ_EOF
;
fseek
(
in
,
get_padding
(
img
),
SEEK_CUR
);
}
return
READ_OK
;
...
...
@@ -66,8 +88,8 @@ enum write_status to_bmp( FILE* out, struct image const* img ) {
struct
bmp_header
header
=
prepare_bmp_header
(
img
);
fwrite
(
&
header
,
sizeof
(
struct
bmp_header
),
1
,
out
);
for
(
size_t
i
=
0
;
i
<
img
->
height
;
i
++
)
{
fwrite
(
&
img
->
data
[
i
*
img
->
width
],
sizeof
(
struct
pixel
),
img
->
width
,
out
);
fwrite
(
&
img
->
data
,
1
,
get_padding
(
img
),
out
);
if
(
fwrite
(
&
img
->
data
[
i
*
img
->
width
],
sizeof
(
struct
pixel
),
img
->
width
,
out
)
!=
img
->
width
)
return
WRITE_EOF
;
if
(
fwrite
(
&
img
->
data
,
1
,
get_padding
(
img
),
out
)
!=
get_padding
(
img
))
return
WRITE_EOF
;
}
return
WRITE_OK
;
}
This diff is collapsed.
Click to expand it.
solution/src/image_io.c
View file @
dec235c0
...
...
@@ -3,22 +3,18 @@
enum
read_status
read_image
(
const
char
*
path
,
struct
image
*
img
)
{
FILE
*
fin
=
fopen
(
path
,
"r"
);
if
(
fin
)
{
enum
read_status
read_status
=
from_bmp
(
fin
,
img
);
fclose
(
fin
);
return
read_status
;
}
else
{
return
READ_FILE_CLOSED
;
}
if
(
!
img
)
return
READ_IMAGE_NULL
;
if
(
!
fin
)
return
READ_FILE_CLOSED
;
enum
read_status
read_status
=
from_bmp
(
fin
,
img
);
fclose
(
fin
);
return
read_status
;
}
enum
write_status
write_image
(
const
char
*
path
,
struct
image
*
img
)
{
FILE
*
fout
=
fopen
(
path
,
"w"
);
if
(
fout
)
{
enum
write_status
write_status
=
to_bmp
(
fout
,
img
);
fclose
(
fout
);
return
write_status
;
}
else
{
return
WRITE_FILE_CLOSED
;
}
if
(
!
img
)
return
WRITE_IMAGE_NULL
;
if
(
!
fout
)
return
WRITE_FILE_CLOSED
;
enum
write_status
write_status
=
to_bmp
(
fout
,
img
);
fclose
(
fout
);
return
write_status
;
}
This diff is collapsed.
Click to expand it.
solution/src/main.c
View file @
dec235c0
...
...
@@ -4,7 +4,7 @@
#include "rotate.h"
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
3
)
{
if
(
argc
!=
3
)
{
printf
(
"This program takes two arguments!"
);
return
-
1
;
}
...
...
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
Menu
Projects
Groups
Snippets
Help