3 changes: 2 additions & 1 deletion src/datasources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ endif()

kst_add_plugin(. ascii)
kst_add_plugin(. qimagesource)
kst_add_plugin(. sampledatasource)
#kst_add_plugin(. sampledatasource)
kst_add_plugin(. sourcelist)
kst_add_plugin(. bis)

if(getdata)
include_directories(${GETDATA_INCLUDE_DIR})
Expand Down
7 changes: 4 additions & 3 deletions src/datasources/ascii/asciidatainterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DataInterfaceAsciiVector : public DataSource::DataInterface<DataVector>
bool isValid(const QString& field) const { return ascii._fieldLookup.contains( field ); }

// T specific
const DataVector::DataInfo dataInfo(const QString&) const;
const DataVector::DataInfo dataInfo(const QString&, int frame = 0) const;
void setDataInfo(const QString&, const DataVector::DataInfo&) {}

// meta data
Expand All @@ -59,8 +59,9 @@ class DataInterfaceAsciiVector : public DataSource::DataInterface<DataVector>


//-------------------------------------------------------------------------------------------
const DataVector::DataInfo DataInterfaceAsciiVector::dataInfo(const QString &field) const
const DataVector::DataInfo DataInterfaceAsciiVector::dataInfo(const QString &field, int frame) const
{
Q_UNUSED(frame)
if (!ascii._fieldLookup.contains(field))
return DataVector::DataInfo();

Expand Down Expand Up @@ -124,7 +125,7 @@ class DataInterfaceAsciiString : public DataSource::DataInterface<DataString>
bool isValid(const QString&) const;

// T specific
const DataString::DataInfo dataInfo(const QString&) const { return DataString::DataInfo(); }
const DataString::DataInfo dataInfo(const QString&, int frame=0) const { Q_UNUSED(frame) return DataString::DataInfo(); }
void setDataInfo(const QString&, const DataString::DataInfo&) {}

// meta data
Expand Down
174 changes: 174 additions & 0 deletions src/datasources/bis/bis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/***************************************************************************
* *
* copyright : (C) 2015 C. Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

#include "bis.h"

char *BIS_ERRORSTR[] = {"OK", "Could not open file", "Unknown file format"};


BISfile *BISopen(char *filename) {
BISfile *bis;
int nr;
unsigned short us_in;

bis = (BISfile*) malloc(sizeof(BISfile));

bis->status = BIS_OK;

bis->fileName = malloc (strlen(filename)+1);

strcpy(bis->fileName,filename);

bis->fp = open(filename, O_RDONLY);

if (bis->fp<0) {
bis->status = BIS_NOOPEN;
return (bis);
}

nr = read(bis->fp, &us_in,2);
bis->formatType = us_in;
nr += read(bis->fp, &us_in,2);
bis->frameSize = us_in;

switch (bis->formatType) {
case 0xe6b0:
bis->imagesPerFrame = 5;
break;
default:
bis->status = BIS_UNKNOWN;
break;
}

return (bis);
}


void BISclose(BISfile *bis) {
if ((bis->fp>0) && (bis->status!=BIS_NOOPEN)) {
close(bis->fp);
}
free(bis);
}


/* initialize the image into a empty image, ready for use */
/* this is essentially a constructor, and should be called on */
/* any new bis image before use! */
void BISInitImage(BISimage *image) {
image->w = image->h = image->x = image->y = 0;
image->allocated = 0;
image->img = NULL;
}


/* free any memory allocated to the bis image */
/* note: the image is still valid and can be used again */
/* without calling BISInitImage */
void BISFreeImage(BISimage *image) {
if (image->img) {
free(image->img);
}
BISInitImage(image);
}


int isBISfile(char *filename) {
BISfile *bis;
int is_bis;

bis = BISopen(filename);
is_bis = (bis->status == BIS_OK);
BISclose(bis);

return (is_bis);
}

int BISnframes(BISfile *bis) {
int bytes;

bytes = lseek(bis->fp,0,SEEK_END);

if (bytes<0) bytes = 0;

if (bis->frameSize >0) {
//return (bytes);
return ((bytes-4)/bis->frameSize);
} else {
return 0;
}
}

int BISreadimage(BISfile *bis, int frame, int i_img, BISimage *I) {
int nframes;
unsigned short us_in[5];
int nr;
int img_size;

nframes = BISnframes(bis);
if (frame < 0) { // last frame
frame = nframes - 1;
}

if ((frame >= nframes) || (nframes<1)) { // can't read past end;
I->w = I->h = I->x = I->y = 0;
return 0;
}

if (i_img >= bis->imagesPerFrame) {
I->w = I->h = I->x = I->y = 0;
return 0;
}

// read the image offsets
lseek(bis->fp, frame*bis->frameSize+4, SEEK_SET);
nr = read(bis->fp, &us_in, 10); // read offsets
if ((nr!=10) || (us_in[i_img] <1)) {
I->w = I->h = I->x = I->y = 0;
return 0;
}

// Read the image size and position data
lseek(bis->fp, frame*bis->frameSize+4+us_in[i_img], SEEK_SET);
nr = read(bis->fp, &us_in, 8); // read offsets
if (nr!=8) {
I->w = I->h = I->x = I->y = 0;
return 0;
}
I->w = us_in[0];
I->h = us_in[1];
I->x = us_in[2];
I->y = us_in[3];

// read the image
img_size = I->w * I->h;
if (img_size > I->allocated) {
I->img = realloc(I->img, img_size+1);
I->allocated = img_size;
}

nr = read(bis->fp, I->img, img_size); // read image
if (nr != img_size) {
I->w = I->h = I->x = I->y = 0;
return 0;
}

return 1;
}

62 changes: 62 additions & 0 deletions src/datasources/bis/bis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/***************************************************************************
* *
* copyright : (C) 2015 C. Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef BIS_H
#define BIS_H

#ifdef __cplusplus
extern "C" {
#endif

#define BIS_OK 0
#define BIS_NOOPEN 1
#define BIS_UNKNOWN 2

extern char *BIS_ERRORSTR[];

typedef struct {
int fp;
char *fileName;
int status;
int frameSize;
int formatType;
int imagesPerFrame;
} BISfile;


typedef struct {
unsigned short w;
unsigned short h;
unsigned short x;
unsigned short y;
int allocated;
unsigned char *img;
} BISimage;

BISfile *BISopen(char *filename);
void BISclose(BISfile *bis);

int isBISfile(char *filename);

int BISnframes(BISfile *bis);

int BISreadimage(BISfile *bis, int frame, int i_img, BISimage *I);

void BISInitImage(BISimage *image);
void BISFreeImage(BISimage *image);


#ifdef __cplusplus
}
#endif

#endif
Loading