| 902 | } |
| 903 | |
| 904 | int bmpread(const char * bmp_file, unsigned int flags, bmpread_t * p_bmp_out) |
| 905 | { |
| 906 | int success = 0; |
| 907 | |
| 908 | read_context ctx; |
| 909 | memset(&ctx, 0, sizeof(ctx)); |
| 910 | |
| 911 | do |
| 912 | { |
| 913 | if(!bmp_file) break; |
| 914 | if(!p_bmp_out) break; |
| 915 | memset(p_bmp_out, 0, sizeof(*p_bmp_out)); |
| 916 | |
| 917 | ctx.flags = flags; |
| 918 | |
| 919 | if(!(ctx.fp = fopen(bmp_file, "rb"))) break; |
| 920 | if(!Validate(&ctx)) break; |
| 921 | if(!Decode(&ctx)) break; |
| 922 | |
| 923 | /* Finally, make sure we can stuff these into ints. I feel like this |
| 924 | * is slightly justified by how it keeps the header definition dead |
| 925 | * simple (including, well, no #includes). I suppose this could also |
| 926 | * be done way earlier and maybe save some disk reads, but I like |
| 927 | * keeping the check with the code it's checking. |
| 928 | */ |
| 929 | #if INT32_MAX > INT_MAX |
| 930 | if(ctx.info.width > INT_MAX) break; |
| 931 | if(ctx.lines > INT_MAX) break; |
| 932 | #endif |
| 933 | |
| 934 | p_bmp_out->width = ctx.info.width; |
| 935 | p_bmp_out->height = ctx.lines; |
| 936 | p_bmp_out->flags = ctx.flags; |
| 937 | p_bmp_out->data = ctx.data_out; |
| 938 | |
| 939 | success = 1; |
| 940 | } while(0); |
| 941 | |
| 942 | FreeContext(&ctx, success); |
| 943 | |
| 944 | return success; |
| 945 | } |
| 946 | |
| 947 | void bmpread_free(bmpread_t * p_bmp) |
| 948 | { |
no test coverage detected