1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/* to sRGB from HSV
*
* 9/6/15
* - from sRGB2HSV.c
*/
/*
This file is part of VIPS.
VIPS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
/*
These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>
#include <stdio.h>
#include <math.h>
#include <vips/vips.h>
#include "pcolour.h"
#define SIXTH_OF_CHAR 42.5
typedef VipsColourCode VipsHSV2sRGB;
typedef VipsColourCodeClass VipsHSV2sRGBClass;
G_DEFINE_TYPE( VipsHSV2sRGB, vips_HSV2sRGB, VIPS_TYPE_COLOUR_CODE );
static void
vips_HSV2sRGB_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
{
unsigned char *p = (unsigned char *) in[0];
unsigned char *q = (unsigned char *) out;
int i;
for( i = 0; i < width; i++ ) {
float c, x, m;
c = p[2] * p[1] / 255.0;
x = c * (1 - VIPS_FABS( fmod( p[0] / SIXTH_OF_CHAR, 2 ) - 1 ));
m = p[2] - c;
if( p[0] < SIXTH_OF_CHAR ) {
q[0] = c + m;
q[1] = x + m;
q[2] = 0 + m;
}
else if( p[0] < 2 * SIXTH_OF_CHAR ) {
q[0] = x + m;
q[1] = c + m;
q[2] = 0 + m;
}
else if( p[0] < 3 * SIXTH_OF_CHAR ) {
q[0] = 0 + m;
q[1] = c + m;
q[2] = x + m;
}
else if( p[0] < 4 * SIXTH_OF_CHAR ) {
q[0] = 0 + m;
q[1] = x + m;
q[2] = c + m;
}
else if( p[0] < 5 * SIXTH_OF_CHAR ) {
q[0] = x + m;
q[1] = 0 + m;
q[2] = c + m;
}
else {
q[0] = c + m;
q[1] = 0 + m;
q[2] = x + m;
}
p += 3;
q += 3;
}
}
static void
vips_HSV2sRGB_class_init( VipsHSV2sRGBClass *class )
{
VipsObjectClass *object_class = (VipsObjectClass *) class;
VipsColourClass *colour_class = VIPS_COLOUR_CLASS( class );
object_class->nickname = "HSV2sRGB";
object_class->description = _( "transform HSV to sRGB" );
colour_class->process_line = vips_HSV2sRGB_line;
}
static void
vips_HSV2sRGB_init( VipsHSV2sRGB *HSV2sRGB )
{
VipsColour *colour = VIPS_COLOUR( HSV2sRGB );
VipsColourCode *code = VIPS_COLOUR_CODE( HSV2sRGB );
colour->interpretation = VIPS_INTERPRETATION_sRGB;
colour->format = VIPS_FORMAT_UCHAR;
colour->bands = 3;
colour->input_bands = 3;
code->input_coding = VIPS_CODING_NONE;
code->input_format = VIPS_FORMAT_UCHAR;
code->input_interpretation = VIPS_INTERPRETATION_HSV;
}
/**
* vips_HSV2sRGB:
* @in: input image
* @out: output image
* @...: %NULL-terminated list of optional named arguments
*
* Convert HSV to sRGB.
*
* HSV is a crude polar coordinate system for RGB images. It is provided for
* compatibility with other image processing systems. See vips_Lab2LCh() for a
* much better colour space.
*
* See also: vips_sRGB2HSV().
*
* Returns: 0 on success, -1 on error.
*/
int
vips_HSV2sRGB( VipsImage *in, VipsImage **out, ... )
{
va_list ap;
int result;
va_start( ap, out );
result = vips_call_split( "HSV2sRGB", ap, in, out );
va_end( ap );
return( result );
}
|