1 /* dlink350f.c
2 *
3 * orientation, byte order, and brightness correction for the D-Link 350F
4 *
5 * Copyright 2003 Mark Slemko <slemkom@users.sourceforge.net>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
21 */
22
23 #include "config.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include <gphoto2/gphoto2-library.h>
30 #include <gphoto2/gphoto2-port-log.h>
31
32 #define GP_MODULE "dlink350f"
33
34 #include "dlink350f.h"
35
36 #define RED(p,x,y,w) *((p)+3*((y)*(w)+(x)) )
37 #define GREEN(p,x,y,w) *((p)+3*((y)*(w)+(x))+1)
38 #define BLUE(p,x,y,w) *((p)+3*((y)*(w)+(x))+2)
39
40 #define SWAP(a,b) {unsigned char t=(a); (a)=(b); (b)=t;}
41
42 #define MINMAX(a,min,max) { (min)=MIN(min,a); (max)=MAX(max,a); }
43
44 #ifndef MAX
45 # define MAX(a, b) ((a) > (b) ? (a) : (b))
46 #endif
47 #ifndef MIN
48 # define MIN(a, b) ((a) < (b) ? (a) : (b))
49 #endif
50
51 /*
52 * function added for the D-Link DSC 350F - written by Mark Slemko - mslemko@netscape.net
53 * This function correctly adjusts the color and orientation of the image
54 */
dlink_dsc350f_postprocessing_and_flip_both(int width,int height,unsigned char * rgb)55 int dlink_dsc350f_postprocessing_and_flip_both (int width, int height, unsigned char* rgb) {
56 unsigned char *start, *end, c;
57
58 int whichcolor = 0;
59 int lowred=255, lowgreen=255, lowblue=255;
60 int hired=0, higreen=0, hiblue=0;
61
62 GP_DEBUG("flipping byte order");
63
64 /* flip image left/right and top/bottom (actually reverse byte order) */
65 start = rgb;
66 end = start + ((width * height) * 3);
67
68 while (start < end) {
69 c = *start;
70
71 /* validation - debugging info - collect the color range info
72 * for first half of image.
73 */
74 switch (whichcolor % 3) {
75 case 0: /* blue */
76 MINMAX((int)c,lowblue,hiblue);
77 break;
78 case 1: /* green */
79 MINMAX((int)c,lowgreen,higreen);
80 break;
81 default: /* red */
82 MINMAX((int)c,lowred,hired);
83 break;
84 }
85
86 /* adjust color magnitude, since it appears that the 350f only had 7 bits of color info */
87 *start++ = *--end << 1;
88 *end = c << 1;
89
90 whichcolor++;
91 }
92
93 /* could do more color processing here
94 GP_DEBUG("adjusting color");
95
96 // adjust image colours
97 start = rgb;
98 end = start + ((width * height) * 3);
99
100 while (start < end) {
101 c = *start++;
102 }
103 */
104
105 /* show the color range of image in debug mode. */
106 GP_DEBUG("\nred low = %d high = %d\ngreen low = %d high = %d\nblue low = %d high = %d\n", lowred,hired, lowgreen,higreen, lowblue,hiblue);
107 return GP_OK;
108 }
109