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
c-language
assignment-image-rotation
Commits
f54c9caf
Commit
f54c9caf
authored
4 years ago
by
draftsquire
Browse files
Options
Download
Email Patches
Plain Diff
Pixels** successfully replaced with pixels*
parent
f39372ce
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
14 deletions
+22
-14
image_rotation.exe
image_rotation.exe
+0
-0
man.bmp
man.bmp
+0
-0
src/bmp.c
src/bmp.c
+8
-3
src/image.c
src/image.c
+3
-7
src/image.h
src/image.h
+1
-1
src/transformation.c
src/transformation.c
+10
-3
No files found.
image_rotation.exe
View file @
f54c9caf
No preview for this file type
This diff is collapsed.
Click to expand it.
man.bmp
deleted
100644 → 0
View file @
f39372ce
1.17 MB
This diff is collapsed.
Click to expand it.
src/bmp.c
View file @
f54c9caf
...
...
@@ -66,9 +66,12 @@ enum bmp_read_status from_bmp( FILE* in, struct image* const read ){
if
(
header
.
biBitCount
!=
24
)
return
READ_INVALID_BITS
;
// uint32_t pixels_count = header.biHeight * header.biWidth;
create_image
(
read
,
header
.
biWidth
,
header
.
biHeight
);
struct
pixel
*
current_address
=
read
->
pixels
;
size_t
padding
=
(
size_t
)
bmp_line_padding
(
header
.
biWidth
);
for
(
size_t
i
=
0
;
i
<
(
size_t
)
header
.
biHeight
;
i
++
){
if
(
fread
(
read
->
pixels
[
i
],
sizeof
(
struct
pixel
),
header
.
biWidth
,
in
)
!=
header
.
biWidth
)
return
READ_PIXELS_LOSS
;
if
(
fread
(
current_address
,
sizeof
(
struct
pixel
)
*
header
.
biWidth
,
1
,
in
)
!=
1
)
return
READ_PIXELS_LOSS
;
fseek
(
in
,
padding
,
SEEK_CUR
);
current_address
+=
header
.
biWidth
;
}
// if (successfully_read_pixels!=pixels_count) return READ_PIXELS_LOSS;
return
READ_OK
;
...
...
@@ -112,9 +115,11 @@ enum bmp_write_status to_bmp(FILE* out, struct image* const write){
//uint32_t successfully_written_pixels=0;
if
(
fwrite
(
&
header
,
sizeof
(
struct
bmp_header
),
1
,
out
)
!=
1
)
return
WRITE_HEADER_ERROR
;
uint8_t
filling_byte
=
0x6F
;
struct
pixel
*
current_adress
=
write
->
pixels
;
for
(
size_t
i
=
0
;
i
<
(
size_t
)
header
.
biHeight
;
i
++
){
if
(
fwrite
(
write
->
pixels
[
i
]
,
sizeof
(
struct
pixel
)
,
header
.
biWidth
,
out
)
!=
header
.
biWidth
)
return
WRITE_PIXELS_LOSS
;
if
(
fwrite
(
current_adress
,
sizeof
(
struct
pixel
)
*
header
.
biWidth
,
1
,
out
)
!=
1
)
return
WRITE_PIXELS_LOSS
;
fwrite
(
&
filling_byte
,
sizeof
(
uint8_t
),
(
size_t
)
bmp_line_padding
(
header
.
biWidth
),
out
);
current_adress
+=
header
.
biWidth
;
}
//if (successfully_written_pixels!=pixels_to_write) return WRITE_PIXELS_LOSS;
return
WRITE_OK
;
...
...
This diff is collapsed.
Click to expand it.
src/image.c
View file @
f54c9caf
...
...
@@ -3,16 +3,12 @@
void
create_image
(
struct
image
*
image
,
uint32_t
width
,
uint32_t
height
)
{
image
->
width
=
width
;
image
->
height
=
height
;
image
->
pixels
=
malloc
(
sizeof
(
struct
pixel
*
)
*
height
);
for
(
size_t
i
=
0
;
i
<
(
size_t
)
height
;
i
++
)
{
image
->
pixels
[
i
]
=
malloc
(
sizeof
(
struct
pixel
)
*
width
);
}
image
->
pixels
=
malloc
(
sizeof
(
struct
pixel
)
*
(
size_t
)(
width
*
height
)
);
}
void
destroy_image
(
struct
image
*
image
){
for
(
size_t
i
=
0
;
i
<
(
size_t
)
image
->
height
;
i
++
)
{
free
(
image
->
pixels
[
i
]);
}
free
(
image
->
pixels
);
}
This diff is collapsed.
Click to expand it.
src/image.h
View file @
f54c9caf
...
...
@@ -11,7 +11,7 @@ struct pixel{
struct
image
{
uint32_t
height
;
uint32_t
width
;
struct
pixel
*
*
pixels
;
struct
pixel
*
pixels
;
};
void
create_image
(
struct
image
*
image
,
uint32_t
width
,
uint32_t
height
);
void
destroy_image
(
struct
image
*
image
);
...
...
This diff is collapsed.
Click to expand it.
src/transformation.c
View file @
f54c9caf
#include "transformation.h"
#include <stdio.h>
struct
image
rotate
(
struct
image
*
const
source
)
{
uint32_t
rotated_width
=
source
->
height
;
uint32_t
rotated_height
=
source
->
width
;
struct
image
rotated_image
=
{
0
};
create_image
(
&
rotated_image
,
rotated_width
,
rotated_height
);
fprintf
(
stdout
,
"%"
PRIu32
"
\n
"
,
rotated_image
.
height
);
for
(
size_t
i
=
0
;
i
<
(
size_t
)
rotated_width
;
i
++
){
for
(
size_t
j
=
0
;
j
<
(
size_t
)
rotated_height
;
j
++
){
rotated_image
.
pixels
[
j
][
rotated_width
-
1
-
i
]
=
source
->
pixels
[
i
][
j
];
for
(
size_t
j
=
0
;
j
<
(
size_t
)
rotated_height
;
++
j
){
//rotated_image.pixels[j][rotated_width-1-i]=source->pixels[i];
rotated_image
.
pixels
[
i
+
j
*
rotated_width
]
=
source
->
pixels
[
rotated_height
*
(
i
+
1
)
-
j
-
1
];
}
}
return
rotated_image
;
}
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