Commit af0df35f authored by Lee Shallis's avatar Lee Shallis
Browse files

Moved some code to a more appropriate place, found out that last of the

test filter images does not currently display correctly, consulting
forums about it
parent ed6cd553
......@@ -4,6 +4,7 @@
#include "buff/common.h"
#include "path/common.h"
#include "view/png.h"
#include "view/ppm.h"
#include <cglm/struct.h>
#include <cglm/cglm.h>
#include <cglm/call.h>
......
......@@ -544,39 +544,12 @@ int ProcessArgv( int argc, char **argv )
return 0;
}
int SaveImagePPM( IMAGE *Image, FILE *file )
uintmax_t ScaleDepthWithoutFPN( uint dstDepth, uint srcDepth, uintmax_t value )
{
ulong Rows = Image->Rows, row;
ulong Cols = Image->Cols, col, i;
ulong keep = ~(~0UL << (Image->Depth + 8));
fprintf( file, "P3\n%lu %lu\n%u\n", Cols, Rows, 255 );
for ( row = 0; row < Rows; ++row )
{
char * whitespace = "\n";
for ( col = 0; col < Cols; ++col )
{
for ( i = 0; i < IMAGE_CHANNEL_A; ++i )
{
ulong index = ImagePixelX( Image, row, col );
ulong value = *ImagePixel( Image, index, i );
ulong scale = value ? keep / value : 0;
if ( scale )
value = 0xFFFF / scale;
fprintf( file, "%s%5lu", whitespace, value );
whitespace = " ";
}
}
}
fputc('\n', file );
fflush( file );
return 0;
uintmax_t limit = 0, scale;
limit = ~(~limit << (srcDepth + dstDepth));
scale = value ? limit / value : 0;
return scale ? limit / scale : 0;
}
int main( int argc, char *argv[] )
......@@ -654,7 +627,7 @@ int main( int argc, char *argv[] )
return EXIT_FAILURE;
}
SaveImagePPM( &Image, pic_ppm );
SaveImagePPM( pic_ppm, &Image );
fclose( pic_ppm );
......
......@@ -4,5 +4,76 @@
#include "../buff/common.h"
#include "../buff/zlib.h"
#include "../path/common.h"
#include <math.h>
typedef struct _CHUNK
{
ulong Size;
char Type[8];
int DataID;
ulong CRC;
} CHUNK;
typedef enum _IMAGE_CHANNELS
{
IMAGE_CHANNEL_R = 0,
IMAGE_CHANNEL_G,
IMAGE_CHANNEL_B,
IMAGE_CHANNEL_A,
IMAGE_CHANNEL_COUNT
} IMAGE_CHANNELS;
#define IMAGE_CLUT_GREYSCALE 0
#define IMAGE_CLUT_TRUECOLOR 2
#define IMAGE_CLUT_PALETTEPOS 3
#define IMAGE_CLUT_GREYSCALEA 4
#define IMAGE_CLUT_TRUECOLORA 6
typedef struct _IMAGE
{
uchar Depth;
uchar Flags;
uchar CMethod;
uchar FMethod;
uchar IMethod;
time_t LastChanged;
float GammaF;
ulong GammaU, Pixels, Cols, Rows;
ulong sBIT, sBITr, sBITg, sBITb;
BIN_FILE BinFile;
/* Buffer IDs */
int ViewID, DataID, FileID, MainDyesID, MiscDyesID;
BUFFERS *Buffers;
SERIES Chunks;
} IMAGE;
IMAGE *SetupImage( IMAGE *Image, BUFFERS *Buffers, tch const * const path );
void EmptyImage( IMAGE *Image );
void EchoImageDetails( FILE *file, IMAGE *Image );
CHUNK * FindNextChunk( IMAGE *Image, char const *desc, int start );
/*Use with the below functions to get equivalant of raw_ptr + pixel */
ulong * ImagePixel( IMAGE *Image, ulong pixel, IMAGE_CHANNELS channel );
/* Adds any offset/s to produce the index for channel 0 of said pixel */
#define ImageRows(IMAGE) ((IMAGE)->Rows)
#define ImageCols(IMAGE) ((IMAGE)->Cols)
#define ImagePfxRows 2
#define ImagePfxCols 1
#define ImageRowOffest(IMAGE,ROW) ((ROW) * (ImageCols(IMAGE) + ImagePfxCols))
#define ImagePixelX(IMAGE, ROW, COL ) \
(ImageRowOffest(IMAGE,(ROW)+ImagePfxRows) + (COL))
/* Adds any offset/s for local pixel indices, index 0 is used for nil, do NOT
* fill that index */
#define ImagePixelA(IMAGE, ROW, COL ) \
(ImagePixelX(IMAGE,ROW,COL) - 1)
#define ImagePixelB(IMAGE, ROW, COL ) \
((ImagePixelX(IMAGE,ROW,COL) - ImageCols(IMAGE)) - ImagePfxCols)
#define ImagePixelC(IMAGE, ROW, COL ) \
(ImagePixelB(IMAGE,ROW,COL) - 1)
#endif
......@@ -680,7 +680,7 @@ int ScanLines( IMAGE *Image )
for ( row = 0, pixel = 0; row < Rows; ++row )
{
ulong filter = ImageValueFromIDAT( Image, &pos, depth );
ulong filter = ImageValueFromIDAT( Image, &pos, 8 );
for ( col = 0; col < Cols; ++col, ++pixel )
{
......
......@@ -2,77 +2,7 @@
#define IMAGE_H
#include "common.h"
#include <math.h>
typedef struct _CHUNK
{
ulong Size;
char Type[8];
int DataID;
ulong CRC;
} CHUNK;
#define IMAGE_CLUT_GREYSCALE 0
#define IMAGE_CLUT_TRUECOLOR 2
#define IMAGE_CLUT_PALETTEPOS 3
#define IMAGE_CLUT_GREYSCALEA 4
#define IMAGE_CLUT_TRUECOLORA 6
typedef struct _IMAGE
{
uchar Depth;
uchar Flags;
uchar CMethod;
uchar FMethod;
uchar IMethod;
time_t LastChanged;
float GammaF;
ulong GammaU, Pixels, Cols, Rows;
ulong sBIT, sBITr, sBITg, sBITb;
BIN_FILE BinFile;
/* Buffer IDs */
int ViewID, DataID, FileID, MainDyesID, MiscDyesID;
BUFFERS *Buffers;
SERIES Chunks;
} IMAGE;
IMAGE *SetupImage( IMAGE *Image, BUFFERS *Buffers, tch const * const path );
int LoadImagePNG( IMAGE *Image, bool loopUntilRdAll );
void EmptyImage( IMAGE *Image );
void EchoImageDetails( FILE *file, IMAGE *Image );
CHUNK * FindNextChunk( IMAGE *Image, char const *desc, int start );
typedef enum _IMAGE_CHANNELS
{
IMAGE_CHANNEL_R = 0,
IMAGE_CHANNEL_G,
IMAGE_CHANNEL_B,
IMAGE_CHANNEL_A,
IMAGE_CHANNEL_COUNT
} IMAGE_CHANNELS;
/*Use with the below functions to get equivalant of raw_ptr + pixel */
ulong * ImagePixel( IMAGE *Image, ulong pixel, IMAGE_CHANNELS channel );
/* Adds any offset/s to produce the index for channel 0 of said pixel */
#define ImageRows(IMAGE) ((IMAGE)->Rows)
#define ImageCols(IMAGE) ((IMAGE)->Cols)
#define ImagePfxRows 2
#define ImagePfxCols 1
#define ImageRowOffest(IMAGE,ROW) ((ROW) * (ImageCols(IMAGE) + ImagePfxCols))
#define ImagePixelX(IMAGE, ROW, COL ) \
(ImageRowOffest(IMAGE,(ROW)+ImagePfxRows) + (COL))
/* Adds any offset/s for local pixel indices, index 0 is used for nil, do NOT
* fill that index */
#define ImagePixelA(IMAGE, ROW, COL ) \
(ImagePixelX(IMAGE,ROW,COL) - 1)
#define ImagePixelB(IMAGE, ROW, COL ) \
((ImagePixelX(IMAGE,ROW,COL) - ImageCols(IMAGE)) - ImagePfxCols)
#define ImagePixelC(IMAGE, ROW, COL ) \
(ImagePixelB(IMAGE,ROW,COL) - 1)
#endif
#include "ppm.h"
int SaveImagePPM( FILE *file, IMAGE *Image )
{
ulong Rows = Image->Rows, row;
ulong Cols = Image->Cols, col, i;
fprintf( file, "P3\n%lu %lu\n%lu\n", Cols, Rows, ~(~0UL << Image->Depth) );
for ( row = 0; row < Rows; ++row )
{
char * whitespace = "\n";
for ( col = 0; col < Cols; ++col )
{
for ( i = 0; i < IMAGE_CHANNEL_A; ++i )
{
ulong index = ImagePixelX( Image, row, col );
ulong value = *ImagePixel( Image, index, i );
fprintf( file, "%s%5lu", whitespace, value );
whitespace = " ";
}
}
}
fputc('\n', file );
fflush( file );
return 0;
}
#ifndef IMAGE_PPM_H
#define IMAGE_PPM_H
#include "common.h"
int SaveImagePPM( FILE *file, IMAGE *Image );
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment