Add new comment

Fuji X-Trans files washed out colors in 2021

I am using the release verson 0.20.2 in my lib (librawfx.org). Now I wanted to update to the newest snapshot version 202110. The problem I have now is that all x-trans files have now washed out colors.

Must I call something special for fuji x-trans files to get the right colors ?

With 0.20.2 all is working as expected but with the latest snapshot version not. You can find the example file under https://github.com/lanthale/LibRawFX/blob/main/LibRawFX/src/main/ressour...

Code I am using (sorry for the Java language but basically I am using the C API):

MemoryAddress iprc = org.libraw.linuxosx.libraw_h.libraw_init(0);
                Logger.getLogger(LibrawImage.class.getName()).log(Level.FINEST, null, "Memory dddress native lib was: " + iprc.toRawLongValue());
                MemorySegment datasegment = org.libraw.linuxosx.libraw_data_t.ofAddress(iprc, scope);
                MemorySegment params$slice = org.libraw.linuxosx.libraw_data_t.params$slice(datasegment);
                org.libraw.linuxosx.libraw_output_params_t.use_camera_wb$set(params$slice, 0);
                org.libraw.linuxosx.libraw_output_params_t.use_auto_wb$set(params$slice, 0);
                org.libraw.linuxosx.libraw_output_params_t.output_tiff$set(params$slice, 0);
                org.libraw.linuxosx.libraw_output_params_t.half_size$set(params$slice, 0);
                org.libraw.linuxosx.libraw_output_params_t.user_qual$set(params$slice, 0);
                //libraw_output_params_t.output_bps$set(params$slice, 8);
                //libraw_output_params_t.output_color$set(params$slice, 0);        
 
                MemorySegment inputStreamBytes = MemorySegment.ofArray(sourceFileAsByteArray);
                MemorySegment allocateNative = SegmentAllocator.ofScope(scope).allocateArray(C_CHAR, sourceFileAsByteArray);
                int k = org.libraw.linuxosx.libraw_h.libraw_open_buffer(iprc, allocateNative, inputStreamBytes.byteSize());
                if (k > 0) {
                    Logger.getLogger(LibrawImage.class.getName()).log(Level.SEVERE, null, "Cannot open stream, return value was: " + k);
                    throw new IOException("Cannot open file stream!");
                }
 
                org.libraw.linuxosx.libraw_h.libraw_unpack(iprc);
 
                MemoryAddress iParams = org.libraw.linuxosx.libraw_h.libraw_get_iparams(iprc);
                MemorySegment iParamsRestricted = org.libraw.linuxosx.libraw_iparams_t.ofAddress(iParams, scope);
                MemorySegment modelSlice = org.libraw.linuxosx.libraw_iparams_t.model$slice(iParamsRestricted);
                cameraModel = new String(modelSlice.toByteArray(), StandardCharsets.US_ASCII);
                MemoryAddress image_other_data = org.libraw.linuxosx.libraw_h.libraw_get_imgother(iprc);
                MemorySegment imageOtherRestricted = org.libraw.linuxosx.libraw_imgother_t.ofAddress(image_other_data, scope);
                long timestamp = org.libraw.linuxosx.libraw_imgother_t.timestamp$get(imageOtherRestricted);
                shootingDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), TimeZone.getDefault().toZoneId());
 
                org.libraw.linuxosx.libraw_h.libraw_dcraw_process(iprc);
                ByteArrayOutputStream bo = new ByteArrayOutputStream();
 
                MemorySegment errorCode = SegmentAllocator.ofScope(scope).allocate(C_INT.byteSize());
                MemoryAddress mem_image_adr = org.libraw.linuxosx.libraw_h.libraw_dcraw_make_mem_image(iprc, errorCode.address());
                MemorySegment imageMemSegment = org.libraw.linuxosx.libraw_processed_image_t.ofAddress(mem_image_adr, scope);
                MemorySegment data$slice = org.libraw.linuxosx.libraw_processed_image_t.data$slice(imageMemSegment);
                imageWidth = org.libraw.linuxosx.libraw_processed_image_t.width$get(imageMemSegment);
                Logger.getLogger(LibrawImage.class.getName()).log(Level.FINEST, null, "Native width: " + imageWidth);
                imageHeight = org.libraw.linuxosx.libraw_processed_image_t.height$get(imageMemSegment);
                imageBits = org.libraw.linuxosx.libraw_processed_image_t.bits$get(imageMemSegment);
                imageColors = org.libraw.linuxosx.libraw_processed_image_t.colors$get(imageMemSegment);
                stride = imageWidth * imageColors * (imageBits / 8);
                Logger.getLogger(LibrawImage.class.getName()).log(Level.FINEST, null, "Start reading image from native memory...");
                byte[] line = new byte[stride];
                for (var i = 0; i < imageHeight; i++) {
                    loader.updateImageProgress(i, imageHeight);
                    MemoryAddress addOffset = data$slice.address().addOffset(stride * i);
                    MemorySegment asSegmentRestricted = addOffset.asSegment(stride, scope);
                    line = asSegmentRestricted.toByteArray();
                    try {
                        bo.write(line);
                    } catch (IOException ex) {
                        Logger.getLogger(LibrawImage.class.getName()).log(Level.SEVERE, "Cannot retrieve image from native memory and write into byte array!", ex);
                        return null;
                    }
                }
                bo.flush();
                Logger.getLogger(LibrawImage.class.getName()).log(Level.FINEST, null, "Start reading image from native memory...finished");
                byte[] data = bo.toByteArray();
                bo.close();
                Logger.getLogger(LibrawImage.class.getName()).log(Level.FINEST, null, "Freeing of native memory...");
                org.libraw.linuxosx.libraw_h.libraw_dcraw_clear_mem(mem_image_adr);
                mem_image_adr = null;
                org.libraw.linuxosx.libraw_h.libraw_close(iprc);
                iprc = null;
                Logger.getLogger(LibrawImage.class.getName()).log(Level.FINEST, null, "Freeing of native memory...finished");
                return data;

Forums: