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
Ирина Усольцева
assignment-image-rotation
Commits
a7b206ad
Commit
a7b206ad
authored
2 years ago
by
chertila1
Browse files
Options
Download
Email Patches
Plain Diff
New file commit
parent
e6173fd2
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1 addition
and
315 deletions
+1
-315
solution/include/bmp.h
solution/include/bmp.h
+0
-49
solution/include/io.h
solution/include/io.h
+0
-21
solution/include/picture.h
solution/include/picture.h
+0
-25
solution/include/rotate.h
solution/include/rotate.h
+0
-8
solution/src/bmp.c
solution/src/bmp.c
+0
-109
solution/src/io.c
solution/src/io.c
+0
-56
solution/src/picture.c
solution/src/picture.c
+0
-15
solution/src/rotate.c
solution/src/rotate.c
+0
-31
tester/src/main.c
tester/src/main.c
+1
-1
No files found.
solution/include/bmp.h
deleted
100644 → 0
View file @
e6173fd2
#ifndef ASSIGNMENT_IMAGE_ROTATION_BMP_H
#define ASSIGNMENT_IMAGE_ROTATION_BMP_H
#include <mm_malloc.h>
#include <stdint.h>
#include <stdio.h>
#include "../include/picture.h"
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
;
};
enum
read_status
{
READ_OK
=
0
,
READ_ERROR
,
SIGNATURE_INVALID
,
HEADER_INVALID
,
};
enum
write_status
{
WRITE_OK
=
0
,
WRITE_ERROR
,
WRITE_CONTINUE
};
extern
const
char
*
read_status_message
[];
extern
const
char
*
write_status_message
[];
enum
read_status
from_bmp
(
FILE
*
in
,
struct
picture
*
picture
);
enum
write_status
to_bmp
(
FILE
*
out
,
const
struct
picture
*
picture
);
#endif //ASSIGNMENT_IMAGE_ROTATION_BMP_H
This diff is collapsed.
Click to expand it.
solution/include/io.h
deleted
100644 → 0
View file @
e6173fd2
#ifndef ASSIGNMENT_IMAGE_ROTATION_IO_H
#define ASSIGNMENT_IMAGE_ROTATION_IO_H
#include <stdbool.h>
#include <stdio.h>
enum
io_return_code
{
OPEN_SUCCESS
=
0
,
CLOSE_SUCCESS
,
OPEN_FAILED
,
CLOSE_FAILED
,
FILE_CLOSED
,
};
extern
const
char
*
io_return_code_string
[];
enum
io_return_code
file_open
(
const
char
*
file_name
,
FILE
**
file
,
const
char
*
mode
);
enum
io_return_code
file_close
(
FILE
*
file
);
#endif //ASSIGNMENT_IMAGE_ROTATION_IO_H
This diff is collapsed.
Click to expand it.
solution/include/picture.h
deleted
100644 → 0
View file @
e6173fd2
#ifndef ASSIGNMENT_IMAGE_ROTATION_IMAGE_H
#define ASSIGNMENT_IMAGE_ROTATION_IMAGE_H
#include <stdbool.h>
#include <stdint.h>
struct
pixel
{
uint8_t
r
;
uint8_t
g
;
uint8_t
b
;
};
struct
picture
{
uint64_t
width
;
uint64_t
height
;
struct
pixel
*
data
;
};
struct
picture
some_picture
(
const
uint64_t
width
,
const
uint64_t
height
,
struct
pixel
*
data
);
struct
picture
picture_create
(
const
uint64_t
picture_width
,
const
uint64_t
picture_height
);
void
picture_destroy
(
const
struct
picture
*
picture
);
#endif //ASSIGNMENT_IMAGE_ROTATION_IMAGE_H
This diff is collapsed.
Click to expand it.
solution/include/rotate.h
deleted
100644 → 0
View file @
e6173fd2
#ifndef ASSIGNMENT_IMAGE_ROTATION_ROTATE_H
#define ASSIGNMENT_IMAGE_ROTATION_ROTATE_H
#include "../include/picture.h"
struct
picture
transform
(
struct
picture
source
);
#endif //ASSIGNMENT_IMAGE_ROTATION_ROTATE_H
This diff is collapsed.
Click to expand it.
solution/src/bmp.c
deleted
100644 → 0
View file @
e6173fd2
#include "../include/bmp.h"
#include "stdint.h"
#include <stdbool.h>
#define BFTYPE 19778
#define BIPLANES 1
#define BISIZE 40
#define BPC 24
#define COMPR 0
#define X_PPM 0
#define Y_PPM 0
#define IMP_COLORS 0
#define NUM_COLORS 0
#define HEADER_BITS 54
const
char
*
read_status_message
[]
=
{
[
READ_OK
]
=
"The read was successful"
,
[
READ_ERROR
]
=
"Read wasn't successful"
,
[
SIGNATURE_INVALID
]
=
"Signature of BMP file is invalid"
,
[
HEADER_INVALID
]
=
"BMP file header is invalid"
};
const
char
*
write_status_message
[]
=
{
[
WRITE_OK
]
=
"The write was successful"
,
[
WRITE_ERROR
]
=
"Unable to write BMP"
};
static
size_t
padding_size
(
const
size_t
width
)
{
return
width
%
4
==
0
?
0
:
4
-
((
width
*
sizeof
(
struct
pixel
))
%
4
);
}
static
enum
read_status
read_head
(
FILE
*
file
,
struct
bmp_header
*
header
)
{
return
fread
(
header
,
sizeof
(
struct
bmp_header
),
1
,
file
);
}
static
size_t
picture_size
(
const
struct
picture
*
picture
)
{
return
(
picture
->
width
*
sizeof
(
struct
pixel
)
+
padding_size
(
picture
->
width
))
*
picture
->
height
;
}
static
size_t
file_size
(
const
struct
picture
*
picture
)
{
return
picture_size
(
picture
)
+
sizeof
(
struct
bmp_header
);
}
static
struct
bmp_header
create_header
(
const
struct
picture
*
picture
)
{
return
(
struct
bmp_header
)
{
.
bfType
=
BFTYPE
,
.
bfileSize
=
file_size
(
picture
),
.
bOffBits
=
HEADER_BITS
,
.
biSize
=
BISIZE
,
.
biWidth
=
picture
->
width
,
.
biHeight
=
picture
->
height
,
.
biPlanes
=
BIPLANES
,
.
biBitCount
=
BPC
,
.
biCompression
=
COMPR
,
.
biSizeImage
=
picture_size
(
picture
),
.
biXPelsPerMeter
=
X_PPM
,
.
biYPelsPerMeter
=
Y_PPM
,
.
biClrUsed
=
NUM_COLORS
,
.
biClrImportant
=
IMP_COLORS
};
}
static
enum
read_status
header_check_valid
(
struct
bmp_header
*
header
)
{
return
header
->
bfType
==
0x4D42
;
}
enum
read_status
from_bmp
(
FILE
*
in
,
struct
picture
*
picture
)
{
struct
bmp_header
header
=
{
0
};
if
(
!
read_head
(
in
,
&
header
))
return
HEADER_INVALID
;
if
(
!
header_check_valid
(
&
header
))
return
SIGNATURE_INVALID
;
*
picture
=
picture_create
(
header
.
biWidth
,
header
.
biHeight
);
const
size_t
padding
=
padding_size
(
picture
->
width
);
for
(
size_t
i
=
0
;
i
<
picture
->
height
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
picture
->
width
;
++
j
)
{
if
(
!
fread
(
&
(
picture
->
data
[
picture
->
width
*
i
+
j
]),
sizeof
(
struct
pixel
),
1
,
in
))
return
READ_ERROR
;
}
if
(
fseek
(
in
,
(
long
)
padding
,
SEEK_CUR
))
return
READ_ERROR
;
}
return
READ_OK
;
}
enum
write_status
to_bmp
(
FILE
*
out
,
const
struct
picture
*
picture
)
{
struct
bmp_header
header
=
create_header
(
picture
);
if
(
!
fwrite
(
&
header
,
sizeof
(
struct
bmp_header
),
1
,
out
))
return
WRITE_ERROR
;
fseek
(
out
,
header
.
bOffBits
,
SEEK_SET
);
const
int8_t
zero
=
0
;
const
size_t
padding
=
padding_size
(
picture
->
width
);
if
(
picture
->
data
!=
NULL
)
{
for
(
size_t
i
=
0
;
i
<
picture
->
height
;
++
i
)
{
if
(
fwrite
(
picture
->
data
+
i
*
picture
->
width
,
sizeof
(
struct
pixel
),
picture
->
width
,
out
)
!=
picture
->
width
)
return
WRITE_ERROR
;
for
(
size_t
j
=
0
;
j
<
padding
;
++
j
)
{
if
(
fwrite
(
&
zero
,
1
,
1
,
out
)
!=
1
)
return
WRITE_ERROR
;
}
}
}
else
{
return
WRITE_ERROR
;
}
return
WRITE_OK
;
}
This diff is collapsed.
Click to expand it.
solution/src/io.c
deleted
100644 → 0
View file @
e6173fd2
#include "../include/io.h"
const
char
*
io_return_code_string
[]
=
{
[
OPEN_FAILED
]
=
"Error occurred while opening the file"
,
[
OPEN_SUCCESS
]
=
"File opened"
,
[
CLOSE_FAILED
]
=
"Error occurred while closing the file"
,
[
CLOSE_SUCCESS
]
=
"File closed"
,
[
FILE_CLOSED
]
=
"Program can't deal with a closed file"
};
enum
io_return_code
file_open
(
const
char
*
file_name
,
FILE
**
file
,
const
char
*
mode
)
{
*
file
=
fopen
(
file_name
,
mode
);
if
(
!*
file
)
return
OPEN_FAILED
;
return
OPEN_SUCCESS
;
}
enum
io_return_code
file_close
(
FILE
*
file
)
{
if
(
!
file
)
return
FILE_CLOSED
;
if
(
fclose
(
file
))
return
CLOSE_FAILED
;
return
CLOSE_SUCCESS
;
}
enum
io_return_code
file_read
(
const
char
*
file_name
,
FILE
**
file
)
{
const
char
*
mode
=
"r"
;
return
file_open
(
file_name
,
file
,
mode
);
}
enum
io_return_code
file_write
(
const
char
*
file_name
,
FILE
**
file
)
{
const
char
*
mode
=
"w"
;
return
file_open
(
file_name
,
file
,
mode
);
}
#ifndef ASSIGNMENT_IMAGE_ROTATION_IO_H
#define ASSIGNMENT_IMAGE_ROTATION_IO_H
#include <stdbool.h>
#include <stdio.h>
enum
io_return_code
{
OPEN_SUCCESS
=
0
,
CLOSE_SUCCESS
,
OPEN_FAILED
,
CLOSE_FAILED
,
FILE_CLOSED
,
};
extern
const
char
*
io_return_code_string
[];
enum
io_return_code
file_open
(
const
char
*
file_name
,
FILE
**
file
,
const
char
*
mode
);
enum
io_return_code
file_close
(
FILE
*
file
);
#endif //ASSIGNMENT_IMAGE_ROTATION_IO_H
This diff is collapsed.
Click to expand it.
solution/src/picture.c
deleted
100644 → 0
View file @
e6173fd2
#include "../include/picture.h"
#include "mm_malloc.h"
#include <stdlib.h>
struct
picture
some_picture
(
const
uint64_t
width
,
const
uint64_t
height
,
struct
pixel
*
data
)
{
return
(
struct
picture
)
{.
width
=
width
,
.
height
=
height
,
.
data
=
data
};
}
struct
picture
picture_create
(
const
uint64_t
width
,
const
uint64_t
height
)
{
struct
pixel
*
pixels
=
malloc
(
sizeof
(
struct
pixel
)
*
width
*
height
);
return
some_picture
(
width
,
height
,
pixels
);
}
void
picture_destroy
(
const
struct
picture
*
picture
)
{
free
(
picture
->
data
);
}
This diff is collapsed.
Click to expand it.
solution/src/rotate.c
deleted
100644 → 0
View file @
e6173fd2
#include "../include/rotate.h"
#include <mm_malloc.h>
static
uint64_t
pixel_index_output
(
size_t
i
,
size_t
j
,
struct
picture
source
)
{
return
source
.
height
*
j
+
(
source
.
height
-
1
-
i
);
}
static
uint64_t
pixel_index_input
(
size_t
i
,
size_t
j
,
struct
picture
source
)
{
return
i
*
source
.
width
+
j
;
}
static
struct
picture
rotate_left
(
const
struct
picture
source
,
struct
pixel
*
pixels
)
{
uint64_t
input_index
;
uint64_t
output_index
;
for
(
size_t
i
=
0
;
i
<
source
.
height
;
++
i
)
{
for
(
size_t
j
=
0
;
j
<
source
.
width
;
++
j
)
{
input_index
=
pixel_index_input
(
i
,
j
,
source
);
output_index
=
pixel_index_output
(
i
,
j
,
source
);
pixels
[
output_index
]
=
source
.
data
[
input_index
];
}
}
return
some_picture
(
source
.
height
,
source
.
width
,
pixels
);
}
struct
picture
transform
(
const
struct
picture
source
)
{
if
(
source
.
data
==
NULL
)
return
some_picture
(
source
.
width
,
source
.
height
,
NULL
);
struct
pixel
*
pixels
=
malloc
(
sizeof
(
struct
pixel
)
*
source
.
width
*
source
.
height
);
return
rotate_left
(
source
,
pixels
);
}
This diff is collapsed.
Click to expand it.
tester/src/main.c
View file @
a7b206ad
...
...
@@ -5,7 +5,7 @@
#include "common.h"
#include "io.h"
void
usage
()
{
void
usage
(
void
)
{
fprintf
(
stderr
,
"Usage: ./"
EXECUTABLE_NAME
" BMP_FILE_NAME1 BMP_FILE_NAME2
\n
"
);
}
...
...
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