home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2001 May
/
VPR0105A.BIN
/
OLS
/
BR98211
/
br98211.lzh
/
JPG6CDB.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
2000-04-25
|
4KB
|
168 lines
// JPEG Loader for Browser Return Ver2
// Copyright (C) AsakaSoft 2000
// this software is based in part on the work of the Independent JPEG Group.
//
#include <stdio.h>
#include <dos.h>
#include <mem.h>
extern "C" {
#include "jpeglib.h"
}
typedef unsigned int uint;
typedef unsigned char uchar;
uchar pbuf[4][640/8];
uchar nsw = 0;
void pinit ( void );
void pset ( uint x, uchar r, uchar g, uchar b, uchar dx, uchar dy );
void psetg ( uint x, uint gray, uchar dx, uchar dy );
void pwrite ( JDIMENSION w, /*uint y,*/ FILE *cfp );
/*uchar pat[4][4] = {
1, 10, 3, 12,
14, 5, 16, 7,
4, 13, 2, 11,
17, 9, 15, 6 };
*/
uchar pat[4][4] = {
16, 7, 14, 5,
3, 12, 1, 10,
13, 4, 15, 6,
0, 8, 2, 11 };
main ( ) {
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
JSAMPARRAY buf;
JDIMENSION jx, jy, sl, i;
unsigned long lx, ly;
FILE *fp;
int row_stride;
FILE *cfp;
/* outportb ( 0x6a, 1 );
for ( i = 0 ; i < 8 ; i++ ) {
outportb ( 0xa8, i );
outportb ( 0xac, i*2 );
outportb ( 0xaa, i*2 );
outportb ( 0xae, i*2 );
outportb ( 0xa8, i + 8 );
outportb ( 0xac, i*2+1 );
outportb ( 0xaa, i*2+1 );
outportb ( 0xae, i*2+1 );
}
*/
cinfo.err = jpeg_std_error ( &jerr );
jpeg_create_decompress ( &cinfo );
// if ( **(_argv+2) == '/' ) nsw = 1;
fp = fopen ( *(_argv+1),"rb" );
if ( fp == NULL ) return ( 1 );
cfp = fopen ( *(_argv+2), "wb" );
if ( cfp == NULL ) {
fclose ( fp );
return ( 1 );
}
printf ( "JPEG Loader for AsakaSoft Browser Returns Ver2\nthis software is based in part on the work of the Independent JPEG Group.\n\nNow Loading %s\n", *(_argv+1) );
jpeg_stdio_src ( &cinfo, fp );
jpeg_read_header ( &cinfo, TRUE );
printf ( "Start Decompress...\r" );
jpeg_start_decompress ( &cinfo );
printf ( "Start Decompress...done.\n" );
jx = cinfo.output_width;
jy = cinfo.output_height;
lx = jx, ly = jy;
printf ( "X%lu Y%lu\n", lx, ly );
fwrite ( (void *)&lx, 4, 1, cfp );
fwrite ( (void *)&ly, 4, 1, cfp );
fputc ( 1, cfp );
row_stride = cinfo.output_width * cinfo.output_components;
buf = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
while ( cinfo.output_scanline < cinfo.output_height ) {
sl = cinfo.output_scanline;
jpeg_read_scanlines (&cinfo, buf, 1);
pinit ();
for ( i = 0 ; i < jx ; i++ ) {
if ( cinfo.output_components == 1 ) {
psetg ( i, buf[0][i], i&3, sl&3 );
} else {
pset ( i, buf[0][i*3], buf[0][i*3+1], buf[0][i*3+2], i&3, sl&3 );
}
}
pwrite ( jx, /*sl,*/ cfp );
printf ( "Scan %u/%u\r", sl, jy );
}
printf ( "Scan Complete.\n" );
jpeg_finish_decompress ( &cinfo );
jpeg_destroy_decompress ( &cinfo );
fclose ( fp );
fclose ( cfp );
return ( 0 );
}
void pinit ( void ) {
memset ( pbuf, 0, 640/8*4 );
}
void pset ( uint x, uchar r, uchar g, uchar b, uchar dx, uchar dy ) {
uchar s;
s = ( (uint)b*28 + (uint)r*77 + (uint)g*151 ) / 256;
psetg ( x, s, dx, dy );
}
void psetg ( uint x, uint gray, uchar dx, uchar dy ) {
uchar or[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
uchar bi, b2;
if ( x >= 640 ) return;
// gray = (uint)gray * 15 / 255;
/* b2 = gray % 17;
gray /= 17;
if ( b2 >= pat[dx][dy] ) gray++;
*/
gray = ( gray + pat[dx][dy] ) / 17;
if ( nsw ) gray = 15 - gray;
bi = x >> 3;
b2 = x & 7;
if ( gray & 1 ) pbuf[0][bi] |= or[b2];
if ( gray & 2 ) pbuf[1][bi] |= or[b2];
if ( gray & 4 ) pbuf[2][bi] |= or[b2];
if ( gray & 8 ) pbuf[3][bi] |= or[b2];
}
void pwrite ( JDIMENSION w, /*uint y,*/ FILE *cfp ) {
// uint gseg[4] = { 0xe000, 0xa800, 0xb000, 0xb800 };
uint i, j;
JDIMENSION x;
// if ( y >= 400 ) return;
x = ( w + 7 ) / 8;
if ( x > 80 ) x = 80;
for ( i = 0 ; i < 4; i++ ) {
// _fmemcpy ( MK_FP ( gseg[i], y * 80 ), pbuf[i], 80 );
fwrite ( pbuf[i], x, 1, cfp );
}
}