📄 mcraw_common.c
字号:
/*****************************************************************************/
/* Copyright 2000, Eastman Kodak Company */
/* All rights reserved */
/* File: "mcraw_common.c" */
/* Description: Function definitions for routines described by */
/* "mcraw_common.h" */
/* Author: Austin Lan */
/* Affiliation: Eastman Kodak Company */
/* Version: VM8.5 */
/* Last Revised: 11 September, 2000 */
/*****************************************************************************/
#include <image_io.h>
#include <local_services.h>
#include <stdio.h>
#include <stdlib.h>
#include "mcraw_common.h"
/* ========================================================================= */
/* ------------------------------ Static Globals --------------------------- */
/* ========================================================================= */
static char errTxt[80]; /* For holding error text */
/*****************************************************************************/
/* EXTERN readBxP */
/*****************************************************************************/
char *readBxP(void **buf, int rows, int cols, int bands, int file_byte_depth,
int data_org, int skip_bytes, int which_line, FILE *fp)
{
int i,j;
int seek_offset1, seek_offset2;
void *buf_p;
size_t num_read;
if (which_line >= rows) {
sprintf(errTxt, "\nreadBxP(): Line number out of range\n");
return errTxt;
}
if (data_org == BSQ) {
seek_offset1 = (cols * file_byte_depth * which_line + skip_bytes);
seek_offset2 = (cols * file_byte_depth * (rows - 1));
num_read = (cols * file_byte_depth);
if (fseek(fp, seek_offset1, SEEK_SET) == -1) {
sprintf(errTxt, "\nreadBxP(): fseek failed\n");
return errTxt;
}
for (i=0; i<bands; i++) {
buf_p = buf[i];
if (fread(buf_p, 1, num_read, fp) != num_read) {
sprintf(errTxt, "\nreadBxP(): fread failed\n");
return errTxt;
}
if (fseek(fp, seek_offset2, SEEK_CUR) == -1) {
sprintf(errTxt, "\nreadBxP(): fseek failed\n");
return errTxt;
}
}
} else if (data_org == BIL) {
buf_p = buf[0];
seek_offset1 = (bands * cols * file_byte_depth * which_line + skip_bytes);
num_read = (bands * cols * file_byte_depth);
if (fseek(fp, seek_offset1, SEEK_SET) == -1) {
sprintf(errTxt, "\nreadBxP(): fseek failed\n");
return errTxt;
}
if (fread(buf_p, 1, num_read, fp) != num_read) {
sprintf(errTxt, "\nreadBxP(): fread failed\n");
return errTxt;
}
} else if (data_org == BIP) {
void *temp_buf;
/* Read in PxB */
num_read = (cols * bands * file_byte_depth);
temp_buf = (void *) local_malloc(IMAGE_IO_MEM_KEY, num_read);
seek_offset1 = (cols * bands * file_byte_depth * which_line + skip_bytes);
if (fseek(fp, seek_offset1, SEEK_SET) == -1) {
sprintf(errTxt, "\nreadBxP(): fseek failed\n");
return errTxt;
}
if (fread(temp_buf, 1, num_read, fp) != num_read) {
sprintf(errTxt, "\nreadBxP(): fread failed\n");
return errTxt;
}
/* Transpose the data to get BxP */
if (file_byte_depth == 1) {
char *temp_buf_p = temp_buf;
for (i=0; i<cols; i++) {
for (j=0; j<bands; j++) {
((char **)buf)[j][i] = *temp_buf_p++;
}
}
} else if (file_byte_depth == 2) {
std_short *temp_buf_p = temp_buf;
for (i=0; i<cols; i++) {
for (j=0; j<bands; j++) {
((std_short **)buf)[j][i] = *temp_buf_p++;
}
}
} else if (file_byte_depth == 4) {
std_int *temp_buf_p = temp_buf;
for (i=0; i<cols; i++) {
for (j=0; j<bands; j++) {
((std_int **)buf)[j][i] = *temp_buf_p++;
}
}
} else {
sprintf(errTxt, "\nreadBxP(): Unsupported file byte depth\n");
return errTxt;
}
local_free((void *)temp_buf);
} else {
sprintf(errTxt, "\nreadBxP(): Unsupported data organization\n");
return errTxt;
}
return NULL;
}
/*****************************************************************************/
/* EXTERN writeBxP */
/*****************************************************************************/
char *writeBxP(void **buf, int rows, int cols, int bands, int file_byte_depth,
int data_org, int skip_bytes, int which_line, FILE *fp)
{
int i,j;
int seek_offset1, seek_offset2;
void *buf_p;
size_t num_write;
if (which_line >= rows) {
sprintf(errTxt, "\nwriteBxP(): Line number out of range\n");
return errTxt;
}
if (data_org == BSQ) {
seek_offset1 = (cols * file_byte_depth * which_line + skip_bytes);
seek_offset2 = (cols * file_byte_depth * (rows - 1));
num_write = (cols * file_byte_depth);
if (fseek(fp, seek_offset1, SEEK_SET) == -1) {
sprintf(errTxt, "\nwriteBxP(): fseek failed\n");
return errTxt;
}
for (i=0; i<bands; i++) {
buf_p = buf[i];
if (fwrite(buf_p, 1, num_write, fp) != num_write) {
sprintf(errTxt, "\nwriteBxP(): fwrite failed\n");
return errTxt;
}
if (fseek(fp, seek_offset2, SEEK_CUR) == -1) {
sprintf(errTxt, "\nwriteBxP(): fseek failed\n");
return errTxt;
}
}
} else if (data_org == BIL) {
buf_p = buf[0];
seek_offset1 = (bands * cols * file_byte_depth * which_line + skip_bytes);
num_write = (bands * cols * file_byte_depth);
if (fseek(fp, seek_offset1, SEEK_SET) == -1) {
sprintf(errTxt, "\nwriteBxP(): fseek failed\n");
return errTxt;
}
if (fwrite(buf_p, 1, num_write, fp) != num_write) {
sprintf(errTxt, "\nwriteBxP(): fwrite failed\n");
return errTxt;
}
} else if (data_org == BIP) {
void *temp_buf;
num_write = (cols * bands * file_byte_depth);
temp_buf = (void *) local_malloc(IMAGE_IO_MEM_KEY, num_write);
/* Transpose the data first */
if (file_byte_depth == 1) {
char *temp_buf_p = temp_buf;
for (i=0; i<cols; i++) {
for (j=0; j<bands; j++) {
*temp_buf_p++ = ((char **)buf)[j][i];
}
}
} else if (file_byte_depth == 2) {
std_short *temp_buf_p = temp_buf;
for (i=0; i<cols; i++) {
for (j=0; j<bands; j++) {
*temp_buf_p++ = ((std_short **)buf)[j][i];
}
}
} else if (file_byte_depth == 4) {
std_int *temp_buf_p = temp_buf;
for (i=0; i<cols; i++) {
for (j=0; j<bands; j++) {
*temp_buf_p++ = ((std_int **)buf)[j][i];
}
}
} else {
sprintf(errTxt, "\nwriteBxP(): Unsupported file byte depth\n");
return errTxt;
}
/* Perform write operation */
seek_offset1 = (cols * bands * file_byte_depth * which_line + skip_bytes);
if (fseek(fp, seek_offset1, SEEK_SET) == -1) {
sprintf(errTxt, "\nwriteBxP(): fseek failed\n");
return errTxt;
}
if (fwrite(temp_buf, 1, num_write, fp) != num_write) {
sprintf(errTxt, "\nwriteBxP(): fwrite failed\n");
return errTxt;
}
local_free((void *)temp_buf);
} else {
sprintf(errTxt, "\nwriteBxP(): Unsupported data organization\n");
return errTxt;
}
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -