소스 검색

Wrote an Oric hires file parser.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2842 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam 16 년 전
부모
커밋
2f5dae2927
4개의 변경된 파일169개의 추가작업 그리고 3개의 파일을 삭제
  1. +6
    -3
      pipi/Makefile.am
  2. +6
    -0
      pipi/codec.c
  3. +154
    -0
      pipi/codec/oric.c
  4. +3
    -0
      pipi/pipi_internals.h

+ 6
- 3
pipi/Makefile.am 파일 보기

@@ -39,12 +39,13 @@ libpipi_la_CFLAGS = $(codec_cflags)
libpipi_la_LDFLAGS = $(codec_libs) \
-no-undefined -version-number @LT_VERSION@

# Conditional sources
# Submodules

codec_cflags =
codec_libs =
codec_sources =
codec_sources = \
codec/oric.c

# Submodules
paint_sources = \
paint/floodfill.c \
paint/line.c \
@@ -84,6 +85,8 @@ dither_sources = \
histogram_sources = \
histogram/histogram.c

# Conditional sources

if USE_SDL
codec_cflags += `sdl-config --cflags`
codec_libs += `sdl-config --libs` -lSDL_image


+ 6
- 0
pipi/codec.c 파일 보기

@@ -36,6 +36,9 @@ pipi_image_t *pipi_load(char const *name)
!strncmp(name, "bayer:", 6))
ret = pipi_load_stock(name);

if(!ret)
ret = pipi_load_oric(name);

#if USE_IMLIB2
if(!ret)
ret = pipi_load_imlib2(name);
@@ -91,6 +94,9 @@ int pipi_save(pipi_image_t *img, const char *name)
ret = pipi_save_gdi(img, name);
#endif

if(!ret)
ret = pipi_save_oric(img, name);

return ret;
}


+ 154
- 0
pipi/codec/oric.c 파일 보기

@@ -0,0 +1,154 @@
/*
* libpipi Proper image processing implementation library
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id$
*
* This library is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details.
*/

/*
* oric.c: Oric Atmos import/export functions
*/

#include "config.h"
#include "common.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "pipi.h"
#include "pipi_internals.h"

static int load_data(const char *name, uint8_t *screen);

pipi_image_t *pipi_load_oric(const char *name)
{
static uint8_t const pal[32] =
{
0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0xff, 0xff,
0x00, 0xff, 0x00, 0xff,
0x00, 0xff, 0xff, 0xff,
0xff, 0x00, 0x00, 0xff,
0xff, 0x00, 0xff, 0xff,
0xff, 0xff, 0x00, 0xff,
0xff, 0xff, 0xff, 0xff,
};

uint8_t screen[8000];
pipi_image_t *img;
pipi_pixels_t *p;
uint8_t *data;
int x, y, i;

if(load_data(name, screen) < 0)
return NULL;

img = pipi_new(240, 200);
p = pipi_getpixels(img, PIPI_PIXELS_RGBA_C);
data = p->pixels;

for(y = 0; y < 200; y++)
{
int bg = 0, fg = 7;

for(x = 0; x < 40; x++)
{
int col;
uint8_t c = screen[y * 40 + x];

if(c & 0x40)
{
for(i = 0; i < 6; i++)
{
col = (c & (1 << (5 - i))) ? (c & 0x80) ? 7 - fg : fg
: (c & 0x80) ? 7 - bg : bg;
memcpy(data + (y * 240 + x * 6 + i) * 4, pal + 4 * col, 4);
}
}
else if((c & 0x60) == 0x00)
{
if(c & 0x10)
bg = c & 0x7;
else
fg = c & 0x7;

col = (c & 0x80) ? 7 - bg : bg;

for(i = 0; i < 6; i++)
memcpy(data + (y * 240 + x * 6 + i) * 4, pal + 4 * col, 4);
}
/* else: invalid sequence */
}
}

img->codec_priv = NULL;

img->wrap = 0;
img->u8 = 1;

return img;
}

int pipi_save_oric(pipi_image_t *img, const char *name)
{
return -1;
}

/*
* XXX: The following functions are local.
*/

static int load_data(const char *name, uint8_t *screen)
{
FILE *fp;
int ch;

fp = fopen(name, "r");
if(!fp)
return -1;

/* Skip the sync bytes */
ch = fgetc(fp);
if(ch != 0x16)
goto syntax_error;
while((ch = fgetc(fp)) == 0x16)
;
if(ch != 0x24)
goto syntax_error;

/* Skip the header */
if(fgetc(fp) != 0x00 || fgetc(fp) != 0xff || fgetc(fp) != 0x80
|| fgetc(fp) != 0x00 || fgetc(fp) != 0xbf || fgetc(fp) != 0x3f
|| fgetc(fp) != 0xa0 || fgetc(fp) != 0x00 || fgetc(fp) != 0x00)
goto syntax_error;

/* Skip the file name */
for(;;)
{
ch = fgetc(fp);
if(ch == EOF)
goto syntax_error;
if(ch == 0x00)
break;
}

/* Read screen data */
if(fread(screen, 1, 8000, fp) != 8000)
goto syntax_error;

fclose(fp);
return 0;

syntax_error:
fclose(fp);
return -1;
}


+ 3
- 0
pipi/pipi_internals.h 파일 보기

@@ -85,5 +85,8 @@ pipi_image_t *pipi_load_gdi(const char *name);
int pipi_save_gdi(pipi_image_t *img, const char *name);
#endif

pipi_image_t *pipi_load_oric(const char *name);
int pipi_save_oric(pipi_image_t *img, const char *name);

#endif /* __PIPI_INTERNALS_H__ */


불러오는 중...
취소
저장