📄 my_lib.c
字号:
#include "my_lib.h"BITMAP global_file_bitmap;unsigned char file_memory[100+(300*300*3)];char* sitoa(char* str, int val) { char* buf = str; int prev_print = 0; int c = val/100; if (c) { *buf++ = c+'0'; val = val - (c*100); prev_print = 1; } c = val/10; if (c || prev_print) { *buf++ = c+'0'; val = val - (c*10); prev_print = 1; } *buf++ = val +'0'; return buf;}unsigned char* write_header(unsigned char *filemem, int width, int height) { /* FILE* fptr = fopen("test.ppm", "w"); int i,j,k; int temp_data; int *datptr; fprintf(fptr, "P6\n%d %d\n%d\n",bmp->w,bmp->h,255); datptr = bmp->dat; for (i = 0 ; i < bmp->w * bmp->h; i++ ) { temp_data = *datptr; datptr++; fprintf(fptr, "%c%c%c", (unsigned char)(temp_data >> 16)&0xff, (unsigned char)(temp_data >> 8)&0xff, (unsigned char)temp_data&0xff); // if (i%16) // fprintf(fptr,"\n"); }*/ unsigned char* fptr = filemem; // fprintf(fptr, "P6\n%d %d\n%d\n",bmp->w,bmp->h,255); *fptr++ = 'P'; *fptr++ = '6'; *fptr++ = '\n'; fptr = sitoa(fptr, width); *fptr++ = ' '; fptr = sitoa(fptr, height); *fptr++ = '\n'; *fptr++ = '2'; *fptr++ = '5'; *fptr++ = '5'; *fptr++ = '\n'; return fptr;}/* create_bitmap_ex * Creates a new memory bitmap in the specified color_depth */BITMAP *create_bitmap_ex(int color_depth, int width, int height){ BITMAP *bitmap; int i; bitmap = &global_file_bitmap; if (!bitmap) return NULL; bitmap->dat = write_header(file_memory, width, height); bitmap->ppm_filesize = (bitmap->dat-file_memory) + (width*height*3);/* bitmap->dat = (int *)malloc(width * height*sizeof(int));// * BYTES_PER_PIXEL(color_depth)); if (!bitmap->dat) { free(bitmap); return NULL; }*/ bitmap->w = bitmap->cr = width; bitmap->h = bitmap->cb = height; bitmap->clip = TRUE; bitmap->cl = bitmap->ct = 0; // CHECK // bitmap->vtable = vtable; // bitmap->write_bank = bitmap->read_bank = _stub_bank_switch; bitmap->id = 0; bitmap->extra = NULL; bitmap->x_ofs = 0; bitmap->y_ofs = 0; // CHECK // bitmap->seg = _default_ds();/* bitmap->line[0] = bitmap->dat; for (i=1; i<height; i++) bitmap->line[i] = bitmap->line[i-1] + width * BYTES_PER_PIXEL(color_depth);*/ // if (system_driver->created_bitmap) // system_driver->created_bitmap(bitmap); return bitmap;}// CHANGED - fix thisvoid putpixel(BITMAP *bmp, int x, int y, int data) { int width = bmp->w; bmp->dat[(y*width*3) + (x*3)] = (unsigned char)(data >> 16)&0xff; bmp->dat[(y*width*3) + (x*3) + 1] = (unsigned char)(data >> 8)&0xff; bmp->dat[(y*width*3) + (x*3) + 2] = (unsigned char)(data)&0xff; // *( ((int*)bmp->dat)+(xx*yy)) = data;}void write_ppm(unsigned char* filemem, int size) {#ifdef NATIVE_COMPILE int i; FILE* fptr = fopen("test.ppm", "w"); for ( i = 0 ; i < size ; i++) { fprintf(fptr,"%c", *filemem++); } fclose(fptr);#else print("\n\rPPM file loc : "); putnum(filemem); print("\n\rPPM file size : "); putnum(size);
print("\n\rDone!\n\r");#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -