add @format and @interpretation to rawload

This commit is contained in:
John Cupitt 2019-09-05 16:25:55 +01:00
parent f09bd91f69
commit dd9eba9e26
2 changed files with 52 additions and 12 deletions

View File

@ -11,7 +11,9 @@
- add vips_switch() / vips_case() ... fast many-way ifthenelse
- better const handling for arithmetic operators fixes comparisons against out
of range values
- sharpen restores input colourspace
- handle alpha in heifload / heifsave [meyermarcel]
- add @interpretation and @format to rawload
31/8/19 started 8.8.3
- revert sharpen restoring the input colourspace

View File

@ -1,6 +1,8 @@
/* load raw data from a file
*
* 14/12/11
* 5/8/19
* - add @format and @interpretation
*/
/*
@ -53,6 +55,8 @@ typedef struct _VipsForeignLoadRaw {
int height;
int bands;
guint64 offset;
VipsBandFormat format;
VipsInterpretation interpretation;
} VipsForeignLoadRaw;
typedef VipsForeignLoadClass VipsForeignLoadRawClass;
@ -76,20 +80,34 @@ static int
vips_foreign_load_raw_header( VipsForeignLoad *load )
{
VipsForeignLoadRaw *raw = (VipsForeignLoadRaw *) load;
VipsImage *out;
VipsImage *out2;
if( !(out2 = vips_image_new_from_file_raw( raw->filename,
raw->width, raw->height, raw->bands, raw->offset )) )
VipsImage *out;
VipsImage *x;
if( !(out = vips_image_new_from_file_raw( raw->filename,
raw->width, raw->height,
vips_format_sizeof_unsafe( raw->format ) * raw->bands,
raw->offset )) )
return( -1 );
if( vips_copy( out, &x,
"interpretation", raw->interpretation,
"format", raw->format,
"bands", raw->bands,
NULL ) ) {
g_object_unref( out );
return( -1 );
}
g_object_unref( out );
out = x;
/* Remove the @out that's there now.
*/
g_object_get( load, "out", &out, NULL );
g_object_unref( out );
g_object_unref( out );
g_object_get( load, "out", &x, NULL );
g_object_unref( x );
g_object_unref( x );
g_object_set( load, "out", out2, NULL );
g_object_set( load, "out", out, NULL );
return( 0 );
}
@ -147,11 +165,27 @@ vips_foreign_load_raw_class_init( VipsForeignLoadRawClass *class )
G_STRUCT_OFFSET( VipsForeignLoadRaw, offset ),
0, 100000000000, 0 );
VIPS_ARG_ENUM( class, "format", 24,
_( "Format" ),
_( "Pixel format in image" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadRaw, format ),
VIPS_TYPE_BAND_FORMAT, VIPS_FORMAT_UCHAR );
VIPS_ARG_ENUM( class, "interpretation", 25,
_( "Interpretation" ),
_( "Pixel interpretation" ),
VIPS_ARGUMENT_OPTIONAL_INPUT,
G_STRUCT_OFFSET( VipsForeignLoadRaw, interpretation ),
VIPS_TYPE_INTERPRETATION, VIPS_INTERPRETATION_MULTIBAND );
}
static void
vips_foreign_load_raw_init( VipsForeignLoadRaw *raw )
{
raw->format = VIPS_FORMAT_UCHAR;
raw->interpretation = VIPS_INTERPRETATION_MULTIBAND;
}
/**
@ -166,14 +200,18 @@ vips_foreign_load_raw_init( VipsForeignLoadRaw *raw )
* Optional arguments:
*
* * @offset: %guint64, offset in bytes from start of file
* * @format: #VipsBandFormat, set image format
* * @interpretation: #VipsInterpretation, set image interpretation
*
* This operation mmaps the file, setting up @out so that access to that
* image will read from the file.
*
* @out will be a 8-bit uchar image with @bands image bands, so @bands can
* be thought of as meaning "number of bytes per pixel". Use functions
* like vips_copy() to set the exact band format, number of bands,
* and so on. Use vips_byteswap() to reverse the byte ordering.
* By default, it assumes uchar pixels. Use @format to select something else.
*
* The image will be tagged as #VIPS_INTERPRETATION_MULTIBAND. Use
* @interpretation to select something else.
*
* Use vips_byteswap() to reverse the byte ordering if necessary.
*
* See also: vips_image_new_from_file(), vips_copy(), vips_byteswap().
*