diff --git a/include/ffapi.h b/include/ffapi.h index 0f5e76a..e7dec64 100644 --- a/include/ffapi.h +++ b/include/ffapi.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -49,7 +50,6 @@ size_t ffapi_seek_frame (FFContext*, size_t offset, void (*progress)(size_t)) int ffapi_write_frame(FFContext*, AVFrame*); int ffapi_close(FFContext*); -// 8 bit only for now #define FFA_PEL(frame,comp,x,y) frame->data[comp.plane][y*frame->linesize[comp.plane]+x*comp.step+comp.offset] static inline void ffapi_setpel_direct(AVFrame* frame, size_t x, size_t y, AVComponentDescriptor comp, unsigned char val) { assert(comp.depth == 8); @@ -72,6 +72,17 @@ static inline void ffapi_setpell_direct(AVFrame* frame, size_t x, size_t y, AVCo default: (ffapi_setpel_direct)(AVFrame,x,y,comp, val)\ ) +static inline void ffapi_setpelf(FFContext* ctx, AVFrame* frame, size_t x, size_t y, int c, float val) { + AVComponentDescriptor comp = ctx->pixdesc->comp[c]; + assert(comp.depth == 32 && (ctx->pixdesc->flags & AV_PIX_FMT_FLAG_FLOAT)); + uint32_t valu = (union { float f; uint32_t u; }){val}.u; + uint8_t* data = &FFA_PEL(frame,comp,x,y); + if(ctx->pixdesc->flags & AV_PIX_FMT_FLAG_BE) + AV_WB32(data,valu); + else + AV_WL32(data,valu); +} + #define ffapi_setpel(FFContext,AVFrame,x,y,c,val) ffapi_setpel_direct(AVFrame,x,y,FFContext->pixdesc->comp[c],val) #define ffapi_getpel(FFContext,AVFrame,x,y,c) ffapi_getpel_direct(AVFrame,x,y,FFContext->pixdesc->comp[c]) #define ffapi_setpixel(FFContext,AVFrame,x,y,val)\ diff --git a/scan/scan.c b/scan/scan.c index 38f50d8..328863f 100644 --- a/scan/scan.c +++ b/scan/scan.c @@ -251,13 +251,10 @@ int main(int argc, char* argv[]) { } size_t width = MagickGetImageWidth(wand), height = MagickGetImageHeight(wand), channels = 3; - unsigned char blackpixel[channels]; - memset(blackpixel,0,channels); - av_log_set_level(loglevel); FFColorProperties color_props; ffapi_parse_color_props(&color_props,""); - color_props.pix_fmt = AV_PIX_FMT_RGB24; + color_props.pix_fmt = AV_PIX_FMT_GBRPF32LE; color_props.color_range = AVCOL_RANGE_JPEG; int imagecolorspace = MagickGetImageColorspace(wand); if(imagecolorspace == RGBColorspace) @@ -375,8 +372,8 @@ int main(int argc, char* argv[]) { if(visualize) { intermediate normalization = spec_normalization_2d(x,y); for(size_t z = 0; z < channels; z++) { - intermediate c = (spec ? spec_scale(sp,coeffs[(y*width+x)*channels+z]*normalization) : 1.0)*255; - ffapi_setpel(ffctx,frame,x+width,y,z,c); + intermediate c = spec ? spec_scale(sp,coeffs[(y*width+x)*channels+z]*normalization) : 1.0; + ffapi_setpelf(ffctx,frame,x+width,y,z,c); } } } @@ -390,7 +387,7 @@ int main(int argc, char* argv[]) { intermediate pel = sum[(y*width+x)*channels+z]; if(trc_encode) pel = trc_encode(pel); - ffapi_setpel(ffctx, frame, x, y, z, pel*255); + ffapi_setpelf(ffctx, frame, x, y, z, pel); } } @@ -410,10 +407,10 @@ int main(int argc, char* argv[]) { if(visualize) { intermediate normalization = spec_normalization_2d(x,y); for(size_t z = 0; z < channels; z++) { - intermediate c = (spec ? spec_scale(sp,coeffs[(y*width+x)*channels+z]*normalization) : 1.0)*255; - ffapi_setpel(ffctx,frame,x+width,y,z,c); + intermediate c = spec ? spec_scale(sp,coeffs[(y*width+x)*channels+z]*normalization) : 1.0; + ffapi_setpelf(ffctx,frame,x+width,y,z,c); if(intermediates) - ffapi_setpel(ffctx,frame,x+width,y+height,z,c); + ffapi_setpelf(ffctx,frame,x+width,y+height,z,c); } } } @@ -432,7 +429,7 @@ int main(int argc, char* argv[]) { intermediate pel = sum[(y*width+x)*channels+z]; if(trc_encode) pel = trc_encode(pel); - ffapi_setpel(ffctx, frame, x, y, z, pel*255); + ffapi_setpelf(ffctx, frame, x, y, z, pel); } if(intermediates) { @@ -463,7 +460,7 @@ int main(int argc, char* argv[]) { intermediate pel = (((image[(y*width+x)*channels+z]+coeffs[z])-min[z])/(max[z]-min[z])); if(trc_encode) pel = trc_encode(pel); - ffapi_setpel(ffctx, frame, x, y+height, z, pel*255); + ffapi_setpelf(ffctx, frame, x, y+height, z, pel); } } @@ -474,7 +471,8 @@ int main(int argc, char* argv[]) { // just clear intermediate coords instead of wiping the entire frame if(intermediates && visualize) for(size_t ci = 0; ci < ncoords; ci++) - ffapi_setpixel(ffctx, frame, coords[ci][1]+width, coords[ci][0]+height, blackpixel); + for(size_t z = 0; z < channels; z++) + ffapi_setpelf(ffctx, frame, coords[ci][1]+width, coords[ci][0]+height, z, 0); } if(!quiet) fprintf(stderr,"\n");