Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pcc004
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Nayoung Kim
pcc004
Commits
dac545d4
Commit
dac545d4
authored
3 years ago
by
Nayoung Kim
Browse files
Options
Downloads
Patches
Plain Diff
Update lec11
parent
24362aec
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+105
-0
105 additions, 0 deletions
README.md
with
105 additions
and
0 deletions
README.md
+
105
−
0
View file @
dac545d4
...
...
@@ -1515,3 +1515,108 @@ int main()
fprintf(stdout, "%d + %d : %d \n", ia, ib, ic);
}
```
## **Lecture 11**
### rgba.c 코드
```
#include <stdio.h>
typedef unsigned int t_rgba;
// input value must be 0~255
/
*
방법 1. 함수 만들기
unsigned int fromRGBA(int r, int g, int b, int a)
{
if (r > 255 || r < 0)
r = 0;
if (g > 255 || g < 0)
g = 0;
if (b > 255 || b < 0)
b = 0;
if (a > 255 || a < 0)
a = 0;
if문 성능 나빠짐
// return r*256*256*256 + g*256*256 + b*256 + a*1;
// return ((r<<24)+(g<<16)+(b<<8)+a);
// return ((r<<(24+g))<<(16+b))<<(8+1);
// return (r<<24|g<<16|b<<8|a);
return ((r&0xff)<<24)|((g&0xff)<<16)|((b&0xff)<<8)|(a&0xff);
}
*
/
// 방법 2. macro
#define fromRGBA(r,g,b,a) ((((r)&0xff)<<24)|(((g)&0xff)<<16)|(((b)&0xff)<<8)|((a)&0xff))
#define F_NUM_1_255 (1.0f/255.0f)
t_rgba mul_float(t_rgba c1, t_rgba c2){
float r1, g1, b1, a1;
float r2, g2, b2, a2;
int ir, ig, ib, ia;
r1 = (float) ((c1 >> 24) & 0xff) * F_NUM_1_255;
g1 = (float) ((c1 >> 16) & 0xff) * F_NUM_1_255;
b1 = (float) ((c1 >> 8) & 0xff) * F_NUM_1_255;
a1 = (float) ((c1 >> 0) & 0xff) * F_NUM_1_255;
r2 = (float) ((c2 >> 24) & 0xff) * F_NUM_1_255;
g2 = (float) ((c2 >> 16) & 0xff) * F_NUM_1_255;
b2 = (float) ((c2 >> 8) & 0xff) * F_NUM_1_255;
a2 = (float) ((c2 >> 0) & 0xff) * F_NUM_1_255;
ir = (int) ((r1 * r2) * 255.0f);
ig = (int) ((g1 * g2) * 255.0f);
ib = (int) ((b1 * b2) * 255.0f);
ia = (int) ((a1 * a2) * 255.0f);
return fromRGBA(ir, ig, ib, ia);
}
t_rgba mul_int(t_rgba c1, t_rgba c2)
{
unsigned int r1, g1, b1, a1;
unsigned int r2, g2, b2, a2;
unsigned int r, g, b, a;
r1 = c1 >> 24 ; r2 = c2 >> 24 ;
g1 = (c1 >> 16) & 0xff ; g2 = (c2 >> 16) & 0xff;
b1 = (c1 >> 16) & 0xff ; b2 = (c2 >> 8) & 0xff;
a1 = c1 & 0xff ; a2 = c2 & 0xff;
r= (r1 * r2) / 255;
g= (g1 * g2) / 255;
b= (b1 * b2) / 255;
a= (a1 * a2) / 255;
return fromRGBA(r,g,b,a);
}
int main()
{
int red, green, blue, alpha;
t_rgba rgba_1, rgba_2, rgba_3;
// input value must be 0~255 : 0.0~1.0
// rgba_1
[
rrrrrrrr
][
gggggggg
][
bbbbbbbb
][
aaaaaaaa
]
printf("input 4 values with 0~255 : ");
scanf("%d %d %d %d", &red, &green, &blue,
&alpha);
rgba_1 = fromRGBA(red, green, blue, alpha);
printf("%d %d %d %d : %u 0x%08x
\n
", red, green, blue, alpha, rgba_1, rgba_1);
rgba_2 = mul_float(rgba_1, rgba_1);
printf("%d %d %d %d : %u 0x%08x
\n
", red, green, blue, alpha, rgba_2, rgba_2);
rgba_3 = mul_int(rgba_1, rgba_1);
printf("%d %d %d %d : %u 0x%08x
\n
", red, green, blue, alpha, rgba_3, rgba_3);
}
```
출력 결과
```
input 4 values with 0~255 : 127 127 127 127
127 127 127 127 : 2139062143 0x7f7f7f7f
127 127 127 127 : 1061109567 0x3f3f3f3f
127 127 127 127 : 1061109567 0x3f3f3f3f
```
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