📄 sample.c
字号:
get_lines = 0;
while ((sImage.line_no - get_lines) > 0)
{
lines = sImage.line_no - get_lines;
if (lines>buffer_list.buf_line) lines = buffer_list.buf_line;
_settextposition(20,1);
_outtext("Scanning lines : ");
printf("%d%% \n ",((long)get_lines)*100/sImage.line_no);
sScan.Comm.func_code = STARTSCAN;
sScan.scan_control = 0;
sScan.scan_bytes = sImage.line_width;
sScan.scan_lines = lines;
sScan.processed_lines = 0;
sScan.number_of_buf = 1;
sScan.buf_list_ptr = (long)(&buffer_list);
SCNCall((char far *) &sScan);
if (sScan.Comm.error_code != 0) break;
switch (set_dev.filter)
{
case 0 : if (fwrite(img_buf, sImage.line_width, lines, fp) <= 0)
{
SCN_ABORT();
fclose(fp);
return(-1);
}
break;
case 1 : // change image data format into RGBRGBRGB...
if (IsAZ_LD == 0)
{ // change data format:RRRGGGBBB->RGBRGBRGB...
for (i = 0; i < lines; i++)
for (j = 0; j < sImage.line_width/3; j++)
{
mem_buf[i*sImage.line_width + 3*j] =
img_buf[i*sImage.line_width + j];
mem_buf[i*sImage.line_width + 3*j + 1] =
img_buf[i*sImage.line_width+sImage.line_width/3+j];
mem_buf[i*sImage.line_width + 3*j + 2] =
img_buf[i*sImage.line_width+2*sImage.line_width/3+j];
} }
else
{
rLD = gLD = bLD = 0;
r_index = g_index = b_index = 0;
i = 0;
// change data format: ???...???...???... -> RGBRGBRGB...
// In this case, the sequence of R,G,B lines is unknown
while (1)
{ // check if GREEN line
if (g_index<lines)
{
if (gLD < set_dev.G_LD) gLD++;
else
{
Qk_G += Pk_res;
if (Qk_G > MaxValue)
{
Qk_G -= MaxValue;
for (j = 0; j<sImage.line_width/3; j++)
mem_buf[g_index*sImage.line_width+3*j+1]
= img_buf[i*sImage.line_width/3+j];
g_index++;
i++;
if (i >= lines*3) break;
} } } // end of check GREEN line
// check if BLUE line
if (b_index < lines)
{
if (bLD < set_dev.B_LD) bLD++;
else
{
Qk_B += Pk_res;
if (Qk_B > MaxValue)
{
Qk_B -= MaxValue;
for (j = 0; j<sImage.line_width/3; j++)
mem_buf[b_index*sImage.line_width+3*j+2]
= img_buf[i*sImage.line_width/3+j];
b_index++;
i++;
if (i >= lines*3) break;
} } } // end of check BLUE line
// check if RED line
if (r_index < lines)
{
if (rLD < set_dev.R_LD) rLD++;
else
{
Qk_R += Pk_res;
if (Qk_R > MaxValue)
{
Qk_R -= MaxValue;
for (j = 0; j<sImage.line_width/3; j++)
mem_buf[r_index*sImage.line_width+3*j]
= img_buf[i*sImage.line_width/3+j];
r_index++;
i++;
if (i >= lines*3) break;
} } } // end of check RED line
} } // end of data format change
fwrite(mem_buf, sImage.line_width, lines, fp);
}
get_lines += lines;
}
fclose(fp);
SCNClose();
return (sScan.Comm.error_code);
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// To stop scanning and let scanner return to the //
// starting position. //
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SCN_ABORT()
{
if (SCNOpen() < 0) return -1;
sAbort.func_code = STOPSCAN;
SCNCall((char far *) &sAbort);
SCNClose();
return (sAbort.error_code);
}
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// Show temparay file in VGA mode //
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
show_image()
{
FILE *img_fp;
int i, j, k, j4;
unsigned char di;
unsigned int width, height, type;
unsigned char far *VideoPtr, x;
unsigned char MaskTable[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char VGAGrayTable[12]={0,1,2,3,4,5,6,7,8,9,10,11};
char VGA_Lut[16][3] =
{
0x00, 0x00, 0x00, /* RGB of gray 0 */
0x06, 0x06, 0x06, /* RGB of gray 1 */
0x0c, 0x0c, 0x0c, /* RGB of gray 2 */
0x12, 0x12, 0x12, /* RGB of gray 3 */
0x18, 0x18, 0x18, /* RGB of gray 4 */
0x1e, 0x1e, 0x1e, /* RGB of gray 5 */
0x24, 0x24, 0x24, /* RGB of gray 6 */
0x2a, 0x2a, 0x2a, /* RGB of gray 7 */
0x30, 0x30, 0x30, /* RGB of gray 8 */
0x35, 0x35, 0x35, /* RGB of gray 9 */
0x3a, 0x3a, 0x3a, /* RGB of gray 10 */
0x3f, 0x3f, 0x3f, /* RGB of gray 11 */
0x15, 0x15, 0x3f, /* RGB of red color */
0x15, 0x3f, 0x15, /* RGB of green color */
0x3f, 0x15, 0x15, /* RGB of blue color */
0x3f, 0x3f, 0x15, /* RGB of yellow color */
};
img_fp = fopen(tmp_file, "rb");
if (img_fp == NULL)
{
printf("Error image file !\n");
return 0;
}
fread(&type, 2, 1, img_fp);
fread(&width, 2, 1, img_fp);
fread(&height, 2, 1, img_fp);
_setvideomode(_VRES16COLOR);
if (type == IT_GRAY) // if gray , set VGA gray palette
{
inp(0x3da); // Write VGA palette
for (i = 0; i < 16; i ++)
{
outp(0x3c0, i);
outp(0x3c0, i);
}
outp(0x3c0, 0x12);
outp(0x3c0, 0xff);
inp(0x3da);
outp(0x3c0, 0x20);
outp(0x3c4, 2); // Enable all four Plane
outp(0x3c5, 0x0f);
outp(0x3c8, 0); // set look-up table
for (i = 0; i < 16; i ++)
{
outp(0x3c9, VGA_Lut[i][0]);
outp(0x3c9, VGA_Lut[i][1]);
outp(0x3c9, VGA_Lut[i][2]);
}
}
for (j = 0; j < height; j++)
{
if (type == IT_COLOR) //if color, using dither method
{
fread(img_buf, sizeof(char)*width*3, 1, img_fp);
j4 = j % 4;
for (i = 0; i < width*3; i++)
{
img_buf[i] >>= 4;
if (img_buf[i] > dither[j4][i/3%4]) img_buf[i] = 1;
else img_buf[i] = 0;
}
for (i = 0; i < width; i++)
{
_setcolor(img_buf[i*3]*4+img_buf[i*3+1]*2+img_buf[i*3+2]+8);
_setpixel(i, j);
} }
else if (type == IT_GRAY) // if gray , show it in grayscale
{
_disable();
FP_SEG(VideoPtr) = VGASEG;
FP_OFF(VideoPtr) = j * 80;
outp(SequenCtlPort, 2); // Enable All Four Color Planes
outp(SequenDataPort, 0x0f);
outp(VGACtlPort , 0); // Write Set-Reset register
outp(VGADataPort, 0);
outp(VGACtlPort , 1);
outp(VGADataPort, 0);
outp(VGACtlPort , 5); // Set write Mode 2
outp(VGADataPort, 2);
outp(VGACtlPort , 8); // Set bit-mask register
fread(img_buf, width, 1, img_fp);
k=0;
for (i = 0; i < width; i ++)
{
outp(VGADataPort, MaskTable[k]); // Set Mask Register
x = *VideoPtr;
if (img_buf[i] > 200)
*VideoPtr = VGAGrayTable[11];
else if (img_buf[i] < 50 )
*VideoPtr = VGAGrayTable[0];
else if (img_buf[i] < 65 )
*VideoPtr = VGAGrayTable[1];
else if (img_buf[i] < 80 )
*VideoPtr = VGAGrayTable[2];
else if (img_buf[i] < 95 )
*VideoPtr = VGAGrayTable[3];
else if (img_buf[i] < 110)
*VideoPtr = VGAGrayTable[4];
else if (img_buf[i] < 125)
*VideoPtr = VGAGrayTable[5];
else if (img_buf[i] < 140)
*VideoPtr = VGAGrayTable[6];
else if (img_buf[i] < 155)
*VideoPtr = VGAGrayTable[7];
else if (img_buf[i] < 170)
*VideoPtr = VGAGrayTable[8];
else if (img_buf[i] < 185)
*VideoPtr = VGAGrayTable[9];
else
*VideoPtr = VGAGrayTable[10];
k++;
if (k == 8) { k = 0; VideoPtr++; }
}
outp(VGACtlPort, 5); // Set write MODE 0
outp(VGADataPort, 00);
outp(VGACtlPort, 8); // Set bit-mask register
outp(VGADataPort, 0xFF);
_enable();
}
else // if binary , show it in binary mode
{
_setcolor(15);
fread(img_buf, width, 1, img_fp);
for (i = 0; i < width * 8; i++)
if ((img_buf[i/8]&(1<<(7-i%8)))!=0) _setpixel(i, j);
} }
fclose(img_fp);
getch();
_setvideomode(_DEFAULTMODE);
unlink(tmp_file);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -