├── main.cpp
├── bmp_utils.c
├── bmp_utils.h
├── rgb2yuv.h
├── yuv2rgb.c
├── yuv2rgb.h
├── make_yuv
├── main.cpp
├── file_utils.c
├── file_utils.h
├── readme.txt
├── fill_yuvdata.c
├── fill_yuvdata.h
└── Makefile
├── yuvfile
├── colorbar_cif_yuv422p.yuv
├── suzie_qcif_yuv420p_00.yuv
├── tempete_cif_yuv420p_00.yuv
├── container_qcif_yuv420p_00.yuv
├── tulips_yuv420_prog_planar_qcif.yuv
└── tulips_yuv422_prog_planar_qcif.yuv
├── yuvrgb.vcxproj.user
├── README
├── yuvrgb.sln
├── LICENSE
├── yuvrgb.vcxproj.filters
├── yuvrgb.vcproj
├── Makefile
├── yuvrgb.vcxproj
└── rgb2yuv.c
/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/main.cpp
--------------------------------------------------------------------------------
/bmp_utils.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/bmp_utils.c
--------------------------------------------------------------------------------
/bmp_utils.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/bmp_utils.h
--------------------------------------------------------------------------------
/rgb2yuv.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/rgb2yuv.h
--------------------------------------------------------------------------------
/yuv2rgb.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuv2rgb.c
--------------------------------------------------------------------------------
/yuv2rgb.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuv2rgb.h
--------------------------------------------------------------------------------
/make_yuv/main.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/make_yuv/main.cpp
--------------------------------------------------------------------------------
/make_yuv/file_utils.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/make_yuv/file_utils.c
--------------------------------------------------------------------------------
/make_yuv/file_utils.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/make_yuv/file_utils.h
--------------------------------------------------------------------------------
/make_yuv/readme.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/make_yuv/readme.txt
--------------------------------------------------------------------------------
/make_yuv/fill_yuvdata.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/make_yuv/fill_yuvdata.c
--------------------------------------------------------------------------------
/make_yuv/fill_yuvdata.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/make_yuv/fill_yuvdata.h
--------------------------------------------------------------------------------
/yuvfile/colorbar_cif_yuv422p.yuv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuvfile/colorbar_cif_yuv422p.yuv
--------------------------------------------------------------------------------
/yuvfile/suzie_qcif_yuv420p_00.yuv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuvfile/suzie_qcif_yuv420p_00.yuv
--------------------------------------------------------------------------------
/yuvfile/tempete_cif_yuv420p_00.yuv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuvfile/tempete_cif_yuv420p_00.yuv
--------------------------------------------------------------------------------
/yuvfile/container_qcif_yuv420p_00.yuv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuvfile/container_qcif_yuv420p_00.yuv
--------------------------------------------------------------------------------
/yuvfile/tulips_yuv420_prog_planar_qcif.yuv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuvfile/tulips_yuv420_prog_planar_qcif.yuv
--------------------------------------------------------------------------------
/yuvfile/tulips_yuv422_prog_planar_qcif.yuv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/latelee/yuv2rgb/HEAD/yuvfile/tulips_yuv422_prog_planar_qcif.yuv
--------------------------------------------------------------------------------
/yuvrgb.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | yuv2rgb
2 | =======
3 |
4 | Convert yuv(yuv422p, yuv420p, yuv422sp, yuv420sp, etc) to rgb(save as bmp file), or vice versa.VS 2015 project.
5 |
6 | Windows: open yuvrgb.vcxproj file using vs 2015.
7 | Linux: make ; ./a.out
8 |
9 | Late Lee
10 |
11 | http://www.latelee.org
12 | latelee@163.com
13 |
--------------------------------------------------------------------------------
/yuvrgb.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "yuvrgb", "yuvrgb.vcxproj", "{4CCDBF90-E213-475E-87EA-17F822257EFA}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Win32 = Debug|Win32
9 | Release|Win32 = Release|Win32
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {4CCDBF90-E213-475E-87EA-17F822257EFA}.Debug|Win32.ActiveCfg = Debug|Win32
13 | {4CCDBF90-E213-475E-87EA-17F822257EFA}.Debug|Win32.Build.0 = Debug|Win32
14 | {4CCDBF90-E213-475E-87EA-17F822257EFA}.Release|Win32.ActiveCfg = Release|Win32
15 | {4CCDBF90-E213-475E-87EA-17F822257EFA}.Release|Win32.Build.0 = Release|Win32
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2021, Late Lee
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | 1. Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | 3. Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/yuvrgb.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 |
32 |
33 | Header Files
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 |
--------------------------------------------------------------------------------
/make_yuv/Makefile:
--------------------------------------------------------------------------------
1 | #
2 | # (C) Copyleft 2011 2012 2013
3 | # Late Lee from http://www.latelee.org
4 | #
5 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* directory
6 | #
7 | # note:
8 | # you can put head file(s) in 'include' directory, so it looks
9 | # a little neat.
10 | #
11 | # usage: $ make
12 | # $ make debug=y
13 | #
14 | # log
15 | # 2013-05-14 sth about debug...
16 | ###############################################################################
17 |
18 | # !!!=== cross compile...
19 | CROSS_COMPILE =
20 |
21 | CC = $(CROSS_COMPILE)gcc
22 | CXX = $(CROSS_COMPILE)g++
23 | AR = $(CROSS_COMPILE)ar
24 |
25 | ARFLAGS = cr
26 | RM = -rm -rf
27 | MAKE = make
28 |
29 | CFLAGS := -Wall
30 |
31 | #****************************************************************************
32 | # debug can be set to y to include debugging info, or n otherwise
33 | debug := y
34 |
35 | #****************************************************************************
36 |
37 | ifeq ($(debug), y)
38 | CFLAGS += -ggdb -rdynamic
39 | else
40 | CFLAGS += -O2 -s
41 | endif
42 |
43 | # !!!===
44 | DEFS =
45 |
46 | CFLAGS += $(DEFS)
47 |
48 | LDFLAGS := $(LIBS)
49 |
50 | # !!!===
51 | INCDIRS := -I./
52 |
53 | # !!!===
54 | CFLAGS += $(INCDIRS)
55 |
56 | # !!!===
57 | LDFLAGS +=
58 |
59 | # !!!===
60 | # source file(s), including c file(s) cpp file(s)
61 | # you can also use $(wildcard *.c), etc.
62 | SRC_C := $(wildcard *.c)
63 | SRC_CPP := $(wildcard *.cpp)
64 |
65 | # object file(s)
66 | OBJ_C := $(patsubst %.c,%.o,$(SRC_C))
67 | OBJ_CPP := $(patsubst %.cpp,%.o,$(SRC_CPP))
68 |
69 | # !!!===
70 | # executable file
71 | target = a.out
72 |
73 | ###############################################################################
74 |
75 | all: $(target)
76 |
77 | $(target): $(OBJ_C) $(OBJ_CPP)
78 | @echo "Generating executable file..." $(notdir $(target))
79 | @$(CXX) $(CFLAGS) $^ -o $(target) $(LDFLAGS)
80 |
81 | # make all .c or .cpp
82 | %.o: %.c
83 | @echo "Compiling: " $(addsuffix .c, $(basename $(notdir $@)))
84 | @$(CC) $(CFLAGS) -c $< -o $@
85 |
86 | %.o: %.cpp
87 | @echo "Compiling: " $(addsuffix .cpp, $(basename $(notdir $@)))
88 | @$(CXX) $(CFLAGS) -c $< -o $@
89 |
90 | clean:
91 | @echo "Cleaning..."
92 | @$(RM) $(target)
93 | @$(RM) *.o *.back *~
94 |
95 | .PHONY: all clean
96 |
--------------------------------------------------------------------------------
/yuvrgb.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
13 |
19 |
30 |
32 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
61 |
67 |
75 |
77 |
86 |
88 |
90 |
92 |
94 |
96 |
98 |
100 |
102 |
104 |
106 |
107 |
108 |
109 |
110 |
111 |
115 |
117 |
118 |
120 |
121 |
123 |
124 |
126 |
127 |
128 |
132 |
134 |
135 |
137 |
138 |
140 |
141 |
142 |
146 |
147 |
148 |
149 |
150 |
151 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # (C) Copyleft 2011 2012 2013 2014 2015 2016 2017 2018
2 | # Late Lee(li@latelee.org) from http://www.latelee.org
3 | #
4 | # A simple Makefile for *ONE* project(c or/and cpp file) in *ONE* or *MORE* directory
5 | #
6 | # note:
7 | # you can put head file(s) in 'include' directory, so it looks
8 | # a little neat.
9 | #
10 | # usage:
11 | # $ make
12 | # $ make V=1 # verbose ouput
13 | # $ make CROSS_COMPILE=arm-arago-linux-gnueabi- # cross compile for ARM, etc.
14 | # $ make debug=y # debug
15 | #
16 | # log
17 | # 2013-05-14 sth about debug...
18 | # 2016-02-29 sth for c/c++ multi diretory
19 | # 2017-04-17 -s for .a/.so if no debug
20 | # 2017-05-05 Add V for verbose ouput
21 | ###############################################################################
22 |
23 | # !!!=== cross compile...
24 | CROSS_COMPILE ?=
25 |
26 | MKDIR_P ?= mkdir -p
27 |
28 | CC = $(CROSS_COMPILE)gcc
29 | CXX = $(CROSS_COMPILE)g++
30 | AR = $(CROSS_COMPILE)ar
31 |
32 | # !!!===
33 | # in case all .c/.cpp need g++, specify CC=CXX...
34 | # CC = $(CXX)
35 |
36 | ARFLAGS = -cr
37 | RM = -rm -rf
38 | MAKE = make
39 |
40 | # !!!===
41 | # target executable file or .a or .so
42 | target = a.out
43 |
44 | # !!!===
45 | # compile flags
46 | CFLAGS += -Wall -Wfatal-errors -MMD
47 |
48 | # !!!=== pkg-config here
49 | #CFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib)
50 | #LDFLAGS += $(shell pkg-config --cflags --libs glib-2.0 gattlib)
51 |
52 | #****************************************************************************
53 | # debug can be set to y to include debugging info, or n otherwise
54 | debug = y
55 |
56 | #****************************************************************************
57 |
58 | ifeq ($(debug), y)
59 | CFLAGS += -ggdb -rdynamic
60 | else
61 | CFLAGS += -O2 -s
62 | endif
63 |
64 | # !!!===
65 | # Macros define here
66 | DEFS += -DJIMKENT
67 |
68 | # !!! compile flags define here...
69 | CFLAGS += $(DEFS)
70 | # !!! c++ flags
71 | CXXFLAGS = $(CFLAGS)
72 | # !!! library here...
73 | LIBS +=
74 | # !!! gcc/g++ link flags here
75 | LDFLAGS += $(LIBS) -lpthread -lrt
76 |
77 | # !!!===
78 | # include head file directory here
79 | INC = ./ ./inc
80 | # or try this
81 | #INC := $(shell find $(INC) -type d)
82 |
83 | # !!!===
84 | # build directory
85 | BUILD_DIR ?= #./build/
86 |
87 | # !!!===
88 | # source file(s), including ALL c file(s) or cpp file(s)
89 | # just need the directory.
90 | SRC_DIRS = .
91 | # or try this
92 | #SRC_DIRS = . ../outbox
93 |
94 | # !!!===
95 | # gcc/g++ compile flags
96 | CFLAGS += $(INCDIRS)
97 | CXXFLAGS += -std=c++11
98 |
99 | # dynamic library build flags
100 | DYNC_FLAGS += -fpic -shared
101 |
102 | # include directory(s)
103 | INCDIRS := $(addprefix -I, $(INC))
104 |
105 | # source file(s)
106 | SRCS := $(shell find $(SRC_DIRS) -maxdepth 1 -name '*.cpp' -or -name '*.c')
107 | # or try this
108 | #SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c')
109 |
110 | OBJS = $(patsubst %.c,$(BUILD_DIR)%.o, $(patsubst %.cpp,$(BUILD_DIR)%.o, $(SRCS)))
111 |
112 | # depend files(.d)
113 | DEPS := $(OBJS:.o=.d)
114 |
115 | ifeq ($(V),1)
116 | Q=
117 | NQ=true
118 | else
119 | Q=@
120 | NQ=echo
121 | endif
122 |
123 | ###############################################################################
124 |
125 | all: $(BUILD_DIR)$(target)
126 |
127 | $(BUILD_DIR)$(target): $(OBJS)
128 |
129 | ifeq ($(suffix $(target)), .so)
130 | @$(NQ) "Generating dynamic lib file..." $(notdir $(target))
131 | $(Q)$(CXX) $(CXXFLAGS) $^ -o $(target) $(LDFLAGS) $(DYNC_FLAGS)
132 | else ifeq ($(suffix $(target)), .a)
133 | @$(NQ) "Generating static lib file..." $(notdir $(target))
134 | $(Q)$(AR) $(ARFLAGS) -o $(target) $^
135 | else
136 | @$(NQ) "Generating executable file..." $(notdir $(target))
137 | $(Q)$(CXX) $(CXXFLAGS) $^ -o $(target) $(LDFLAGS)
138 | endif
139 |
140 | # make all .c or .cpp
141 | $(BUILD_DIR)%.o: %.c
142 | @$(MKDIR_P) $(dir $@)
143 | @$(NQ) "Compiling: " $(basename $(notdir $@)).c
144 | $(Q)$(CC) $(CFLAGS) -c $< -o $@
145 |
146 | $(BUILD_DIR)%.o: %.cpp
147 | @$(MKDIR_P) $(dir $@)
148 | @$(NQ) "Compiling: " $(basename $(notdir $@)).cpp
149 | $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@
150 |
151 | clean:
152 | @$(NQ) "Cleaning..."
153 | $(Q)$(RM) $(OBJS) $(target) $(DEPS)
154 | # delete build directory if needed
155 | ifneq ($(BUILD_DIR),)
156 | $(Q)$(RM) $(BUILD_DIR)
157 | endif
158 | # use 'grep -v soapC.o' to skip the file
159 | @find . -iname '*.o' -o -iname '*.bak' -o -iname '*.d' | xargs rm -f
160 |
161 | .PHONY: all clean
162 |
163 | -include $(DEPS)
--------------------------------------------------------------------------------
/yuvrgb.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 |
14 | {4CCDBF90-E213-475E-87EA-17F822257EFA}
15 | Win32Proj
16 |
17 |
18 |
19 | Application
20 | MultiByte
21 | v140
22 |
23 |
24 | Application
25 | MultiByte
26 | v140
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | <_ProjectFileVersion>10.0.30319.1
40 | Debug\
41 | Debug\
42 | true
43 | Release\
44 | Release\
45 | false
46 | AllRules.ruleset
47 |
48 |
49 | AllRules.ruleset
50 |
51 |
52 |
53 |
54 |
55 | Disabled
56 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
57 | true
58 | EnableFastChecks
59 | MultiThreadedDebug
60 |
61 |
62 | Level3
63 | EditAndContinue
64 |
65 |
66 | $(OutDir)yuvrgb.exe
67 | true
68 | $(OutDir)yuvrgb.pdb
69 | Console
70 | MachineX86
71 |
72 |
73 |
74 |
75 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
76 | MultiThreaded
77 |
78 |
79 | Level3
80 | ProgramDatabase
81 |
82 |
83 | $(OutDir)yuvrgb.exe
84 | true
85 | Console
86 | true
87 | true
88 | MachineX86
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
--------------------------------------------------------------------------------
/rgb2yuv.c:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | *
3 | * rgb2yuv.c, 24-bit RGB bitmap to YUV converter
4 | *
5 | * Copyright (C) 2001 Project Mayo
6 | *
7 | * Adam Li
8 | *
9 | * DivX Advance Research Center
10 | *
11 | **************************************************************************/
12 |
13 | #include
14 | #include "rgb2yuv.h"
15 |
16 | static int RGB2YUV_YR[256], RGB2YUV_YG[256], RGB2YUV_YB[256];
17 | static int RGB2YUV_UR[256], RGB2YUV_UG[256], RGB2YUV_UBVR[256];
18 | static int RGB2YUV_VG[256], RGB2YUV_VB[256];
19 |
20 | void init_lookup_table()
21 | {
22 | int i;
23 |
24 | for (i = 0; i < 256; i++) RGB2YUV_YR[i] = 65.481 * (i<<8);
25 | for (i = 0; i < 256; i++) RGB2YUV_YG[i] = 128.553 * (i<<8);
26 | for (i = 0; i < 256; i++) RGB2YUV_YB[i] = 24.966 * (i<<8);
27 | for (i = 0; i < 256; i++) RGB2YUV_UR[i] = 37.797 * (i<<8);
28 | for (i = 0; i < 256; i++) RGB2YUV_UG[i] = 74.203 * (i<<8);
29 | for (i = 0; i < 256; i++) RGB2YUV_VG[i] = 93.786 * (i<<8);
30 | for (i = 0; i < 256; i++) RGB2YUV_VB[i] = 8.214 * (i<<8);
31 | for (i = 0; i < 256; i++) RGB2YUV_UBVR[i] = 112 * (i<<8);
32 | }
33 |
34 | /************************************************************************
35 | *
36 | * int RGB2YUV420 (int x_dim, int y_dim,
37 | * unsigned char *bmp,
38 | * unsigned char *yuv, int flip)
39 | *
40 | * Purpose : It takes a 24-bit RGB bitmap and convert it into
41 | * YUV (4:2:0) format
42 | *
43 | * Input : x_dim the x dimension of the bitmap
44 | * y_dim the y dimension of the bitmap
45 | * bmp pointer to the buffer of the bitmap
46 | * yuv pointer to the YUV structure
47 | * flip 0: RGB order in bmp; 1: BGR order in bmp
48 | *
49 | *
50 | *
51 | ************************************************************************/
52 | int rgb24_to_yuv420 (int x_dim, int y_dim,
53 | unsigned char *bmp,
54 | unsigned char *yuv, int flip)
55 | {
56 | int i, j;
57 | unsigned char *r, *g, *b;
58 | unsigned char *y, *u, *v;
59 | unsigned char *uu, *vv;
60 | unsigned char *pu1, *pu2,*pu3,*pu4;
61 | unsigned char *pv1, *pv2,*pv3,*pv4;
62 |
63 | if(flip==0){
64 | r=bmp;
65 | g=bmp+1;
66 | b=bmp+2;
67 | }
68 | else{
69 | b=bmp;
70 | g=bmp+1;
71 | r=bmp+2;
72 | }
73 |
74 | y=yuv;
75 | //uu=new unsigned char[x_dim*y_dim];
76 | //vv=new unsigned char[x_dim*y_dim];
77 | uu = (unsigned char *)malloc(sizeof(char) * x_dim * y_dim);
78 | vv = (unsigned char *)malloc(sizeof(char) * x_dim * y_dim);
79 | u=uu;
80 | v=vv;
81 | for (i=0;i>16;
84 | *u++=(-RGB2YUV_UR[*r] -RGB2YUV_UG[*g]+RGB2YUV_UBVR[*b]+8388608)>>16;
85 | *v++=( RGB2YUV_UBVR[*r]-RGB2YUV_VG[*g]-RGB2YUV_VB[*b]+8388608)>>16;
86 |
87 | r+=3;
88 | g+=3;
89 | b+=3;
90 | }
91 | }
92 |
93 | //dimension reduction for U and V components
94 | u=yuv+x_dim*y_dim;
95 | v=u+x_dim*y_dim/4;
96 |
97 | pu1=uu;
98 | pu2=pu1+1;
99 | pu3=pu1+x_dim;
100 | pu4=pu3+1;
101 |
102 | pv1=vv;
103 | pv2=pv1+1;
104 | pv3=pv1+x_dim;
105 | pv4=pv3+1;
106 | for(i=0;i>2;
109 | *v++=(*pv1+*pv2+*pv3+*pv4)>>2;
110 | pu1+=2;
111 | pu2+=2;
112 | pu3+=2;
113 | pu4+=2;
114 | pv1+=2;
115 | pv2+=2;
116 | pv3+=2;
117 | pv4+=2;
118 | }
119 | pu1+=x_dim;
120 | pu2+=x_dim;
121 | pu3+=x_dim;
122 | pu4+=x_dim;
123 | pv1+=x_dim;
124 | pv2+=x_dim;
125 | pv3+=x_dim;
126 | pv4+=x_dim;
127 | }
128 | free(uu);
129 | free(vv);
130 | //delete []uu;
131 | //delete []vv;
132 | return 0;
133 | }
134 |
135 | #define SCALEBITS 8
136 | #define ONE_HALF (1 << (SCALEBITS - 1))
137 | #define FIX(x) ((int) ((x) * (1L<> SCALEBITS;
158 | r = p[3];
159 | g = p[4];
160 | b = p[5];
161 | r1 += r;
162 | g1 += g;
163 | b1 += b;
164 | lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
165 | p += wrap3;
166 | lum += wrap;
167 | r = p[0];
168 | g = p[1];
169 | b = p[2];
170 | r1 += r;
171 | g1 += g;
172 | b1 += b;
173 | lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g +FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
174 | r = p[3];
175 | g = p[4];
176 | b = p[5];
177 | r1 += r;
178 | g1 += g;
179 | b1 += b;
180 | lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g +FIX(0.11400) * b + ONE_HALF) >> SCALEBITS;
181 |
182 | cb[0] = (((- FIX(0.16874) * r1 - FIX(0.33126) * g1 +
183 | FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128);
184 | cr[0] = (((FIX(0.50000) * r1 - FIX(0.41869) * g1 -
185 | FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128);
186 | cb++;
187 | cr++;
188 | p += -wrap3+2 * 3;
189 | lum += -wrap + 2;
190 | }
191 | p += wrap3;
192 | lum += wrap;
193 | }
194 | }
--------------------------------------------------------------------------------