sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <sys/stat.h>
|
sl@0
|
19 |
#include <fcntl.h>
|
sl@0
|
20 |
#include <unistd.h>
|
sl@0
|
21 |
#include <stdlib.h>
|
sl@0
|
22 |
#include <stdio.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
#include <liboil/liboil.h>
|
sl@0
|
25 |
#include "liboil/liboilcolorspace.h"
|
sl@0
|
26 |
#include "jpeg.h"
|
sl@0
|
27 |
|
sl@0
|
28 |
#define LOG_FILE "c:\\logs\\examples_jpeg_rgb_log1.txt"
|
sl@0
|
29 |
#include "std_log_result.h"
|
sl@0
|
30 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
sl@0
|
31 |
|
sl@0
|
32 |
void create_xml(int result)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
if(result)
|
sl@0
|
35 |
assert_failed = 1;
|
sl@0
|
36 |
|
sl@0
|
37 |
testResultXml("examples_jpeg_rgb");
|
sl@0
|
38 |
close_log_file();
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
/* getfile */
|
sl@0
|
42 |
|
sl@0
|
43 |
void *getfile (char *path, int *n_bytes);
|
sl@0
|
44 |
static void dump_pnm (uint32_t *ptr, int rowstride, int width, int height);
|
sl@0
|
45 |
|
sl@0
|
46 |
int
|
sl@0
|
47 |
main (int argc, char *argv[])
|
sl@0
|
48 |
{
|
sl@0
|
49 |
unsigned char *data;
|
sl@0
|
50 |
int len;
|
sl@0
|
51 |
char *fn = "c:\\data\\liboil\\test.jpg";
|
sl@0
|
52 |
uint32_t *image = NULL;
|
sl@0
|
53 |
int width;
|
sl@0
|
54 |
int height;
|
sl@0
|
55 |
int ret;
|
sl@0
|
56 |
std_log(LOG_FILENAME_LINE, "Test Started examples_jpeg_rgb");
|
sl@0
|
57 |
|
sl@0
|
58 |
/*if (argc < 2) {
|
sl@0
|
59 |
printf("jpeg_rgb_test <file.jpg>\n");
|
sl@0
|
60 |
std_log(LOG_FILENAME_LINE,"jpeg_rgb_test <file.jpg>");
|
sl@0
|
61 |
exit(1);
|
sl@0
|
62 |
}*/
|
sl@0
|
63 |
if(argc > 1){
|
sl@0
|
64 |
fn = argv[1];
|
sl@0
|
65 |
}
|
sl@0
|
66 |
std_log(LOG_FILENAME_LINE,"fn = %s",fn);
|
sl@0
|
67 |
data = getfile (fn, &len);
|
sl@0
|
68 |
|
sl@0
|
69 |
if (data == NULL) {
|
sl@0
|
70 |
printf("cannot read file %s\n", fn);
|
sl@0
|
71 |
exit(1);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
ret = jpeg_decode_argb (data, len, &image, &width, &height);
|
sl@0
|
75 |
if (ret) {
|
sl@0
|
76 |
dump_pnm (image, width*4, width, height);
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
if (image) free (image);
|
sl@0
|
80 |
|
sl@0
|
81 |
free (data);
|
sl@0
|
82 |
|
sl@0
|
83 |
std_log(LOG_FILENAME_LINE, "Test Successful");
|
sl@0
|
84 |
create_xml(0);
|
sl@0
|
85 |
return 0;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
|
sl@0
|
89 |
|
sl@0
|
90 |
/* getfile */
|
sl@0
|
91 |
|
sl@0
|
92 |
void *
|
sl@0
|
93 |
getfile (char *path, int *n_bytes)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
int fd;
|
sl@0
|
96 |
struct stat st;
|
sl@0
|
97 |
void *ptr = NULL;
|
sl@0
|
98 |
int ret;
|
sl@0
|
99 |
std_log(LOG_FILENAME_LINE, "getfile ENTER");
|
sl@0
|
100 |
fd = open (path, O_RDONLY);
|
sl@0
|
101 |
if (!fd)
|
sl@0
|
102 |
return NULL;
|
sl@0
|
103 |
|
sl@0
|
104 |
ret = fstat (fd, &st);
|
sl@0
|
105 |
if (ret < 0) {
|
sl@0
|
106 |
close (fd);
|
sl@0
|
107 |
return NULL;
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
ptr = malloc (st.st_size);
|
sl@0
|
111 |
if (!ptr) {
|
sl@0
|
112 |
close (fd);
|
sl@0
|
113 |
return NULL;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
ret = read (fd, ptr, st.st_size);
|
sl@0
|
117 |
if (ret != st.st_size) {
|
sl@0
|
118 |
free (ptr);
|
sl@0
|
119 |
close (fd);
|
sl@0
|
120 |
return NULL;
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
if (n_bytes)
|
sl@0
|
124 |
*n_bytes = st.st_size;
|
sl@0
|
125 |
|
sl@0
|
126 |
close (fd);
|
sl@0
|
127 |
std_log(LOG_FILENAME_LINE, "getfile EXIT");
|
sl@0
|
128 |
return ptr;
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
static void
|
sl@0
|
132 |
dump_pnm (uint32_t *ptr, int rowstride, int width, int height)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
int x, y;
|
sl@0
|
135 |
|
sl@0
|
136 |
printf ("P3\n");
|
sl@0
|
137 |
printf ("%d %d\n", width, height);
|
sl@0
|
138 |
printf ("255\n");
|
sl@0
|
139 |
std_log(LOG_FILENAME_LINE, "P3");
|
sl@0
|
140 |
std_log(LOG_FILENAME_LINE, "%d %d",width, height);
|
sl@0
|
141 |
std_log(LOG_FILENAME_LINE, "255");
|
sl@0
|
142 |
|
sl@0
|
143 |
for (y = 0; y < height; y++) {
|
sl@0
|
144 |
for (x = 0; x < width; x++) {
|
sl@0
|
145 |
printf ("%d ", oil_argb_R(ptr[x]));
|
sl@0
|
146 |
printf ("%d ", oil_argb_G(ptr[x])); //Extracts the green component from color.Evaluates to the green component
|
sl@0
|
147 |
printf ("%d ", oil_argb_B(ptr[x]));
|
sl@0
|
148 |
std_log(LOG_FILENAME_LINE, "%d ",oil_argb_R(ptr[x]));
|
sl@0
|
149 |
std_log(LOG_FILENAME_LINE, "%d ",oil_argb_G(ptr[x]));
|
sl@0
|
150 |
std_log(LOG_FILENAME_LINE, "%d ",oil_argb_B(ptr[x]));
|
sl@0
|
151 |
if ((x & 15) == 15) {
|
sl@0
|
152 |
printf ("\n");
|
sl@0
|
153 |
}
|
sl@0
|
154 |
}
|
sl@0
|
155 |
printf ("\n");
|
sl@0
|
156 |
ptr += rowstride/4;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
}
|