Skip to content

Commit

Permalink
add @Format and @Interpretation to rawload
Browse files Browse the repository at this point in the history
  • Loading branch information
jcupitt committed Sep 5, 2019
1 parent f09bd91 commit dd9eba9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 11 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -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
Expand Down
60 changes: 49 additions & 11 deletions libvips/foreign/rawload.c
@@ -1,6 +1,8 @@
/* load raw data from a file
*
* 14/12/11
* 5/8/19
* - add @format and @interpretation
*/

/*
Expand Down Expand Up @@ -53,6 +55,8 @@ typedef struct _VipsForeignLoadRaw {
int height;
int bands;
guint64 offset;
VipsBandFormat format;
VipsInterpretation interpretation;
} VipsForeignLoadRaw;

typedef VipsForeignLoadClass VipsForeignLoadRawClass;
Expand All @@ -76,20 +80,34 @@ static int
vips_foreign_load_raw_header( VipsForeignLoad *load )
{
VipsForeignLoadRaw *raw = (VipsForeignLoadRaw *) load;

VipsImage *out;
VipsImage *out2;
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( !(out2 = vips_image_new_from_file_raw( raw->filename,
raw->width, raw->height, raw->bands, raw->offset )) )
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 );
}
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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().
*
Expand Down

0 comments on commit dd9eba9

Please sign in to comment.