From klauspost at gmail.com Tue Nov 3 17:52:46 2009 From: klauspost at gmail.com (Klaus Post) Date: Tue, 03 Nov 2009 17:52:46 +0100 Subject: [Rawstudio-commit] rawspeed r165 - RawSpeed Message-ID: Author: post Date: 2009-11-03 17:52:46 +0100 (Tue, 03 Nov 2009) New Revision: 165 Modified: RawSpeed/BitPumpMSB.cpp RawSpeed/BitPumpMSB.h RawSpeed/OrfDecoder.cpp Log: - Unrolled ORF decoder. Approx 5% speedup. - Inlined Bitpump. Modified: RawSpeed/BitPumpMSB.cpp =================================================================== --- RawSpeed/BitPumpMSB.cpp 2009-10-29 16:14:00 UTC (rev 164) +++ RawSpeed/BitPumpMSB.cpp 2009-11-03 16:52:46 UTC (rev 165) @@ -40,7 +40,7 @@ init(); } -void __inline BitPumpMSB::init() { +__inline void BitPumpMSB::init() { for (int i = 0; i < 31; i++) { masks[i] = (1 << i) - 1; } @@ -48,7 +48,7 @@ fill(); } -void BitPumpMSB::fill() { +__inline void BitPumpMSB::fill() { guchar c; while (mLeft < MIN_GET_BITS) { @@ -59,51 +59,7 @@ } } -guint BitPumpMSB::getBit() { - if (!mLeft) fill(); - return (mCurr >> (--mLeft)) & 1; -} - -guint BitPumpMSB::getBits(guint nbits) { - if (mLeft < nbits) { - if (nbits>24) - throw IOException("Invalid data, attempting to read more than 24 bits."); - - fill(); - } - - return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits]; -} - -guint BitPumpMSB::peekBit() { - if (!mLeft) fill(); - - return (mCurr >> (mLeft - 1)) & 1; -} - -guint BitPumpMSB::peekBits(guint nbits) { - if (mLeft < nbits) { - if (nbits>24) - throw IOException("Invalid data, attempting to read more than 24 bits."); - - fill(); - } - - return ((mCurr >> (mLeft - nbits))) & masks[nbits]; -} - -guint BitPumpMSB::peekByte() { - if (mLeft < 8) { - fill(); - } - - if (off > size) - throw IOException("Out of buffer read"); - - return ((mCurr >> (mLeft - 8))) & 0xff; -} - guint BitPumpMSB::getBitSafe() { if (!mLeft) { fill(); @@ -129,29 +85,7 @@ return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits]; } -void BitPumpMSB::skipBits(unsigned int nbits) { - if (mLeft < nbits) { - fill(); - if (off > size) - throw IOException("Out of buffer read"); - } - - mLeft -= nbits; -} - -void BitPumpMSB::skipBitsNoFill(unsigned int nbits) { - mLeft -= nbits; -} - -unsigned char BitPumpMSB::getByte() { - if (mLeft < 8) { - fill(); - } - - return ((mCurr >> (mLeft -= 8))) & 0xff; -} - unsigned char BitPumpMSB::getByteSafe() { if (mLeft < 8) { fill(); Modified: RawSpeed/BitPumpMSB.h =================================================================== --- RawSpeed/BitPumpMSB.h 2009-10-29 16:14:00 UTC (rev 164) +++ RawSpeed/BitPumpMSB.h 2009-11-03 16:52:46 UTC (rev 165) @@ -31,27 +31,86 @@ public: BitPumpMSB(ByteStream *s); BitPumpMSB(const guchar* _buffer, guint _size ); - guint getBits(guint nbits); - guint getBit(); guint getBitsSafe(guint nbits); guint getBitSafe(); - guint peekBits(guint nbits); - guint peekBit(); - guint peekByte(); - void skipBits(guint nbits); - void skipBitsNoFill(guint nbits); - __inline void checkPos() { if (off>size) throw IOException("Out of buffer read");}; // Check if we have a valid position - guchar getByte(); guchar getByteSafe(); void setAbsoluteOffset(guint offset); // Set offset in bytes - guint getOffset() { return off-(mLeft>>3);} + __inline guint getOffset() { return off-(mLeft>>3);} + __inline void checkPos() { if (off>size) throw IOException("Out of buffer read");}; // Check if we have a valid position __inline guint getBitNoFill() {return (mCurr >> (--mLeft)) & 1;} __inline guint peekByteNoFill() {return ((mCurr >> (mLeft-8))) & 0xff; } __inline guint getBitsNoFill(guint nbits) {return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits];} __inline guint peekBitsNoFill(guint nbits) {return ((mCurr >> (mLeft-nbits))) &masks[nbits]; } - void fill(); // Fill the buffer with at least 24 bits + __inline void fill(); // Fill the buffer with at least 24 bits + __inline guint BitPumpMSB::getBit() { + if (!mLeft) fill(); + return (mCurr >> (--mLeft)) & 1; + } + + __inline guint BitPumpMSB::getBits(guint nbits) { + if (mLeft < nbits) { + if (nbits>24) + throw IOException("Invalid data, attempting to read more than 24 bits."); + + fill(); + } + + return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits]; + } + + __inline guint BitPumpMSB::peekBit() { + if (!mLeft) fill(); + + return (mCurr >> (mLeft - 1)) & 1; + } + + __inline guint BitPumpMSB::peekBits(guint nbits) { + if (mLeft < nbits) { + if (nbits>24) + throw IOException("Invalid data, attempting to read more than 24 bits."); + + fill(); + } + + return ((mCurr >> (mLeft - nbits))) & masks[nbits]; + } + + __inline guint BitPumpMSB::peekByte() { + if (mLeft < 8) { + fill(); + } + + if (off > size) + throw IOException("Out of buffer read"); + + return ((mCurr >> (mLeft - 8))) & 0xff; + } + + __inline void BitPumpMSB::skipBits(unsigned int nbits) { + if (mLeft < nbits) { + fill(); + + if (off > size) + throw IOException("Out of buffer read"); + } + + mLeft -= nbits; + } + + __inline void BitPumpMSB::skipBitsNoFill(unsigned int nbits) { + mLeft -= nbits; + } + + __inline unsigned char BitPumpMSB::getByte() { + if (mLeft < 8) { + fill(); + } + + return ((mCurr >> (mLeft -= 8))) & 0xff; + } + virtual ~BitPumpMSB(void); protected: void __inline init(); Modified: RawSpeed/OrfDecoder.cpp =================================================================== --- RawSpeed/OrfDecoder.cpp 2009-10-29 16:14:00 UTC (rev 164) +++ RawSpeed/OrfDecoder.cpp 2009-11-03 16:52:46 UTC (rev 165) @@ -104,8 +104,8 @@ */ void OrfDecoder::decodeCompressed(ByteStream& s, guint w, guint h) { - int nbits, sign, low, high, i, wo, n, nw; - int acarry[2][3], *carry, pred, diff; + int nbits, sign, low, high, i, wo0, n, nw0, wo1, nw1; + int acarry0[3], acarry1[3], pred, diff; guchar* data = mRaw->getData(); gint pitch = mRaw->pitch; @@ -119,19 +119,20 @@ break; bittable[i] = high; } - + wo0 = nw0 = wo1 = nw1 = 0; s.skipBytes(7); BitPumpMSB bits(&s); for (guint y = 0; y < h; y++) { - memset(acarry, 0, sizeof acarry); + memset(acarry0, 0, sizeof acarry0); + memset(acarry1, 0, sizeof acarry1); gushort* dest = (gushort*) & data[y*pitch]; for (guint x = 0; x < w; x++) { bits.checkPos(); bits.fill(); - carry = acarry[x & 1]; - i = 2 * (carry[2] < 3); - for (nbits = 2 + i; (gushort) carry[0] >> (nbits + i); nbits++); + i = 2 * (acarry0[2] < 3); + for (nbits = 2 + i; (gushort) acarry0[0] >> (nbits + i); nbits++); + int b = bits.peekBitsNoFill(15); sign = (b >> 14) * -1; low = (b >> 12) & 3; @@ -141,25 +142,91 @@ if (high == 12) high = bits.getBits(16 - nbits) >> 1; - carry[0] = (high << nbits) | bits.getBits(nbits); - diff = (carry[0] ^ sign) + carry[1]; - carry[1] = (diff * 3 + carry[1]) >> 5; - carry[2] = carry[0] > 16 ? 0 : carry[2] + 1; - if (y < 2 && x < 2) pred = 0; - else if (y < 2) pred = dest[x-2]; - else if (x < 2) pred = dest[-pitch+((gint)x)]; // Pitch is in bytes, and dest is in short, so we skip two lines - else { - wo = dest[x-2]; + + acarry0[0] = (high << nbits) | bits.getBits(nbits); + diff = (acarry0[0] ^ sign) + acarry0[1]; + acarry0[1] = (diff * 3 + acarry0[1]) >> 5; + acarry0[2] = acarry0[0] > 16 ? 0 : acarry0[2] + 1; + + if (y < 2 || x < 2) { + if (y < 2 && x < 2) + pred = 0; + else if (y < 2) + pred = wo0; + else { + pred = dest[-pitch+((gint)x)]; + nw0 = pred; + } + dest[x] = pred + ((diff << 2) | low); + // Set predictor + wo0 = dest[x]; + } else { n = dest[-pitch+((gint)x)]; - nw = dest[-pitch+((gint)x)-2]; - if ((wo < nw && nw < n) || (n < nw && nw < wo)) { - if (abs(wo - nw) > 32 || abs(n - nw) > 32) - pred = wo + n - nw; - else pred = (wo + n) >> 1; - } else pred = abs(wo - nw) > abs(n - nw) ? wo : n; + if (((wo0 < nw0) & (nw0 < n)) | ((n < nw0) & (nw0 < wo0))) { + if (abs(wo0 - nw0) > 32 || abs(n - nw0) > 32) + pred = wo0 + n - nw0; + else + pred = (wo0 + n) >> 1; + } else + pred = abs(wo0 - nw0) > abs(n - nw0) ? wo0 : n; + + dest[x] = pred + ((diff << 2) | low); + // Set predictors + wo0 = dest[x]; + nw0 = n; } - dest[x] = pred + ((diff << 2) | low); _ASSERTE(0 == dest[x] >> 12) ; + + // ODD PIXELS + x += 1; + bits.checkPos(); + bits.fill(); + i = 2 * (acarry1[2] < 3); + for (nbits = 2 + i; (gushort) acarry1[0] >> (nbits + i); nbits++); + b = bits.peekBitsNoFill(15); + sign = (b >> 14) * -1; + low = (b >> 12) & 3; + high = bittable[b&4095]; + // Skip bits used above. + bits.skipBitsNoFill(min(12+3, high + 1 + 3)); + + if (high == 12) + high = bits.getBits(16 - nbits) >> 1; + + acarry1[0] = (high << nbits) | bits.getBits(nbits); + diff = (acarry1[0] ^ sign) + acarry1[1]; + acarry1[1] = (diff * 3 + acarry1[1]) >> 5; + acarry1[2] = acarry1[0] > 16 ? 0 : acarry1[2] + 1; + + if (y < 2 || x < 2) { + if (y < 2 && x < 2) + pred = 0; + else if (y < 2) + pred = wo1; + else { + pred = dest[-pitch+((gint)x)]; + nw1 = pred; + } + dest[x] = pred + ((diff << 2) | low); + // Set predictor + wo1 = dest[x]; + } else { + n = dest[-pitch+((gint)x)]; + if (((wo1 < nw1) & (nw1 < n)) | ((n < nw1) & (nw1 < wo1))) { + if (abs(wo1 - nw1) > 32 || abs(n - nw1) > 32) + pred = wo1 + n - nw1; + else + pred = (wo1 + n) >> 1; + } else + pred = abs(wo1 - nw1) > abs(n - nw1) ? wo1 : n; + + dest[x] = pred + ((diff << 2) | low); + + // Set predictors + wo1 = dest[x]; + nw1 = n; + } + _ASSERTE(0 == dest[x] >> 12) ; } } } From klauspost at gmail.com Tue Nov 3 17:59:56 2009 From: klauspost at gmail.com (Klaus Post) Date: Tue, 03 Nov 2009 17:59:56 +0100 Subject: [Rawstudio-commit] rawspeed r166 - RawSpeed Message-ID: Author: post Date: 2009-11-03 17:59:55 +0100 (Tue, 03 Nov 2009) New Revision: 166 Modified: RawSpeed/BitPumpMSB.cpp RawSpeed/BitPumpMSB.h Log: GCC Friendly inlining. Modified: RawSpeed/BitPumpMSB.cpp =================================================================== --- RawSpeed/BitPumpMSB.cpp 2009-11-03 16:52:46 UTC (rev 165) +++ RawSpeed/BitPumpMSB.cpp 2009-11-03 16:59:55 UTC (rev 166) @@ -26,10 +26,7 @@ /*** Used for entropy encoded sections ***/ -#define BITS_PER_LONG (8*sizeof(guint)) -#define MIN_GET_BITS (BITS_PER_LONG-7) /* max value for long getBuffer */ - BitPumpMSB::BitPumpMSB(ByteStream *s): buffer(s->getData()), size(s->getRemainSize() + sizeof(guint)), mLeft(0), mCurr(0), off(0) { init(); @@ -48,18 +45,6 @@ fill(); } -__inline void BitPumpMSB::fill() { - guchar c; - - while (mLeft < MIN_GET_BITS) { - _ASSERTE(off < size); - c = buffer[off++]; - mCurr = (mCurr << 8) | c; - mLeft += 8; - } -} - - guint BitPumpMSB::getBitSafe() { if (!mLeft) { fill(); Modified: RawSpeed/BitPumpMSB.h =================================================================== --- RawSpeed/BitPumpMSB.h 2009-11-03 16:52:46 UTC (rev 165) +++ RawSpeed/BitPumpMSB.h 2009-11-03 16:59:55 UTC (rev 166) @@ -22,6 +22,9 @@ #pragma once #include "ByteStream.h" +#define BITS_PER_LONG (8*sizeof(guint)) +#define MIN_GET_BITS (BITS_PER_LONG-7) /* max value for long getBuffer */ + namespace RawSpeed { // Note: Allocated buffer MUST be at least size+sizeof(guint) large. @@ -41,15 +44,26 @@ __inline guint peekByteNoFill() {return ((mCurr >> (mLeft-8))) & 0xff; } __inline guint getBitsNoFill(guint nbits) {return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits];} __inline guint peekBitsNoFill(guint nbits) {return ((mCurr >> (mLeft-nbits))) &masks[nbits]; } - __inline void fill(); // Fill the buffer with at least 24 bits - __inline guint BitPumpMSB::getBit() { + // Fill the buffer with at least 24 bits + __inline void fill() { + guchar c; + + while (mLeft < MIN_GET_BITS) { + _ASSERTE(off < size); + c = buffer[off++]; + mCurr = (mCurr << 8) | c; + mLeft += 8; + } + } + + __inline guint getBit() { if (!mLeft) fill(); return (mCurr >> (--mLeft)) & 1; } - __inline guint BitPumpMSB::getBits(guint nbits) { + __inline guint getBits(guint nbits) { if (mLeft < nbits) { if (nbits>24) throw IOException("Invalid data, attempting to read more than 24 bits."); @@ -60,13 +74,13 @@ return ((mCurr >> (mLeft -= (nbits)))) & masks[nbits]; } - __inline guint BitPumpMSB::peekBit() { + __inline guint peekBit() { if (!mLeft) fill(); return (mCurr >> (mLeft - 1)) & 1; } - __inline guint BitPumpMSB::peekBits(guint nbits) { + __inline guint peekBits(guint nbits) { if (mLeft < nbits) { if (nbits>24) throw IOException("Invalid data, attempting to read more than 24 bits."); @@ -77,7 +91,7 @@ return ((mCurr >> (mLeft - nbits))) & masks[nbits]; } - __inline guint BitPumpMSB::peekByte() { + __inline guint peekByte() { if (mLeft < 8) { fill(); } @@ -88,7 +102,7 @@ return ((mCurr >> (mLeft - 8))) & 0xff; } - __inline void BitPumpMSB::skipBits(unsigned int nbits) { + __inline void skipBits(unsigned int nbits) { if (mLeft < nbits) { fill(); @@ -99,11 +113,11 @@ mLeft -= nbits; } - __inline void BitPumpMSB::skipBitsNoFill(unsigned int nbits) { + __inline void skipBitsNoFill(unsigned int nbits) { mLeft -= nbits; } - __inline unsigned char BitPumpMSB::getByte() { + __inline unsigned char getByte() { if (mLeft < 8) { fill(); } From anders at kvistmail.dk Mon Nov 9 01:00:08 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 09 Nov 2009 01:00:08 +0100 Subject: [Rawstudio-commit] r2735 - trunk/src Message-ID: Author: akv Date: 2009-11-09 01:00:07 +0100 (Mon, 09 Nov 2009) New Revision: 2735 Modified: trunk/src/rs-batch.c Log: respect queue export maximum dimensions - Patch by Edouard Gomez Modified: trunk/src/rs-batch.c =================================================================== --- trunk/src/rs-batch.c 2009-10-21 01:52:00 UTC (rev 2734) +++ trunk/src/rs-batch.c 2009-11-09 00:00:07 UTC (rev 2735) @@ -520,8 +520,8 @@ "rectangle", photo->crop, "settings", photo->settings[setting_id], "bounding-box", TRUE, - "width", 250, - "height", 250, + "width", queue->width, + "height", queue->height, NULL); /* Render preview image */ From anders at kvistmail.dk Mon Nov 9 01:03:25 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 09 Nov 2009 01:03:25 +0100 Subject: [Rawstudio-commit] r2736 - trunk/src Message-ID: Author: akv Date: 2009-11-09 01:03:25 +0100 (Mon, 09 Nov 2009) New Revision: 2736 Modified: trunk/src/rs-preview-widget.c Log: add 16:9 crop ratio - Patch by Edouard Gomez Modified: trunk/src/rs-preview-widget.c =================================================================== --- trunk/src/rs-preview-widget.c 2009-11-09 00:00:07 UTC (rev 2735) +++ trunk/src/rs-preview-widget.c 2009-11-09 00:03:25 UTC (rev 2736) @@ -947,6 +947,7 @@ const static gdouble aspect_43 = 4.0f/3.0f; const static gdouble aspect_1008 = 10.0f/8.0f; const static gdouble aspect_1610 = 16.0f/10.0f; + const static gdouble aspect_169 = 16.0f/9.0f; const static gdouble aspect_83 = 8.0f/3.0f; const static gdouble aspect_11 = 1.0f; static gdouble aspect_iso216; @@ -1001,6 +1002,7 @@ gui_confbox_add_entry(aspect_confbox, "4:3", _("4:3"), (gpointer) &aspect_43); gui_confbox_add_entry(aspect_confbox, "10:8", _("10:8 (SXGA)"), (gpointer) &aspect_1008); gui_confbox_add_entry(aspect_confbox, "16:10", _("16:10 (Wide XGA)"), (gpointer) &aspect_1610); + gui_confbox_add_entry(aspect_confbox, "16:9", _("16:9 (HDTV)"), (gpointer) &aspect_169); gui_confbox_add_entry(aspect_confbox, "8:3", _("8:3 (Dualhead XGA)"), (gpointer) &aspect_83); gui_confbox_add_entry(aspect_confbox, "1:1", _("1:1"), (gpointer) &aspect_11); gui_confbox_add_entry(aspect_confbox, "goldenrectangle", _("Golden rectangle"), (gpointer) &aspect_golden); From anders at brander.dk Mon Nov 9 04:04:41 2009 From: anders at brander.dk (Anders Brander) Date: Mon, 09 Nov 2009 04:04:41 +0100 Subject: [Rawstudio-commit] r2737 - trunk/src Message-ID: Author: abrander Date: 2009-11-09 04:04:41 +0100 (Mon, 09 Nov 2009) New Revision: 2737 Modified: trunk/src/rs-batch.c Log: Reverting revision 2735 and applied proper fix. Modified: trunk/src/rs-batch.c =================================================================== --- trunk/src/rs-batch.c 2009-11-09 00:03:25 UTC (rev 2736) +++ trunk/src/rs-batch.c 2009-11-09 03:04:41 UTC (rev 2737) @@ -520,8 +520,8 @@ "rectangle", photo->crop, "settings", photo->settings[setting_id], "bounding-box", TRUE, - "width", queue->width, - "height", queue->height, + "width", 250, + "height", 250, NULL); /* Render preview image */ @@ -542,6 +542,8 @@ gtk_main_iteration(); g_free(basename); + width = 65535; + height = 65535; /* Calculate new size */ switch (queue->size_lock) { @@ -552,21 +554,16 @@ break; case LOCK_WIDTH: width = queue->width; - scale = ((gdouble) width) / rs_filter_get_width(fcrop); - height = (gint) (scale * ((gdouble) rs_filter_get_height(fcrop))); break; case LOCK_HEIGHT: height = queue->height; - scale = ((gdouble) height) / rs_filter_get_height(fcrop); - width = (gint) (scale * ((gdouble) rs_filter_get_width(fcrop))); break; case LOCK_BOUNDING_BOX: - width = rs_filter_get_width(fcrop); - height = rs_filter_get_height(fcrop); - rs_constrain_to_bounding_box(queue->width, queue->height, &width, &height); + width = queue->width; + height = queue->height; break; } - g_object_set(fend, + rs_filter_set_recursive(fend, "width", width, "height", height, NULL); From klauspost at gmail.com Mon Nov 9 20:05:40 2009 From: klauspost at gmail.com (Klaus Post) Date: Mon, 09 Nov 2009 20:05:40 +0100 Subject: [Rawstudio-commit] rawspeed r167 - RawSpeed Message-ID: Author: post Date: 2009-11-09 20:05:39 +0100 (Mon, 09 Nov 2009) New Revision: 167 Modified: RawSpeed/rawstudio-plugin-api.cpp Log: - Only display a warning when the camera file cannot be found. - Include black/white scale in timing. - Nicer error messages. ;) Modified: RawSpeed/rawstudio-plugin-api.cpp =================================================================== --- RawSpeed/rawstudio-plugin-api.cpp 2009-11-03 16:59:55 UTC (rev 166) +++ RawSpeed/rawstudio-plugin-api.cpp 2009-11-09 19:05:39 UTC (rev 167) @@ -40,7 +40,12 @@ if (!c) { gchar *path = g_build_filename(rs_confdir_get(), "cameras.xml", NULL); + try { c = new CameraMetaData(path); + } catch (CameraMetadataException e) { + printf("RawSpeed: Could not open camera metadata information.\n%s\nRawSpeed will not be used!\n", e.what()); + return NULL; + } g_free(path); } @@ -65,7 +70,7 @@ } #ifdef TIME_LOAD - printf("Open %s: %.03fs\n", filename, g_timer_elapsed(gt, NULL)); + printf("RawSpeed Open %s: %.03fs\n", filename, g_timer_elapsed(gt, NULL)); g_timer_destroy(gt); #endif @@ -85,24 +90,24 @@ d->decodeRaw(); d->decodeMetaData(c); -#ifdef TIME_LOAD - printf("Decode %s: %.03fs\n", filename, g_timer_elapsed(gt, NULL)); - g_timer_destroy(gt); -#endif - for (guint i = 0; i < d->errors.size(); i++) - printf("Error Encountered:%s\n", d->errors[i]); + printf("RawSpeed: Error Encountered:%s\n", d->errors[i]); RawImage r = d->mRaw; r->scaleBlackWhite(); +#ifdef TIME_LOAD + printf("RawSpeed Decode %s: %.03fs\n", filename, g_timer_elapsed(gt, NULL)); + g_timer_destroy(gt); +#endif + cpp = r->getCpp(); if (cpp == 1) image = rs_image16_new(r->dim.x, r->dim.y, cpp, cpp); else if (cpp == 3) image = rs_image16_new(r->dim.x, r->dim.y, 3, 4); else { - printf("Unsupported component per pixel count"); + printf("RawSpeed: Unsupported component per pixel count\n"); return NULL; } @@ -110,12 +115,6 @@ image->filters = r->cfa.getDcrawFilter(); - if (r->isCFA) - { -// printf("DCRAW filter:%x\n",r->cfa.getDcrawFilter()); -// printf("%s", r->cfa.asString().c_str()); - } - if (cpp == 1) { BitBlt((guchar *)(GET_PIXEL(image,0,0)),image->pitch*2, @@ -138,12 +137,12 @@ } catch (RawDecoderException e) { - printf("RawDecoderException: %s\n", e.what()); + printf("RawSpeed: RawDecoderException: %s\n", e.what()); } } catch (TiffParserException e) { - printf("TiffParserException: %s\n", e.what()); + printf("RawSpeed: TiffParserException: %s\n", e.what()); } if (d) delete d; From klauspost at gmail.com Tue Nov 10 19:14:25 2009 From: klauspost at gmail.com (Klaus Post) Date: Tue, 10 Nov 2009 19:14:25 +0100 Subject: [Rawstudio-commit] rawspeed r168 - / Message-ID: Author: post Date: 2009-11-10 19:14:25 +0100 (Tue, 10 Nov 2009) New Revision: 168 Modified: cameras.xml Log: - Add support for Canon Powershot S90. Modified: cameras.xml =================================================================== --- cameras.xml 2009-11-09 19:05:39 UTC (rev 167) +++ cameras.xml 2009-11-10 18:14:25 UTC (rev 168) @@ -273,6 +273,16 @@ + + + RED + GREEN + GREEN + BLUE + + + + GREEN From anders at brander.dk Sun Nov 15 17:42:46 2009 From: anders at brander.dk (Anders Brander) Date: Sun, 15 Nov 2009 17:42:46 +0100 Subject: [Rawstudio-commit] r2738 - trunk/plugins/meta-tiff Message-ID: Author: abrander Date: 2009-11-15 17:42:46 +0100 (Sun, 15 Nov 2009) New Revision: 2738 Modified: trunk/plugins/meta-tiff/tiff-meta.c Log: Added camera WB support for Nikon D300S. Modified: trunk/plugins/meta-tiff/tiff-meta.c =================================================================== --- trunk/plugins/meta-tiff/tiff-meta.c 2009-11-09 03:04:41 UTC (rev 2737) +++ trunk/plugins/meta-tiff/tiff-meta.c 2009-11-15 16:42:46 UTC (rev 2738) @@ -530,6 +530,7 @@ case 0x000c: /* D1 White Balance */ if (g_str_equal(meta->model_ascii, "NIKON D1X") || g_str_equal(meta->model_ascii, "NIKON D90") + || g_str_equal(meta->model_ascii, "NIKON D300S") || g_str_equal(meta->model_ascii, "NIKON D3000") || g_str_equal(meta->model_ascii, "NIKON D5000")) { @@ -567,7 +568,8 @@ meta->thumbnail_start += base; break; case 0x0097: /* white balance */ - if (g_str_equal(meta->model_ascii, "NIKON D90")) + if (g_str_equal(meta->model_ascii, "NIKON D90") + || g_str_equal(meta->model_ascii, "NIKON D300S")) break; for(i=0;i<4;i++) From anders at kvistmail.dk Sun Nov 15 20:15:44 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Sun, 15 Nov 2009 20:15:44 +0100 Subject: [Rawstudio-commit] r2739 - in trunk: librawstudio plugins/lensfun src Message-ID: Author: akv Date: 2009-11-15 20:15:44 +0100 (Sun, 15 Nov 2009) New Revision: 2739 Modified: trunk/librawstudio/rs-settings.c trunk/librawstudio/rs-settings.h trunk/plugins/lensfun/lensfun.c trunk/src/application.c trunk/src/rs-actions.c trunk/src/rs-cache.c trunk/src/rs-preview-widget.c trunk/src/rs-toolbox.c Log: Adding TCA correction. Modified: trunk/librawstudio/rs-settings.c =================================================================== --- trunk/librawstudio/rs-settings.c 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/librawstudio/rs-settings.c 2009-11-15 19:15:44 UTC (rev 2739) @@ -52,6 +52,8 @@ PROP_SHARPEN, PROP_DENOISE_LUMA, PROP_DENOISE_CHROMA, + PROP_TCA_KR, + PROP_TCA_KB, PROP_CHANNELMIXER_RED, PROP_CHANNELMIXER_GREEN, PROP_CHANNELMIXER_BLUE @@ -111,6 +113,16 @@ 0.0, 100.0, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, + PROP_TCA_KR, g_param_spec_float( /* FIXME: ? */ + "tca_kr", _("tca_kr"), _("tca_kr"), + 0.9, 1.1, 1.0, G_PARAM_READWRITE) + ); + g_object_class_install_property(object_class, + PROP_TCA_KB, g_param_spec_float( /* FIXME: ? */ + "tca_kb", _("tca_kb"), _("tca_kb"), + 0.9, 1.1, 1.0, G_PARAM_READWRITE) + ); + g_object_class_install_property(object_class, PROP_CHANNELMIXER_RED, g_param_spec_float( /* FIXME: ? */ "channelmixer_red", _("Red"), _("Red"), 0.0, 300.0, 100.0, G_PARAM_READWRITE) @@ -171,6 +183,8 @@ CASE(SHARPEN, sharpen); CASE(DENOISE_LUMA, denoise_luma); CASE(DENOISE_CHROMA, denoise_chroma); + CASE(TCA_KR, tca_kr); + CASE(TCA_KB, tca_kb); CASE(CHANNELMIXER_RED, channelmixer_red); CASE(CHANNELMIXER_GREEN, channelmixer_green); CASE(CHANNELMIXER_BLUE, channelmixer_blue); @@ -205,6 +219,8 @@ CASE(SHARPEN, sharpen); CASE(DENOISE_LUMA, denoise_luma); CASE(DENOISE_CHROMA, denoise_chroma); + CASE(TCA_KR, tca_kr); + CASE(TCA_KB, tca_kb); CASE(CHANNELMIXER_RED, channelmixer_red); CASE(CHANNELMIXER_GREEN, channelmixer_green); CASE(CHANNELMIXER_BLUE, channelmixer_blue); @@ -261,6 +277,12 @@ if (mask & MASK_DENOISE_CHROMA) rs_object_class_property_reset(settings, "denoise_chroma"); + if (mask & MASK_TCA_KR) + rs_object_class_property_reset(settings, "tca_kr"); + + if (mask & MASK_TCA_KB) + rs_object_class_property_reset(settings, "tca_kb"); + if (mask & MASK_CHANNELMIXER_RED) rs_object_class_property_reset(settings, "channelmixer_red"); @@ -359,6 +381,8 @@ SETTINGS_COPY(SHARPEN, sharpen); SETTINGS_COPY(DENOISE_LUMA, denoise_luma); SETTINGS_COPY(DENOISE_CHROMA, denoise_chroma); + SETTINGS_COPY(TCA_KR, tca_kr); + SETTINGS_COPY(TCA_KB, tca_kb); SETTINGS_COPY(CHANNELMIXER_RED, channelmixer_red); SETTINGS_COPY(CHANNELMIXER_GREEN, channelmixer_green); SETTINGS_COPY(CHANNELMIXER_BLUE, channelmixer_blue); Modified: trunk/librawstudio/rs-settings.h =================================================================== --- trunk/librawstudio/rs-settings.h 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/librawstudio/rs-settings.h 2009-11-15 19:15:44 UTC (rev 2739) @@ -44,9 +44,12 @@ MASK_SHARPEN = (1<<7), MASK_DENOISE_LUMA = (1<<8), MASK_DENOISE_CHROMA = (1<<9), - MASK_CHANNELMIXER_RED = (1<<10), - MASK_CHANNELMIXER_GREEN = (1<<11), - MASK_CHANNELMIXER_BLUE = (1<<12), + MASK_TCA_KR = (1<<10), + MASK_TCA_KB = (1<<11), + MASK_TCA = MASK_TCA_KR | MASK_TCA_KB, + MASK_CHANNELMIXER_RED = (1<<12), + MASK_CHANNELMIXER_GREEN = (1<<13), + MASK_CHANNELMIXER_BLUE = (1<<14), MASK_CHANNELMIXER = MASK_CHANNELMIXER_RED | MASK_CHANNELMIXER_GREEN | MASK_CHANNELMIXER_BLUE, MASK_ALL = 0x00ffffff, } RSSettingsMask; @@ -64,6 +67,8 @@ gfloat sharpen; gfloat denoise_luma; gfloat denoise_chroma; + gfloat tca_kr; + gfloat tca_kb; gfloat channelmixer_red; gfloat channelmixer_green; gfloat channelmixer_blue; Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/plugins/lensfun/lensfun.c 2009-11-15 19:15:44 UTC (rev 2739) @@ -40,6 +40,8 @@ gchar *lens_model; gfloat focal; gfloat aperture; + gfloat tca_kr; + gfloat tca_kb; }; struct _RSLensfunClass { @@ -57,6 +59,8 @@ PROP_LENS_MODEL, PROP_FOCAL, PROP_APERTURE, + PROP_TCA_KR, + PROP_TCA_KB, }; static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec); @@ -119,6 +123,16 @@ "aperture", "aperture", "aperture", 1.0, G_MAXFLOAT, 5.6, G_PARAM_READWRITE) ); + g_object_class_install_property(object_class, + PROP_TCA_KR, g_param_spec_float( + "tca_kr", "tca_kr", "tca_kr", + 0.9, 1.1, 1.0, G_PARAM_READWRITE) + ); + g_object_class_install_property(object_class, + PROP_TCA_KB, g_param_spec_float( + "tca_kb", "tca_kb", "tca_kb", + 0.9, 1.1, 1.0, G_PARAM_READWRITE) + ); filter_class->name = "Lensfun filter"; filter_class->get_image = get_image; @@ -134,6 +148,8 @@ lensfun->lens_model = NULL; lensfun->focal = 50.0; /* Well... */ lensfun->aperture = 5.6; + lensfun->tca_kr = 1.0; + lensfun->tca_kb = 1.0; } static void @@ -164,6 +180,12 @@ case PROP_APERTURE: g_value_set_float(value, lensfun->aperture); break; + case PROP_TCA_KR: + g_value_set_float(value, lensfun->tca_kr); + break; + case PROP_TCA_KB: + g_value_set_float(value, lensfun->tca_kb); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -195,6 +217,14 @@ case PROP_APERTURE: lensfun->aperture = g_value_get_float(value); break; + case PROP_TCA_KR: + lensfun->tca_kr = g_value_get_float(value); + rs_filter_changed(RS_FILTER(lensfun), RS_FILTER_CHANGED_PIXELDATA); + break; + case PROP_TCA_KB: + lensfun->tca_kb = g_value_get_float(value); + rs_filter_changed(RS_FILTER(lensfun), RS_FILTER_CHANGED_PIXELDATA); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -347,6 +377,19 @@ { gint effective_flags; + if (lensfun->tca_kr != 1.0 || lensfun->tca_kb != 1.0) + { + /* Set TCA */ + lfLensCalibTCA tca; + tca.Model = LF_TCA_MODEL_LINEAR; + const char *details; + const lfParameter **params; + lf_get_tca_model_desc (tca.Model, &details, ¶ms); + tca.Terms[0] = lensfun->tca_kr; + tca.Terms[1] = lensfun->tca_kb; + lf_lens_add_calib_tca((lfLens *) lens, (lfLensCalibTCA *) &tca.Model); + } + lfModifier *mod = lf_modifier_new (lens, cameras[0]->CropFactor, input->w, input->h); effective_flags = lf_modifier_initialize (mod, lens, LF_PF_U16, /* lfPixelFormat */ Modified: trunk/src/application.c =================================================================== --- trunk/src/application.c 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/src/application.c 2009-11-15 19:15:44 UTC (rev 2739) @@ -85,6 +85,8 @@ "lens", lens, "focal", (gfloat) meta->focallength, "aperture", meta->aperture, + "tca_kr", rs->photo->settings[rs->current_setting]->tca_kr, + "tca_kb", rs->photo->settings[rs->current_setting]->tca_kb, NULL); g_object_unref(lens); } Modified: trunk/src/rs-actions.c =================================================================== --- trunk/src/rs-actions.c 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/src/rs-actions.c 2009-11-15 19:15:44 UTC (rev 2739) @@ -338,7 +338,7 @@ gint mask = 0xffffff; /* Should be RSSettingsMask, is gint to satisfy rs_conf_get_integer() */ GtkWidget *dialog, *cb_box; - GtkWidget *cb_exposure, *cb_saturation, *cb_hue, *cb_contrast, *cb_whitebalance, *cb_curve, *cb_sharpen, *cb_denoise_luma, *cb_denoise_chroma, *cb_channelmixer; + GtkWidget *cb_exposure, *cb_saturation, *cb_hue, *cb_contrast, *cb_whitebalance, *cb_curve, *cb_sharpen, *cb_denoise_luma, *cb_denoise_chroma, *cb_channelmixer, *cb_tca; if (rs->settings_buffer) { @@ -352,6 +352,7 @@ cb_denoise_luma = gtk_check_button_new_with_label (_("Denoise")); cb_denoise_chroma = gtk_check_button_new_with_label (_("Color denoise")); cb_channelmixer = gtk_check_button_new_with_label (_("Channel mixer")); + cb_tca = gtk_check_button_new_with_label (_("TCA")); cb_curve = gtk_check_button_new_with_label (_("Curve")); rs_conf_get_integer(CONF_PASTE_MASK, &mask); @@ -374,6 +375,8 @@ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_denoise_chroma), TRUE); if (mask & MASK_CHANNELMIXER) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_channelmixer), TRUE); + if (mask & MASK_TCA) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_tca), TRUE); if (mask & MASK_CURVE) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_curve), TRUE); @@ -388,6 +391,7 @@ gtk_box_pack_start (GTK_BOX (cb_box), cb_denoise_luma, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (cb_box), cb_denoise_chroma, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (cb_box), cb_channelmixer, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (cb_box), cb_tca, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (cb_box), cb_curve, FALSE, TRUE, 0); dialog = gui_dialog_make_from_widget(GTK_STOCK_DIALOG_QUESTION, _("Select settings to paste"), cb_box); @@ -419,6 +423,8 @@ mask |= MASK_DENOISE_CHROMA; if (GTK_TOGGLE_BUTTON(cb_channelmixer)->active) mask |= MASK_CHANNELMIXER; + if (GTK_TOGGLE_BUTTON(cb_tca)->active) + mask |= MASK_TCA; if (GTK_TOGGLE_BUTTON(cb_curve)->active) mask |= MASK_CURVE; rs_conf_set_integer(CONF_PASTE_MASK, mask); Modified: trunk/src/rs-cache.c =================================================================== --- trunk/src/rs-cache.c 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/src/rs-cache.c 2009-11-15 19:15:44 UTC (rev 2739) @@ -120,6 +120,12 @@ xmlTextWriterWriteFormatElement(writer, BAD_CAST "channelmixer_blue", "%f", photo->settings[id]->channelmixer_blue); } + if (mask & MASK_TCA_KR) + xmlTextWriterWriteFormatElement(writer, BAD_CAST "tca_kr", "%f", + photo->settings[id]->tca_kr); + if (mask & MASK_TCA_KB) + xmlTextWriterWriteFormatElement(writer, BAD_CAST "tca_kb", "%f", + photo->settings[id]->tca_kb); if (mask & MASK_CURVE && photo->settings[id]->curve_nknots > 0) { xmlTextWriterStartElement(writer, BAD_CAST "curve"); @@ -223,6 +229,20 @@ if (version < 4) rss->channelmixer_blue *= 3.0; } + else if ((!xmlStrcmp(cur->name, BAD_CAST "tca_kr"))) + { + mask |= MASK_TCA_KR; + val = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + rss->tca_kr = rs_atof((gchar *) val); + xmlFree(val); + } + else if ((!xmlStrcmp(cur->name, BAD_CAST "tca_kb"))) + { + mask |= MASK_TCA_KB; + val = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + rss->tca_kb = rs_atof((gchar *) val); + xmlFree(val); + } else if ((!xmlStrcmp(cur->name, BAD_CAST "curve"))) { gchar **vals; Modified: trunk/src/rs-preview-widget.c =================================================================== --- trunk/src/rs-preview-widget.c 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/src/rs-preview-widget.c 2009-11-15 19:15:44 UTC (rev 2739) @@ -150,6 +150,7 @@ RSFilter *filter_mask[MAX_VIEWS]; RSFilter *filter_cache3[MAX_VIEWS]; RSFilter *filter_end[MAX_VIEWS]; /* For convenience */ + RSFilter *filter_lensfun[MAX_VIEWS]; RSFilterRequest *request[MAX_VIEWS]; GdkRectangle *last_roi[MAX_VIEWS]; @@ -567,6 +568,7 @@ if (preview->photo) { + g_signal_connect(G_OBJECT(preview->photo), "settings-changed", G_CALLBACK(settings_changed), preview); for(view=0;viewrequest[view], TRUE); @@ -584,6 +586,24 @@ void rs_preview_widget_set_filter(RSPreviewWidget *preview, RSFilter *filter) { + RSFilter *lensfun = NULL; + + RSFilter *f = filter; + + while(RS_IS_FILTER(filter)) + { + if (g_str_equal(RS_FILTER_NAME(filter), "RSLensfun")) + lensfun = filter; + filter = filter->previous; + } + filter = f; + + if (RS_IS_FILTER(lensfun)) + { + preview->filter_lensfun[0] = lensfun; + printf("We found the lensfun filter!\n"); + } + g_assert(RS_IS_PREVIEW_WIDGET(preview)); g_assert(RS_IS_FILTER(filter)); @@ -2153,6 +2173,40 @@ } static void +settings_changed(RS_PHOTO *photo, RSSettingsMask mask, RSPreviewWidget *preview) +{ + gint view; + + /* Seperate snapshot */ + const gint snapshot = mask>>24; + mask &= 0x00ffffff; + + /* Return if no more relevant */ + if (photo != preview->photo) + return; + + for(view=0;viewviews;view++) + { + if (preview->snapshot[view] == snapshot) + { + DIRTY(preview->dirty[view], SCREEN); + if (mask & MASK_TCA_KR) + { + gfloat f = 1.0; + g_object_get(preview->photo->settings[preview->snapshot[view]], "tca_kr", &f, NULL); + g_object_set(preview->filter_lensfun[view], "tca_kr", (gfloat) f, NULL); + } + if (mask & MASK_TCA_KB) + { + gfloat f = 1.0; + g_object_get(preview->photo->settings[preview->snapshot[view]], "tca_kb", &f, NULL); + g_object_set(preview->filter_lensfun[view], "tca_kb", (gfloat) f, NULL); + } + } + } +} + +static void filter_changed(RSFilter *filter, RSFilterChangedMask mask, RSPreviewWidget *preview) { gint view; Modified: trunk/src/rs-toolbox.c =================================================================== --- trunk/src/rs-toolbox.c 2009-11-15 16:42:46 UTC (rev 2738) +++ trunk/src/rs-toolbox.c 2009-11-15 19:15:44 UTC (rev 2739) @@ -59,12 +59,19 @@ }; #define NCHANNELMIXER (3) +const static BasicSettings tca[] = { + { "tca_kr", 0.00001 }, + { "tca_kb", 0.00001 }, +}; +#define NTCA (2) + struct _RSToolbox { GtkScrolledWindow parent; GtkWidget *notebook; GtkBox *toolbox; GtkRange *ranges[3][NBASICS]; GtkRange *channelmixer[3][NCHANNELMIXER]; + GtkRange *tca[3][NTCA]; RSSettings *settings[3]; GtkWidget *curve[3]; @@ -615,17 +622,20 @@ new_snapshot_page(RSToolbox *toolbox, const gint snapshot) { GtkWidget *vbox = gtk_vbox_new(FALSE, 1); - GtkTable *table, *channelmixertable; + GtkTable *table, *channelmixertable, *tcatable; gint row; table = GTK_TABLE(gtk_table_new(NBASICS, 5, FALSE)); channelmixertable = GTK_TABLE(gtk_table_new(NCHANNELMIXER, 5, FALSE)); + tcatable = GTK_TABLE(gtk_table_new(NTCA, 5, FALSE)); /* Add basic sliders */ for(row=0;rowranges[snapshot][row] = basic_slider(toolbox, snapshot, table, row, &basic[row]); for(row=0;rowchannelmixer[snapshot][row] = basic_slider(toolbox, snapshot, channelmixertable, row, &channelmixer[row]); + for(row=0;rowtca[snapshot][row] = basic_slider(toolbox, snapshot, tcatable, row, &tca[row]); /* Add curve editor */ toolbox->curve[snapshot] = rs_curve_widget_new(); @@ -636,6 +646,7 @@ /* Pack everything nice */ gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("Basic"), GTK_WIDGET(table), "show_basic", TRUE), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("Channel Mixer"), GTK_WIDGET(channelmixertable), "show_channelmixer", TRUE), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("TCA"), GTK_WIDGET(tcatable), "show_tca", TRUE), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("Curve"), toolbox->curve[snapshot], "show_curve", TRUE), FALSE, FALSE, 0); return vbox; @@ -761,6 +772,10 @@ { gtk_widget_set_sensitive(GTK_WIDGET(toolbox->channelmixer[snapshot][i]), FALSE); } + for(i=0;itca[snapshot][i]), FALSE); + } rs_curve_widget_reset(RS_CURVE_WIDGET(toolbox->curve[snapshot])); rs_curve_widget_add_knot(RS_CURVE_WIDGET(toolbox->curve[snapshot]), 0.0,0.0); rs_curve_widget_add_knot(RS_CURVE_WIDGET(toolbox->curve[snapshot]), 1.0,1.0); @@ -794,6 +809,15 @@ gtk_range_set_value(toolbox->channelmixer[snapshot][i], value); } + /* Update tca */ + for(i=0;iphoto->settings[snapshot], tca[i].property_name, &value, NULL); + gtk_range_set_value(toolbox->tca[snapshot][i], value); + } + /* Update curve */ if(mask & MASK_CURVE) { @@ -838,6 +862,8 @@ gtk_widget_set_sensitive(GTK_WIDGET(toolbox->ranges[snapshot][i]), TRUE); for(i=0;ichannelmixer[snapshot][i]), TRUE); + for(i=0;itca[snapshot][i]), TRUE); } photo_spatial_changed(toolbox->photo, toolbox); } From anders at kvistmail.dk Sun Nov 15 20:58:19 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Sun, 15 Nov 2009 20:58:19 +0100 Subject: [Rawstudio-commit] r2740 - in trunk: librawstudio plugins/lensfun src Message-ID: Author: akv Date: 2009-11-15 20:58:19 +0100 (Sun, 15 Nov 2009) New Revision: 2740 Modified: trunk/librawstudio/rs-settings.c trunk/librawstudio/rs-settings.h trunk/plugins/lensfun/lensfun.c trunk/src/application.c trunk/src/rs-actions.c trunk/src/rs-cache.c trunk/src/rs-preview-widget.c trunk/src/rs-toolbox.c Log: Enabling basic vignetting - only using Lensfun Vignetting K2 value as suggested by Lensfun author. Modified: trunk/librawstudio/rs-settings.c =================================================================== --- trunk/librawstudio/rs-settings.c 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/librawstudio/rs-settings.c 2009-11-15 19:58:19 UTC (rev 2740) @@ -54,6 +54,7 @@ PROP_DENOISE_CHROMA, PROP_TCA_KR, PROP_TCA_KB, + PROP_VIGNETTING_K2, PROP_CHANNELMIXER_RED, PROP_CHANNELMIXER_GREEN, PROP_CHANNELMIXER_BLUE @@ -123,6 +124,11 @@ 0.9, 1.1, 1.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, + PROP_VIGNETTING_K2, g_param_spec_float( /* FIXME: ? */ + "vignetting_k2", _("vignetting_k2"), _("vignetting_k2"), + -1, 2, 0.0, G_PARAM_READWRITE) + ); + g_object_class_install_property(object_class, PROP_CHANNELMIXER_RED, g_param_spec_float( /* FIXME: ? */ "channelmixer_red", _("Red"), _("Red"), 0.0, 300.0, 100.0, G_PARAM_READWRITE) @@ -185,6 +191,7 @@ CASE(DENOISE_CHROMA, denoise_chroma); CASE(TCA_KR, tca_kr); CASE(TCA_KB, tca_kb); + CASE(VIGNETTING_K2, vignetting_k2); CASE(CHANNELMIXER_RED, channelmixer_red); CASE(CHANNELMIXER_GREEN, channelmixer_green); CASE(CHANNELMIXER_BLUE, channelmixer_blue); @@ -221,6 +228,7 @@ CASE(DENOISE_CHROMA, denoise_chroma); CASE(TCA_KR, tca_kr); CASE(TCA_KB, tca_kb); + CASE(VIGNETTING_K2, vignetting_k2); CASE(CHANNELMIXER_RED, channelmixer_red); CASE(CHANNELMIXER_GREEN, channelmixer_green); CASE(CHANNELMIXER_BLUE, channelmixer_blue); @@ -283,6 +291,9 @@ if (mask & MASK_TCA_KB) rs_object_class_property_reset(settings, "tca_kb"); + if (mask & MASK_VIGNETTING_K2) + rs_object_class_property_reset(settings, "vignetting_k2"); + if (mask & MASK_CHANNELMIXER_RED) rs_object_class_property_reset(settings, "channelmixer_red"); @@ -383,6 +394,7 @@ SETTINGS_COPY(DENOISE_CHROMA, denoise_chroma); SETTINGS_COPY(TCA_KR, tca_kr); SETTINGS_COPY(TCA_KB, tca_kb); + SETTINGS_COPY(VIGNETTING_K2, vignetting_k2); SETTINGS_COPY(CHANNELMIXER_RED, channelmixer_red); SETTINGS_COPY(CHANNELMIXER_GREEN, channelmixer_green); SETTINGS_COPY(CHANNELMIXER_BLUE, channelmixer_blue); Modified: trunk/librawstudio/rs-settings.h =================================================================== --- trunk/librawstudio/rs-settings.h 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/librawstudio/rs-settings.h 2009-11-15 19:58:19 UTC (rev 2740) @@ -51,6 +51,8 @@ MASK_CHANNELMIXER_GREEN = (1<<13), MASK_CHANNELMIXER_BLUE = (1<<14), MASK_CHANNELMIXER = MASK_CHANNELMIXER_RED | MASK_CHANNELMIXER_GREEN | MASK_CHANNELMIXER_BLUE, + MASK_VIGNETTING_K2 = (1<<15), + MASK_VIGNETTING = MASK_VIGNETTING_K2, MASK_ALL = 0x00ffffff, } RSSettingsMask; @@ -69,6 +71,7 @@ gfloat denoise_chroma; gfloat tca_kr; gfloat tca_kb; + gfloat vignetting_k2; gfloat channelmixer_red; gfloat channelmixer_green; gfloat channelmixer_blue; Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/plugins/lensfun/lensfun.c 2009-11-15 19:58:19 UTC (rev 2740) @@ -42,6 +42,9 @@ gfloat aperture; gfloat tca_kr; gfloat tca_kb; + gfloat vignetting_k1; + gfloat vignetting_k2; + gfloat vignetting_k3; }; struct _RSLensfunClass { @@ -61,6 +64,9 @@ PROP_APERTURE, PROP_TCA_KR, PROP_TCA_KB, + PROP_VIGNETTING_K1, + PROP_VIGNETTING_K2, + PROP_VIGNETTING_K3, }; static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec); @@ -133,6 +139,21 @@ "tca_kb", "tca_kb", "tca_kb", 0.9, 1.1, 1.0, G_PARAM_READWRITE) ); + g_object_class_install_property(object_class, + PROP_VIGNETTING_K1, g_param_spec_float( + "vignetting_k1", "vignetting_k1", "vignetting_k1", + -1, 2, 0.0, G_PARAM_READWRITE) + ); + g_object_class_install_property(object_class, + PROP_VIGNETTING_K2, g_param_spec_float( + "vignetting_k2", "vignetting_k2", "vignetting_k2", + -1, 2, 0.0, G_PARAM_READWRITE) + ); + g_object_class_install_property(object_class, + PROP_VIGNETTING_K3, g_param_spec_float( + "vignetting_k3", "vignetting_k3", "vignetting_k3", + -1, 2, 0.0, G_PARAM_READWRITE) + ); filter_class->name = "Lensfun filter"; filter_class->get_image = get_image; @@ -150,6 +171,9 @@ lensfun->aperture = 5.6; lensfun->tca_kr = 1.0; lensfun->tca_kb = 1.0; + lensfun->vignetting_k1 = 0.0; + lensfun->vignetting_k2 = 0.0; + lensfun->vignetting_k3 = 0.0; } static void @@ -186,6 +210,15 @@ case PROP_TCA_KB: g_value_set_float(value, lensfun->tca_kb); break; + case PROP_VIGNETTING_K1: + g_value_set_float(value, lensfun->vignetting_k1); + break; + case PROP_VIGNETTING_K2: + g_value_set_float(value, lensfun->vignetting_k2); + break; + case PROP_VIGNETTING_K3: + g_value_set_float(value, lensfun->vignetting_k3); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -225,6 +258,18 @@ lensfun->tca_kb = g_value_get_float(value); rs_filter_changed(RS_FILTER(lensfun), RS_FILTER_CHANGED_PIXELDATA); break; + case PROP_VIGNETTING_K1: + lensfun->vignetting_k1 = g_value_get_float(value); + rs_filter_changed(RS_FILTER(lensfun), RS_FILTER_CHANGED_PIXELDATA); + break; + case PROP_VIGNETTING_K2: + lensfun->vignetting_k2 = g_value_get_float(value); + rs_filter_changed(RS_FILTER(lensfun), RS_FILTER_CHANGED_PIXELDATA); + break; + case PROP_VIGNETTING_K3: + lensfun->vignetting_k3 = g_value_get_float(value); + rs_filter_changed(RS_FILTER(lensfun), RS_FILTER_CHANGED_PIXELDATA); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -387,15 +432,29 @@ lf_get_tca_model_desc (tca.Model, &details, ¶ms); tca.Terms[0] = lensfun->tca_kr; tca.Terms[1] = lensfun->tca_kb; - lf_lens_add_calib_tca((lfLens *) lens, (lfLensCalibTCA *) &tca.Model); + lf_lens_add_calib_tca((lfLens *) lens, (lfLensCalibTCA *) &tca); } + if (lensfun->vignetting_k2 != 0.0 ) + { + /* Set vignetting */ + lfLensCalibVignetting vignetting; + vignetting.Model = LF_VIGNETTING_MODEL_PA; + vignetting.Distance = 1.0; + vignetting.Focal = lensfun->focal; + vignetting.Aperture = lensfun->aperture; + vignetting.Terms[0] = lensfun->vignetting_k1; + vignetting.Terms[1] = lensfun->vignetting_k2; + vignetting.Terms[2] = lensfun->vignetting_k3; + lf_lens_add_calib_vignetting((lfLens *) lens, &vignetting); + } + lfModifier *mod = lf_modifier_new (lens, cameras[0]->CropFactor, input->w, input->h); effective_flags = lf_modifier_initialize (mod, lens, LF_PF_U16, /* lfPixelFormat */ lensfun->focal, /* focal */ lensfun->aperture, /* aperture */ - 0.0, /* distance */ + 1.0, /* distance */ 1.0, /* scale */ LF_UNKNOWN, /* lfLensType targeom, */ /* FIXME: ? */ LF_MODIFY_ALL, /* flags */ /* FIXME: ? */ @@ -418,6 +477,15 @@ g_debug("Effective flags:%s", flags->str); g_string_free(flags, TRUE); + /* Do lensfun vignetting */ + if (effective_flags & LF_MODIFY_VIGNETTING) + { + lf_modifier_apply_color_modification ( + mod, input->pixels, 0.0, 0.0, input->w, input->h, + LF_CR_4 (RED, GREEN, BLUE, UNKNOWN), + input->rowstride*2); + } + if (effective_flags > 0) { guint y_offset, y_per_thread, threaded_h; Modified: trunk/src/application.c =================================================================== --- trunk/src/application.c 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/src/application.c 2009-11-15 19:58:19 UTC (rev 2740) @@ -87,6 +87,7 @@ "aperture", meta->aperture, "tca_kr", rs->photo->settings[rs->current_setting]->tca_kr, "tca_kb", rs->photo->settings[rs->current_setting]->tca_kb, + "vignetting_k2", rs->photo->settings[rs->current_setting]->vignetting_k2, NULL); g_object_unref(lens); } Modified: trunk/src/rs-actions.c =================================================================== --- trunk/src/rs-actions.c 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/src/rs-actions.c 2009-11-15 19:58:19 UTC (rev 2740) @@ -338,7 +338,7 @@ gint mask = 0xffffff; /* Should be RSSettingsMask, is gint to satisfy rs_conf_get_integer() */ GtkWidget *dialog, *cb_box; - GtkWidget *cb_exposure, *cb_saturation, *cb_hue, *cb_contrast, *cb_whitebalance, *cb_curve, *cb_sharpen, *cb_denoise_luma, *cb_denoise_chroma, *cb_channelmixer, *cb_tca; + GtkWidget *cb_exposure, *cb_saturation, *cb_hue, *cb_contrast, *cb_whitebalance, *cb_curve, *cb_sharpen, *cb_denoise_luma, *cb_denoise_chroma, *cb_channelmixer, *cb_tca, *cb_vignetting; if (rs->settings_buffer) { @@ -353,6 +353,7 @@ cb_denoise_chroma = gtk_check_button_new_with_label (_("Color denoise")); cb_channelmixer = gtk_check_button_new_with_label (_("Channel mixer")); cb_tca = gtk_check_button_new_with_label (_("TCA")); + cb_vignetting = gtk_check_button_new_with_label (_("Vignetting")); cb_curve = gtk_check_button_new_with_label (_("Curve")); rs_conf_get_integer(CONF_PASTE_MASK, &mask); @@ -377,6 +378,8 @@ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_channelmixer), TRUE); if (mask & MASK_TCA) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_tca), TRUE); + if (mask & MASK_VIGNETTING) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_vignetting), TRUE); if (mask & MASK_CURVE) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb_curve), TRUE); @@ -392,6 +395,7 @@ gtk_box_pack_start (GTK_BOX (cb_box), cb_denoise_chroma, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (cb_box), cb_channelmixer, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (cb_box), cb_tca, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (cb_box), cb_vignetting, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (cb_box), cb_curve, FALSE, TRUE, 0); dialog = gui_dialog_make_from_widget(GTK_STOCK_DIALOG_QUESTION, _("Select settings to paste"), cb_box); @@ -425,6 +429,8 @@ mask |= MASK_CHANNELMIXER; if (GTK_TOGGLE_BUTTON(cb_tca)->active) mask |= MASK_TCA; + if (GTK_TOGGLE_BUTTON(cb_vignetting)->active) + mask |= MASK_VIGNETTING; if (GTK_TOGGLE_BUTTON(cb_curve)->active) mask |= MASK_CURVE; rs_conf_set_integer(CONF_PASTE_MASK, mask); Modified: trunk/src/rs-cache.c =================================================================== --- trunk/src/rs-cache.c 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/src/rs-cache.c 2009-11-15 19:58:19 UTC (rev 2740) @@ -126,6 +126,9 @@ if (mask & MASK_TCA_KB) xmlTextWriterWriteFormatElement(writer, BAD_CAST "tca_kb", "%f", photo->settings[id]->tca_kb); + if (mask & MASK_VIGNETTING_K2) + xmlTextWriterWriteFormatElement(writer, BAD_CAST "vignetting_k2", "%f", + photo->settings[id]->vignetting_k2); if (mask & MASK_CURVE && photo->settings[id]->curve_nknots > 0) { xmlTextWriterStartElement(writer, BAD_CAST "curve"); @@ -243,6 +246,13 @@ rss->tca_kb = rs_atof((gchar *) val); xmlFree(val); } + else if ((!xmlStrcmp(cur->name, BAD_CAST "vignetting_k2"))) + { + mask |= MASK_VIGNETTING_K2; + val = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + rss->vignetting_k2 = rs_atof((gchar *) val); + xmlFree(val); + } else if ((!xmlStrcmp(cur->name, BAD_CAST "curve"))) { gchar **vals; Modified: trunk/src/rs-preview-widget.c =================================================================== --- trunk/src/rs-preview-widget.c 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/src/rs-preview-widget.c 2009-11-15 19:58:19 UTC (rev 2740) @@ -2202,6 +2202,12 @@ g_object_get(preview->photo->settings[preview->snapshot[view]], "tca_kb", &f, NULL); g_object_set(preview->filter_lensfun[view], "tca_kb", (gfloat) f, NULL); } + if (mask & MASK_VIGNETTING_K2) + { + gfloat f = 1.0; + g_object_get(preview->photo->settings[preview->snapshot[view]], "vignetting_k2", &f, NULL); + g_object_set(preview->filter_lensfun[view], "vignetting_k2", (gfloat) f, NULL); + } } } } Modified: trunk/src/rs-toolbox.c =================================================================== --- trunk/src/rs-toolbox.c 2009-11-15 19:15:44 UTC (rev 2739) +++ trunk/src/rs-toolbox.c 2009-11-15 19:58:19 UTC (rev 2740) @@ -59,11 +59,12 @@ }; #define NCHANNELMIXER (3) -const static BasicSettings tca[] = { - { "tca_kr", 0.00001 }, - { "tca_kb", 0.00001 }, +const static BasicSettings lens[] = { + { "tca_kr", 0.001 }, + { "tca_kb", 0.001 }, + { "vignetting_k2", 0.01 }, }; -#define NTCA (2) +#define NLENS (3) struct _RSToolbox { GtkScrolledWindow parent; @@ -71,7 +72,7 @@ GtkBox *toolbox; GtkRange *ranges[3][NBASICS]; GtkRange *channelmixer[3][NCHANNELMIXER]; - GtkRange *tca[3][NTCA]; + GtkRange *lens[3][NLENS]; RSSettings *settings[3]; GtkWidget *curve[3]; @@ -622,20 +623,20 @@ new_snapshot_page(RSToolbox *toolbox, const gint snapshot) { GtkWidget *vbox = gtk_vbox_new(FALSE, 1); - GtkTable *table, *channelmixertable, *tcatable; + GtkTable *table, *channelmixertable, *lenstable; gint row; table = GTK_TABLE(gtk_table_new(NBASICS, 5, FALSE)); channelmixertable = GTK_TABLE(gtk_table_new(NCHANNELMIXER, 5, FALSE)); - tcatable = GTK_TABLE(gtk_table_new(NTCA, 5, FALSE)); + lenstable = GTK_TABLE(gtk_table_new(NLENS, 5, FALSE)); /* Add basic sliders */ for(row=0;rowranges[snapshot][row] = basic_slider(toolbox, snapshot, table, row, &basic[row]); for(row=0;rowchannelmixer[snapshot][row] = basic_slider(toolbox, snapshot, channelmixertable, row, &channelmixer[row]); - for(row=0;rowtca[snapshot][row] = basic_slider(toolbox, snapshot, tcatable, row, &tca[row]); + for(row=0;rowlens[snapshot][row] = basic_slider(toolbox, snapshot, lenstable, row, &lens[row]); /* Add curve editor */ toolbox->curve[snapshot] = rs_curve_widget_new(); @@ -646,7 +647,7 @@ /* Pack everything nice */ gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("Basic"), GTK_WIDGET(table), "show_basic", TRUE), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("Channel Mixer"), GTK_WIDGET(channelmixertable), "show_channelmixer", TRUE), FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("TCA"), GTK_WIDGET(tcatable), "show_tca", TRUE), FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("Lens corrections"), GTK_WIDGET(lenstable), "show_lens", TRUE), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), gui_box(_("Curve"), toolbox->curve[snapshot], "show_curve", TRUE), FALSE, FALSE, 0); return vbox; @@ -772,9 +773,9 @@ { gtk_widget_set_sensitive(GTK_WIDGET(toolbox->channelmixer[snapshot][i]), FALSE); } - for(i=0;itca[snapshot][i]), FALSE); + gtk_widget_set_sensitive(GTK_WIDGET(toolbox->lens[snapshot][i]), FALSE); } rs_curve_widget_reset(RS_CURVE_WIDGET(toolbox->curve[snapshot])); rs_curve_widget_add_knot(RS_CURVE_WIDGET(toolbox->curve[snapshot]), 0.0,0.0); @@ -809,13 +810,13 @@ gtk_range_set_value(toolbox->channelmixer[snapshot][i], value); } - /* Update tca */ - for(i=0;iphoto->settings[snapshot], tca[i].property_name, &value, NULL); - gtk_range_set_value(toolbox->tca[snapshot][i], value); + g_object_get(toolbox->photo->settings[snapshot], lens[i].property_name, &value, NULL); + gtk_range_set_value(toolbox->lens[snapshot][i], value); } /* Update curve */ @@ -862,8 +863,8 @@ gtk_widget_set_sensitive(GTK_WIDGET(toolbox->ranges[snapshot][i]), TRUE); for(i=0;ichannelmixer[snapshot][i]), TRUE); - for(i=0;itca[snapshot][i]), TRUE); + for(i=0;ilens[snapshot][i]), TRUE); } photo_spatial_changed(toolbox->photo, toolbox); } From anders at kvistmail.dk Sun Nov 15 21:04:54 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Sun, 15 Nov 2009 21:04:54 +0100 Subject: [Rawstudio-commit] r2741 - in trunk: librawstudio plugins/lensfun Message-ID: Author: akv Date: 2009-11-15 21:04:54 +0100 (Sun, 15 Nov 2009) New Revision: 2741 Modified: trunk/librawstudio/rs-settings.c trunk/plugins/lensfun/lensfun.c Log: Added old patch to change behaviour of TCA -1 to +1 instead of 0.9 to 1.1. Modified: trunk/librawstudio/rs-settings.c =================================================================== --- trunk/librawstudio/rs-settings.c 2009-11-15 19:58:19 UTC (rev 2740) +++ trunk/librawstudio/rs-settings.c 2009-11-15 20:04:54 UTC (rev 2741) @@ -116,12 +116,12 @@ g_object_class_install_property(object_class, PROP_TCA_KR, g_param_spec_float( /* FIXME: ? */ "tca_kr", _("tca_kr"), _("tca_kr"), - 0.9, 1.1, 1.0, G_PARAM_READWRITE) + -1, 1, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, PROP_TCA_KB, g_param_spec_float( /* FIXME: ? */ "tca_kb", _("tca_kb"), _("tca_kb"), - 0.9, 1.1, 1.0, G_PARAM_READWRITE) + -1, 1, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, PROP_VIGNETTING_K2, g_param_spec_float( /* FIXME: ? */ Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-15 19:58:19 UTC (rev 2740) +++ trunk/plugins/lensfun/lensfun.c 2009-11-15 20:04:54 UTC (rev 2741) @@ -132,12 +132,12 @@ g_object_class_install_property(object_class, PROP_TCA_KR, g_param_spec_float( "tca_kr", "tca_kr", "tca_kr", - 0.9, 1.1, 1.0, G_PARAM_READWRITE) + -1, 1, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, PROP_TCA_KB, g_param_spec_float( "tca_kb", "tca_kb", "tca_kb", - 0.9, 1.1, 1.0, G_PARAM_READWRITE) + -1, 1, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, PROP_VIGNETTING_K1, g_param_spec_float( @@ -169,8 +169,8 @@ lensfun->lens_model = NULL; lensfun->focal = 50.0; /* Well... */ lensfun->aperture = 5.6; - lensfun->tca_kr = 1.0; - lensfun->tca_kb = 1.0; + lensfun->tca_kr = 0.0; + lensfun->tca_kb = 0.0; lensfun->vignetting_k1 = 0.0; lensfun->vignetting_k2 = 0.0; lensfun->vignetting_k3 = 0.0; @@ -422,16 +422,16 @@ { gint effective_flags; - if (lensfun->tca_kr != 1.0 || lensfun->tca_kb != 1.0) + if (lensfun->tca_kr != 0.0 || lensfun->tca_kb != 0.0) { /* Set TCA */ lfLensCalibTCA tca; tca.Model = LF_TCA_MODEL_LINEAR; - const char *details; - const lfParameter **params; + const char *details = NULL; + const lfParameter **params = NULL; lf_get_tca_model_desc (tca.Model, &details, ¶ms); - tca.Terms[0] = lensfun->tca_kr; - tca.Terms[1] = lensfun->tca_kb; + tca.Terms[0] = (lensfun->tca_kr/100)+1; + tca.Terms[1] = (lensfun->tca_kb/100)+1; lf_lens_add_calib_tca((lfLens *) lens, (lfLensCalibTCA *) &tca); } @@ -440,6 +440,9 @@ /* Set vignetting */ lfLensCalibVignetting vignetting; vignetting.Model = LF_VIGNETTING_MODEL_PA; +// const char *details; +// const lfParameter **params; +// lf_get_vignetting_model_desc(vignetting.Model, &details, ¶ms); vignetting.Distance = 1.0; vignetting.Focal = lensfun->focal; vignetting.Aperture = lensfun->aperture; @@ -504,7 +507,8 @@ t[i].mod = mod; t[i].start_y = y_offset; y_offset += y_per_thread; - y_offset = MIN(input->h, y_offset); + /* FIXME: Why the -1 */ + y_offset = MIN(input->h-1, y_offset); t[i].end_y = y_offset; t[i].threadid = g_thread_create(thread_func, &t[i], TRUE, NULL); From anders at kvistmail.dk Sun Nov 15 22:37:51 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Sun, 15 Nov 2009 22:37:51 +0100 Subject: [Rawstudio-commit] r2742 - trunk/plugins/lensfun Message-ID: Author: akv Date: 2009-11-15 22:37:51 +0100 (Sun, 15 Nov 2009) New Revision: 2742 Modified: trunk/plugins/lensfun/lensfun.c Log: Moving lensfundatabase init to plugin init instead of doing this every time get_image() is called. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-15 20:04:54 UTC (rev 2741) +++ trunk/plugins/lensfun/lensfun.c 2009-11-15 21:37:51 UTC (rev 2742) @@ -33,6 +33,8 @@ struct _RSLensfun { RSFilter parent; + lfDatabase *ldb; + gchar *make; gchar *model; RSLens *lens; @@ -174,6 +176,10 @@ lensfun->vignetting_k1 = 0.0; lensfun->vignetting_k2 = 0.0; lensfun->vignetting_k3 = 0.0; + + /* Initialize Lensfun database */ + lensfun->ldb = lf_db_new (); + lf_db_load (lensfun->ldb); } static void @@ -344,9 +350,8 @@ return response; gint i, j; - lfDatabase *ldb = lf_db_new (); - if (!ldb) + if (!lensfun->ldb) { g_warning ("Failed to create database"); rs_filter_response_set_image(response, input); @@ -354,11 +359,9 @@ return response; } - lf_db_load (ldb); - const lfCamera **cameras = NULL; if (lensfun->make && lensfun->model) - cameras = lf_db_find_cameras(ldb, lensfun->make, lensfun->model); + cameras = lf_db_find_cameras(lensfun->ldb, lensfun->make, lensfun->model); if (!cameras) { @@ -376,7 +379,7 @@ cameras [i]->Variant ? "(" : "", cameras [i]->Variant ? lf_mlstr_get (cameras [i]->Variant) : "", cameras [i]->Variant ? ")" : ""); - g_print ("\tMount: %s\n", lf_db_mount_name (ldb, cameras [i]->Mount)); + g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, cameras [i]->Mount)); g_print ("\tCrop factor: %g\n", cameras [i]->CropFactor); } @@ -390,7 +393,7 @@ make = rs_lens_get_lensfun_make(lensfun->lens); } - lenses = lf_db_find_lenses_hd(ldb, cameras[0], make, model, 0); + lenses = lf_db_find_lenses_hd(lensfun->ldb, cameras[0], make, model, 0); if (!lenses) { g_debug("lens not found (make: \"%s\" model: \"%s\")", lensfun->lens_make, model); @@ -411,7 +414,7 @@ g_print ("\tCCI: %g/%g/%g\n", lenses [i]->RedCCI, lenses [i]->GreenCCI, lenses [i]->BlueCCI); if (lenses [i]->Mounts) for (j = 0; lenses [i]->Mounts [j]; j++) - g_print ("\tMount: %s\n", lf_db_mount_name (ldb, lenses [i]->Mounts [j])); + g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, lenses [i]->Mounts [j])); } const lfLens *lens = lenses [0]; From anders at kvistmail.dk Sun Nov 15 23:01:36 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Sun, 15 Nov 2009 23:01:36 +0100 Subject: [Rawstudio-commit] r2743 - trunk/src Message-ID: Author: akv Date: 2009-11-15 23:01:36 +0100 (Sun, 15 Nov 2009) New Revision: 2743 Modified: trunk/src/rs-batch.c Log: Enabling Lensfun on batch export. Modified: trunk/src/rs-batch.c =================================================================== --- trunk/src/rs-batch.c 2009-11-15 21:37:51 UTC (rev 2742) +++ trunk/src/rs-batch.c 2009-11-15 22:01:36 UTC (rev 2743) @@ -395,7 +395,8 @@ gint done = 0, left = 0; RSFilter *finput = rs_filter_new("RSInputImage16", NULL); RSFilter *fdemosaic = rs_filter_new("RSDemosaic", finput); - RSFilter *frotate = rs_filter_new("RSRotate", fdemosaic); + RSFilter *flensfun = rs_filter_new("RSLensfun", fdemosaic); + RSFilter *frotate = rs_filter_new("RSRotate", flensfun); RSFilter *fcrop = rs_filter_new("RSCrop", frotate); RSFilter *fcache = rs_filter_new("RSCache", fcrop); RSFilter *fresample= rs_filter_new("RSResample", fcache); @@ -524,6 +525,27 @@ "height", 250, NULL); + /* Look up lens */ + RSMetadata *meta = rs_photo_get_metadata(photo); + RSLensDb *lens_db = rs_lens_db_get_default(); + RSLens *lens = rs_lens_db_lookup_from_metadata(lens_db, meta); + + /* Apply lens information to RSLensfun */ + if (lens) + { + rs_filter_set_recursive(fend, + "make", meta->make_ascii, + "model", meta->model_ascii, + "lens", lens, + "focal", (gfloat) meta->focallength, + "aperture", meta->aperture, + "tca_kr", photo->settings[setting_id]->tca_kr, + "tca_kb", photo->settings[setting_id]->tca_kb, + "vignetting_k2", photo->settings[setting_id]->vignetting_k2, + NULL); + g_object_unref(lens); + } + /* Render preview image */ filter_response = rs_filter_get_image8(fend, NULL); pixbuf = rs_filter_response_get_image8(filter_response); @@ -595,6 +617,7 @@ g_object_unref(finput); g_object_unref(fdemosaic); + g_object_unref(flensfun); g_object_unref(frotate); g_object_unref(fcrop); g_object_unref(fcache); From anders at kvistmail.dk Mon Nov 16 17:03:33 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 16 Nov 2009 17:03:33 +0100 Subject: [Rawstudio-commit] r2744 - trunk/librawstudio Message-ID: Author: akv Date: 2009-11-16 17:03:32 +0100 (Mon, 16 Nov 2009) New Revision: 2744 Modified: trunk/librawstudio/rs-settings.c Log: Changed names on lens correction sliders. Modified: trunk/librawstudio/rs-settings.c =================================================================== --- trunk/librawstudio/rs-settings.c 2009-11-15 22:01:36 UTC (rev 2743) +++ trunk/librawstudio/rs-settings.c 2009-11-16 16:03:32 UTC (rev 2744) @@ -115,17 +115,17 @@ ); g_object_class_install_property(object_class, PROP_TCA_KR, g_param_spec_float( /* FIXME: ? */ - "tca_kr", _("tca_kr"), _("tca_kr"), + "tca_kr", _("CA Red"), _("CA Red"), -1, 1, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, PROP_TCA_KB, g_param_spec_float( /* FIXME: ? */ - "tca_kb", _("tca_kb"), _("tca_kb"), + "tca_kb", _("CA Blue"), _("CA Blue"), -1, 1, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, PROP_VIGNETTING_K2, g_param_spec_float( /* FIXME: ? */ - "vignetting_k2", _("vignetting_k2"), _("vignetting_k2"), + "vignetting_k2", _("Vignetting"), _("Vignetting"), -1, 2, 0.0, G_PARAM_READWRITE) ); g_object_class_install_property(object_class, From anders at kvistmail.dk Mon Nov 16 17:20:03 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 16 Nov 2009 17:20:03 +0100 Subject: [Rawstudio-commit] r2745 - trunk/src Message-ID: Author: akv Date: 2009-11-16 17:20:02 +0100 (Mon, 16 Nov 2009) New Revision: 2745 Modified: trunk/src/rs-preview-widget.c Log: Using rs_filter_set_recursive() to set lens data to lensfun filter. Modified: trunk/src/rs-preview-widget.c =================================================================== --- trunk/src/rs-preview-widget.c 2009-11-16 16:03:32 UTC (rev 2744) +++ trunk/src/rs-preview-widget.c 2009-11-16 16:20:02 UTC (rev 2745) @@ -586,24 +586,6 @@ void rs_preview_widget_set_filter(RSPreviewWidget *preview, RSFilter *filter) { - RSFilter *lensfun = NULL; - - RSFilter *f = filter; - - while(RS_IS_FILTER(filter)) - { - if (g_str_equal(RS_FILTER_NAME(filter), "RSLensfun")) - lensfun = filter; - filter = filter->previous; - } - filter = f; - - if (RS_IS_FILTER(lensfun)) - { - preview->filter_lensfun[0] = lensfun; - printf("We found the lensfun filter!\n"); - } - g_assert(RS_IS_PREVIEW_WIDGET(preview)); g_assert(RS_IS_FILTER(filter)); @@ -2190,24 +2172,21 @@ if (preview->snapshot[view] == snapshot) { DIRTY(preview->dirty[view], SCREEN); - if (mask & MASK_TCA_KR) - { - gfloat f = 1.0; - g_object_get(preview->photo->settings[preview->snapshot[view]], "tca_kr", &f, NULL); - g_object_set(preview->filter_lensfun[view], "tca_kr", (gfloat) f, NULL); - } - if (mask & MASK_TCA_KB) - { - gfloat f = 1.0; - g_object_get(preview->photo->settings[preview->snapshot[view]], "tca_kb", &f, NULL); - g_object_set(preview->filter_lensfun[view], "tca_kb", (gfloat) f, NULL); - } - if (mask & MASK_VIGNETTING_K2) - { - gfloat f = 1.0; - g_object_get(preview->photo->settings[preview->snapshot[view]], "vignetting_k2", &f, NULL); - g_object_set(preview->filter_lensfun[view], "vignetting_k2", (gfloat) f, NULL); - } + if (mask & MASK_TCA || mask & MASK_VIGNETTING) + { + gfloat tca_kr = 0.0; + gfloat tca_kb = 0.0; + gfloat vignetting_k2 = 0.0; + g_object_get(preview->photo->settings[preview->snapshot[view]], "tca_kr", &tca_kr, NULL); + g_object_get(preview->photo->settings[preview->snapshot[view]], "tca_kb", &tca_kb, NULL); + g_object_get(preview->photo->settings[preview->snapshot[view]], "vignetting_k2", &vignetting_k2, NULL); + + rs_filter_set_recursive(preview->filter_end[view], + "tca_kr", tca_kr, + "tca_kb", tca_kb, + "vignetting_k2", vignetting_k2, + NULL); + } } } } From anders at kvistmail.dk Mon Nov 16 17:31:42 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 16 Nov 2009 17:31:42 +0100 Subject: [Rawstudio-commit] r2746 - trunk/plugins/lensfun Message-ID: Author: akv Date: 2009-11-16 17:31:42 +0100 (Mon, 16 Nov 2009) New Revision: 2746 Modified: trunk/plugins/lensfun/lensfun.c Log: Only initializing camera and lens on first request to get_image() - marking as dirty when new camera/lens is set. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-16 16:20:02 UTC (rev 2745) +++ trunk/plugins/lensfun/lensfun.c 2009-11-16 16:31:42 UTC (rev 2746) @@ -47,6 +47,11 @@ gfloat vignetting_k1; gfloat vignetting_k2; gfloat vignetting_k3; + + const lfLens *selected_lens; + const lfCamera *selected_camera; + + gboolean DIRTY; }; struct _RSLensfunClass { @@ -240,15 +245,18 @@ case PROP_MAKE: g_free(lensfun->make); lensfun->make = g_value_dup_string(value); + lensfun->DIRTY = TRUE; break; case PROP_MODEL: g_free(lensfun->model); lensfun->model = g_value_dup_string(value); + lensfun->DIRTY = TRUE; break; case PROP_LENS: if (lensfun->lens) g_object_unref(lensfun->lens); lensfun->lens = g_value_dup_object(value); + lensfun->DIRTY = TRUE; break; case PROP_FOCAL: lensfun->focal = g_value_get_float(value); @@ -359,69 +367,80 @@ return response; } - const lfCamera **cameras = NULL; - if (lensfun->make && lensfun->model) - cameras = lf_db_find_cameras(lensfun->ldb, lensfun->make, lensfun->model); - - if (!cameras) + if(lensfun->DIRTY) { - g_debug("camera not found (make: \"%s\" model: \"%s\")", lensfun->make, lensfun->model); - rs_filter_response_set_image(response, input); - g_object_unref(input); - return response; - } - for (i = 0; cameras [i]; i++) - { - g_print ("Camera: %s / %s %s%s%s\n", - lf_mlstr_get (cameras [i]->Maker), - lf_mlstr_get (cameras [i]->Model), - cameras [i]->Variant ? "(" : "", - cameras [i]->Variant ? lf_mlstr_get (cameras [i]->Variant) : "", - cameras [i]->Variant ? ")" : ""); - g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, cameras [i]->Mount)); - g_print ("\tCrop factor: %g\n", cameras [i]->CropFactor); - } + const lfCamera **cameras = NULL; + if (lensfun->make && lensfun->model) + cameras = lf_db_find_cameras(lensfun->ldb, lensfun->make, lensfun->model); - const lfLens **lenses; + if (!cameras) + { + g_debug("camera not found (make: \"%s\" model: \"%s\")", lensfun->make, lensfun->model); + rs_filter_response_set_image(response, input); + g_object_unref(input); + return response; + } - if (lensfun->lens) - { - model = rs_lens_get_lensfun_model(lensfun->lens); - if (!model) - model = rs_lens_get_description(lensfun->lens); - make = rs_lens_get_lensfun_make(lensfun->lens); - } + for (i = 0; cameras [i]; i++) + { + g_print ("Camera: %s / %s %s%s%s\n", + lf_mlstr_get (cameras [i]->Maker), + lf_mlstr_get (cameras [i]->Model), + cameras [i]->Variant ? "(" : "", + cameras [i]->Variant ? lf_mlstr_get (cameras [i]->Variant) : "", + cameras [i]->Variant ? ")" : ""); + g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, cameras [i]->Mount)); + g_print ("\tCrop factor: %g\n", cameras [i]->CropFactor); + } - lenses = lf_db_find_lenses_hd(lensfun->ldb, cameras[0], make, model, 0); - if (!lenses) - { - g_debug("lens not found (make: \"%s\" model: \"%s\")", lensfun->lens_make, model); - rs_filter_response_set_image(response, input); - g_object_unref(input); - return response; - } + /* FIXME: selecting first camera */ + lensfun->selected_camera = cameras [0]; + lf_free (cameras); - for (i = 0; lenses [i]; i++) - { - g_print ("Lens: %s / %s\n", - lf_mlstr_get (lenses [i]->Maker), - lf_mlstr_get (lenses [i]->Model)); - g_print ("\tCrop factor: %g\n", lenses [i]->CropFactor); - g_print ("\tFocal: %g-%g\n", lenses [i]->MinFocal, lenses [i]->MaxFocal); - g_print ("\tAperture: %g-%g\n", lenses [i]->MinAperture, lenses [i]->MaxAperture); - g_print ("\tCenter: %g,%g\n", lenses [i]->CenterX, lenses [i]->CenterY); - g_print ("\tCCI: %g/%g/%g\n", lenses [i]->RedCCI, lenses [i]->GreenCCI, lenses [i]->BlueCCI); - if (lenses [i]->Mounts) - for (j = 0; lenses [i]->Mounts [j]; j++) - g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, lenses [i]->Mounts [j])); + const lfLens **lenses; + + if (lensfun->lens) + { + model = rs_lens_get_lensfun_model(lensfun->lens); + if (!model) + model = rs_lens_get_description(lensfun->lens); + make = rs_lens_get_lensfun_make(lensfun->lens); + } + + lenses = lf_db_find_lenses_hd(lensfun->ldb, cameras[0], make, model, 0); + if (!lenses) + { + g_debug("lens not found (make: \"%s\" model: \"%s\")", lensfun->lens_make, model); + rs_filter_response_set_image(response, input); + g_object_unref(input); + return response; + } + + for (i = 0; lenses [i]; i++) + { + g_print ("Lens: %s / %s\n", + lf_mlstr_get (lenses [i]->Maker), + lf_mlstr_get (lenses [i]->Model)); + g_print ("\tCrop factor: %g\n", lenses [i]->CropFactor); + g_print ("\tFocal: %g-%g\n", lenses [i]->MinFocal, lenses [i]->MaxFocal); + g_print ("\tAperture: %g-%g\n", lenses [i]->MinAperture, lenses [i]->MaxAperture); + g_print ("\tCenter: %g,%g\n", lenses [i]->CenterX, lenses [i]->CenterY); + g_print ("\tCCI: %g/%g/%g\n", lenses [i]->RedCCI, lenses [i]->GreenCCI, lenses [i]->BlueCCI); + if (lenses [i]->Mounts) + for (j = 0; lenses [i]->Mounts [j]; j++) + g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, lenses [i]->Mounts [j])); + } + + /* FIXME: selecting first lens */ + lensfun->selected_lens = lenses [0]; + lf_free (lenses); + + lensfun->DIRTY = FALSE; } - const lfLens *lens = lenses [0]; - lf_free (lenses); - /* Procedd if we got everything */ - if (lf_lens_check((lfLens *) lens)) + if (lf_lens_check((lfLens *) lensfun->selected_lens)) { gint effective_flags; @@ -435,7 +454,7 @@ lf_get_tca_model_desc (tca.Model, &details, ¶ms); tca.Terms[0] = (lensfun->tca_kr/100)+1; tca.Terms[1] = (lensfun->tca_kb/100)+1; - lf_lens_add_calib_tca((lfLens *) lens, (lfLensCalibTCA *) &tca); + lf_lens_add_calib_tca((lfLens *) lensfun->selected_lens, (lfLensCalibTCA *) &tca); } if (lensfun->vignetting_k2 != 0.0 ) @@ -452,11 +471,11 @@ vignetting.Terms[0] = lensfun->vignetting_k1; vignetting.Terms[1] = lensfun->vignetting_k2; vignetting.Terms[2] = lensfun->vignetting_k3; - lf_lens_add_calib_vignetting((lfLens *) lens, &vignetting); + lf_lens_add_calib_vignetting((lfLens *) lensfun->selected_lens, &vignetting); } - lfModifier *mod = lf_modifier_new (lens, cameras[0]->CropFactor, input->w, input->h); - effective_flags = lf_modifier_initialize (mod, lens, + lfModifier *mod = lf_modifier_new (lensfun->selected_lens, lensfun->selected_camera->CropFactor, input->w, input->h); + effective_flags = lf_modifier_initialize (mod, lensfun->selected_lens, LF_PF_U16, /* lfPixelFormat */ lensfun->focal, /* focal */ lensfun->aperture, /* aperture */ From anders at kvistmail.dk Mon Nov 16 22:10:25 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 16 Nov 2009 22:10:25 +0100 Subject: [Rawstudio-commit] r2747 - trunk/plugins/lensfun Message-ID: Author: akv Date: 2009-11-16 22:10:25 +0100 (Mon, 16 Nov 2009) New Revision: 2747 Modified: trunk/plugins/lensfun/lensfun.c Log: Not using lens correction if lens isn't added to RSLensDB. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-16 16:31:42 UTC (rev 2746) +++ trunk/plugins/lensfun/lensfun.c 2009-11-16 21:10:25 UTC (rev 2747) @@ -398,20 +398,19 @@ lensfun->selected_camera = cameras [0]; lf_free (cameras); - const lfLens **lenses; + const lfLens **lenses = NULL; - if (lensfun->lens) + if (rs_lens_get_lensfun_model(lensfun->lens)) { model = rs_lens_get_lensfun_model(lensfun->lens); - if (!model) - model = rs_lens_get_description(lensfun->lens); make = rs_lens_get_lensfun_make(lensfun->lens); + + lenses = lf_db_find_lenses_hd(lensfun->ldb, cameras[0], make, model, 0); } - lenses = lf_db_find_lenses_hd(lensfun->ldb, cameras[0], make, model, 0); if (!lenses) { - g_debug("lens not found (make: \"%s\" model: \"%s\")", lensfun->lens_make, model); + g_debug("lens not found - disabling lens correction"); rs_filter_response_set_image(response, input); g_object_unref(input); return response; From anders at kvistmail.dk Mon Nov 16 23:52:22 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 16 Nov 2009 23:52:22 +0100 Subject: [Rawstudio-commit] r2748 - trunk/plugins/lensfun Message-ID: Author: akv Date: 2009-11-16 23:52:21 +0100 (Mon, 16 Nov 2009) New Revision: 2748 Modified: trunk/plugins/lensfun/lensfun.c Log: Fixing nullpointer. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-16 21:10:25 UTC (rev 2747) +++ trunk/plugins/lensfun/lensfun.c 2009-11-16 22:52:21 UTC (rev 2748) @@ -405,7 +405,7 @@ model = rs_lens_get_lensfun_model(lensfun->lens); make = rs_lens_get_lensfun_make(lensfun->lens); - lenses = lf_db_find_lenses_hd(lensfun->ldb, cameras[0], make, model, 0); + lenses = lf_db_find_lenses_hd(lensfun->ldb, lensfun->selected_camera, make, model, 0); } if (!lenses) From anders at kvistmail.dk Mon Nov 16 23:58:25 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Mon, 16 Nov 2009 23:58:25 +0100 Subject: [Rawstudio-commit] r2749 - trunk/plugins/lensfun Message-ID: Author: akv Date: 2009-11-16 23:58:25 +0100 (Mon, 16 Nov 2009) New Revision: 2749 Modified: trunk/plugins/lensfun/lensfun.c Log: Removing old debug. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-16 22:52:21 UTC (rev 2748) +++ trunk/plugins/lensfun/lensfun.c 2009-11-16 22:58:25 UTC (rev 2749) @@ -382,18 +382,6 @@ return response; } - for (i = 0; cameras [i]; i++) - { - g_print ("Camera: %s / %s %s%s%s\n", - lf_mlstr_get (cameras [i]->Maker), - lf_mlstr_get (cameras [i]->Model), - cameras [i]->Variant ? "(" : "", - cameras [i]->Variant ? lf_mlstr_get (cameras [i]->Variant) : "", - cameras [i]->Variant ? ")" : ""); - g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, cameras [i]->Mount)); - g_print ("\tCrop factor: %g\n", cameras [i]->CropFactor); - } - /* FIXME: selecting first camera */ lensfun->selected_camera = cameras [0]; lf_free (cameras); @@ -416,21 +404,6 @@ return response; } - for (i = 0; lenses [i]; i++) - { - g_print ("Lens: %s / %s\n", - lf_mlstr_get (lenses [i]->Maker), - lf_mlstr_get (lenses [i]->Model)); - g_print ("\tCrop factor: %g\n", lenses [i]->CropFactor); - g_print ("\tFocal: %g-%g\n", lenses [i]->MinFocal, lenses [i]->MaxFocal); - g_print ("\tAperture: %g-%g\n", lenses [i]->MinAperture, lenses [i]->MaxAperture); - g_print ("\tCenter: %g,%g\n", lenses [i]->CenterX, lenses [i]->CenterY); - g_print ("\tCCI: %g/%g/%g\n", lenses [i]->RedCCI, lenses [i]->GreenCCI, lenses [i]->BlueCCI); - if (lenses [i]->Mounts) - for (j = 0; lenses [i]->Mounts [j]; j++) - g_print ("\tMount: %s\n", lf_db_mount_name (lensfun->ldb, lenses [i]->Mounts [j])); - } - /* FIXME: selecting first lens */ lensfun->selected_lens = lenses [0]; lf_free (lenses); From anders at kvistmail.dk Tue Nov 17 00:01:04 2009 From: anders at kvistmail.dk (Anders Kvist) Date: Tue, 17 Nov 2009 00:01:04 +0100 Subject: [Rawstudio-commit] r2750 - trunk/plugins/lensfun Message-ID: Author: akv Date: 2009-11-17 00:01:04 +0100 (Tue, 17 Nov 2009) New Revision: 2750 Modified: trunk/plugins/lensfun/lensfun.c Log: Changed debug to warnings when lens or camera isn't known. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-16 22:58:25 UTC (rev 2749) +++ trunk/plugins/lensfun/lensfun.c 2009-11-16 23:01:04 UTC (rev 2750) @@ -376,7 +376,7 @@ if (!cameras) { - g_debug("camera not found (make: \"%s\" model: \"%s\")", lensfun->make, lensfun->model); + g_warning("camera not found (make: \"%s\" model: \"%s\")", lensfun->make, lensfun->model); rs_filter_response_set_image(response, input); g_object_unref(input); return response; @@ -398,7 +398,7 @@ if (!lenses) { - g_debug("lens not found - disabling lens correction"); + g_warning("lens not found"); rs_filter_response_set_image(response, input); g_object_unref(input); return response; From klauspost at gmail.com Sun Nov 22 16:17:27 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 22 Nov 2009 16:17:27 +0100 Subject: [Rawstudio-commit] r2751 - trunk/plugins/lensfun Message-ID: Author: post Date: 2009-11-22 16:17:27 +0100 (Sun, 22 Nov 2009) New Revision: 2751 Modified: trunk/plugins/lensfun/lensfun.c Log: Lensfun: Added multithreaded vignetting correction. Vignetting no longer overwrites input. Added (future) ROI-support for lensfun. Also set Vignetting and TCA if they are zero to allow resetting it. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-16 23:01:04 UTC (rev 2750) +++ trunk/plugins/lensfun/lensfun.c 2009-11-22 15:17:27 UTC (rev 2751) @@ -296,33 +296,51 @@ RS_IMAGE16 *input; RS_IMAGE16 *output; GThread *threadid; + gint effective_flags; + GdkRectangle *roi; + gint stage; } ThreadInfo; static gpointer thread_func(gpointer _thread_info) { - gint row, col; + gint x, y; ThreadInfo* t = _thread_info; - gfloat *pos = g_new0(gfloat, t->input->w*6); - const gint pixelsize = t->output->pixelsize; - for(row=t->start_y;rowend_y;row++) + if (t->stage == 2) { - gushort *target; - lf_modifier_apply_subpixel_geometry_distortion(t->mod, 0.0, (gfloat) row, t->input->w, 1, pos); - target = GET_PIXEL(t->output, 0, row); - gfloat* l_pos = pos; - - for(col=0;colinput->w;col++) + /* Do lensfun vignetting */ + if (t->effective_flags & LF_MODIFY_VIGNETTING) { - rs_image16_bilinear_full(t->input, target, l_pos); - target += pixelsize; - l_pos += 6; + lf_modifier_apply_color_modification (t->mod, GET_PIXEL(t->input, t->roi->x, t->start_y), + t->roi->x, t->start_y, t->roi->width, t->end_y - t->start_y, + LF_CR_4 (RED, GREEN, BLUE, UNKNOWN), + t->input->rowstride*2); } } - g_free(pos); + if (t->stage == 3) + { + /* Do TCA and distortion */ + gfloat *pos = g_new0(gfloat, t->input->w*6); + const gint pixelsize = t->output->pixelsize; + + for(y = t->start_y; y < t->end_y; y++) + { + gushort *target; + lf_modifier_apply_subpixel_geometry_distortion(t->mod, t->roi->x, (gfloat) y, t->roi->width, 1, pos); + target = GET_PIXEL(t->output, t->roi->x, y); + gfloat* l_pos = pos; + for(x = 0; x < t->roi->width ; x++) + { + rs_image16_bilinear_full(t->input, target, l_pos); + target += pixelsize; + l_pos += 6; + } + } + g_free(pos); + } return NULL; } @@ -337,6 +355,7 @@ RS_IMAGE16 *output = NULL; const gchar *make = NULL; const gchar *model = NULL; + GdkRectangle *roi; previous_response = rs_filter_get_image(filter->previous, request); input = rs_filter_response_get_image(previous_response); @@ -357,7 +376,7 @@ if (!RS_IS_IMAGE16(input)) return response; - gint i, j; + gint i; if (!lensfun->ldb) { @@ -392,7 +411,6 @@ { model = rs_lens_get_lensfun_model(lensfun->lens); make = rs_lens_get_lensfun_make(lensfun->lens); - lenses = lf_db_find_lenses_hd(lensfun->ldb, lensfun->selected_camera, make, model, 0); } @@ -410,41 +428,49 @@ lensfun->DIRTY = FALSE; } - + + roi = rs_filter_request_get_roi(request); + gboolean destroy_roi = FALSE; + printf("ROI: "); + if (!roi) + { + roi = g_new(GdkRectangle, 1); + roi->x = 0; + roi->y = 0; + roi->width = input->w; + roi->height = input->h; + destroy_roi = TRUE; + printf("(new) "); + } + printf("x:%d, y:%d; w:%d, h:%d\n",roi->x,roi->y,roi->width, roi->height); /* Procedd if we got everything */ if (lf_lens_check((lfLens *) lensfun->selected_lens)) { gint effective_flags; - if (lensfun->tca_kr != 0.0 || lensfun->tca_kb != 0.0) - { - /* Set TCA */ - lfLensCalibTCA tca; - tca.Model = LF_TCA_MODEL_LINEAR; - const char *details = NULL; - const lfParameter **params = NULL; - lf_get_tca_model_desc (tca.Model, &details, ¶ms); - tca.Terms[0] = (lensfun->tca_kr/100)+1; - tca.Terms[1] = (lensfun->tca_kb/100)+1; - lf_lens_add_calib_tca((lfLens *) lensfun->selected_lens, (lfLensCalibTCA *) &tca); - } + /* Set TCA */ + lfLensCalibTCA tca; + tca.Model = LF_TCA_MODEL_LINEAR; + const char *details = NULL; + const lfParameter **params = NULL; + lf_get_tca_model_desc (tca.Model, &details, ¶ms); + tca.Terms[0] = (lensfun->tca_kr/100)+1; + tca.Terms[1] = (lensfun->tca_kb/100)+1; + lf_lens_add_calib_tca((lfLens *) lensfun->selected_lens, (lfLensCalibTCA *) &tca); - if (lensfun->vignetting_k2 != 0.0 ) - { - /* Set vignetting */ - lfLensCalibVignetting vignetting; - vignetting.Model = LF_VIGNETTING_MODEL_PA; + /* Set vignetting */ + lfLensCalibVignetting vignetting; + vignetting.Model = LF_VIGNETTING_MODEL_PA; // const char *details; // const lfParameter **params; // lf_get_vignetting_model_desc(vignetting.Model, &details, ¶ms); - vignetting.Distance = 1.0; - vignetting.Focal = lensfun->focal; - vignetting.Aperture = lensfun->aperture; - vignetting.Terms[0] = lensfun->vignetting_k1; - vignetting.Terms[1] = lensfun->vignetting_k2; - vignetting.Terms[2] = lensfun->vignetting_k3; - lf_lens_add_calib_vignetting((lfLens *) lensfun->selected_lens, &vignetting); - } + vignetting.Distance = 1.0; + vignetting.Focal = lensfun->focal; + vignetting.Aperture = lensfun->aperture; + vignetting.Terms[0] = lensfun->vignetting_k1; + vignetting.Terms[1] = lensfun->vignetting_k2; + vignetting.Terms[2] = lensfun->vignetting_k3; + lf_lens_add_calib_vignetting((lfLens *) lensfun->selected_lens, &vignetting); lfModifier *mod = lf_modifier_new (lensfun->selected_lens, lensfun->selected_camera->CropFactor, input->w, input->h); effective_flags = lf_modifier_initialize (mod, lensfun->selected_lens, @@ -474,44 +500,68 @@ g_debug("Effective flags:%s", flags->str); g_string_free(flags, TRUE); - /* Do lensfun vignetting */ - if (effective_flags & LF_MODIFY_VIGNETTING) - { - lf_modifier_apply_color_modification ( - mod, input->pixels, 0.0, 0.0, input->w, input->h, - LF_CR_4 (RED, GREEN, BLUE, UNKNOWN), - input->rowstride*2); - } if (effective_flags > 0) { guint y_offset, y_per_thread, threaded_h; const guint threads = rs_get_number_of_processor_cores(); - output = rs_image16_copy(input, FALSE); ThreadInfo *t = g_new(ThreadInfo, threads); - threaded_h = input->h; + threaded_h = roi->height; y_per_thread = (threaded_h + threads-1)/threads; - y_offset = 0; + y_offset = roi->y; /* Set up job description for individual threads */ for (i = 0; i < threads; i++) { - t[i].input = input; - t[i].output = output; t[i].mod = mod; t[i].start_y = y_offset; y_offset += y_per_thread; - /* FIXME: Why the -1 */ - y_offset = MIN(input->h-1, y_offset); + y_offset = MIN(roi->height, y_offset); t[i].end_y = y_offset; - - t[i].threadid = g_thread_create(thread_func, &t[i], TRUE, NULL); + t[i].effective_flags = effective_flags; + t[i].roi = roi; } - /* Wait for threads to finish */ - for(i = 0; i < threads; i++) - g_thread_join(t[i].threadid); + /* Start threads to apply phase 2, Vignetting and CA Correction */ + if (effective_flags & (LF_MODIFY_VIGNETTING | LF_MODIFY_CCI)) + { + /* Phase 2 is corrected inplace, so copy input first */ + output = rs_image16_copy(input, TRUE); + g_object_unref(input); + for (i = 0; i < threads; i++) + { + t[i].input = t[i].output = output; + t[i].stage = 2; + t[i].threadid = g_thread_create(thread_func, &t[i], TRUE, NULL); + } + + /* Wait for threads to finish */ + for(i = 0; i < threads; i++) + g_thread_join(t[i].threadid); + input = output; + } + + /* Start threads to apply phase 1+3, Chromatic abberation and distortion Correction */ + if (effective_flags & (LF_MODIFY_TCA | LF_MODIFY_DISTORTION | LF_MODIFY_GEOMETRY)) + { + output = rs_image16_copy(input, FALSE); + for (i = 0; i < threads; i++) + { + t[i].input = input; + t[i].output = output; + t[i].stage = 3; + t[i].threadid = g_thread_create(thread_func, &t[i], TRUE, NULL); + } + + /* Wait for threads to finish */ + for(i = 0; i < threads; i++) + g_thread_join(t[i].threadid); + } + else + { + output = rs_image16_copy(input, TRUE); + } g_free(t); rs_filter_response_set_image(response, output); g_object_unref(output); @@ -524,6 +574,8 @@ else g_debug("lf_lens_check() failed"); // lfModifier *mod = lfModifier::Create (lens, opts.Crop, img->width, img->height); + if (destroy_roi) + g_free(roi); g_object_unref(input); return response; From klauspost at gmail.com Sun Nov 22 16:19:11 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 22 Nov 2009 16:19:11 +0100 Subject: [Rawstudio-commit] r2752 - trunk/plugins/resample Message-ID: Author: post Date: 2009-11-22 16:19:10 +0100 (Sun, 22 Nov 2009) New Revision: 2752 Modified: trunk/plugins/resample/resample.c Log: Resampler: Don't remove ROI, if no resampling takes place. Modified: trunk/plugins/resample/resample.c =================================================================== --- trunk/plugins/resample/resample.c 2009-11-22 15:17:27 UTC (rev 2751) +++ trunk/plugins/resample/resample.c 2009-11-22 15:19:10 UTC (rev 2752) @@ -289,6 +289,15 @@ gint input_width = rs_filter_get_width(filter->previous); gint input_height = rs_filter_get_height(filter->previous); + + /* Return the input, if the new size is uninitialized */ + if ((resample->new_width == -1) || (resample->new_height == -1)) + return rs_filter_get_image(filter->previous, request); + + /* Simply return the input, if we don't scale */ + if ((input_width == resample->new_width) && (input_height == resample->new_height)) + return rs_filter_get_image(filter->previous, request); + /* Remove ROI, it doesn't make sense across resampler */ if (rs_filter_request_get_roi(request)) { @@ -300,14 +309,6 @@ else previous_response = rs_filter_get_image(filter->previous, request); - /* Return the input, if the new size is uninitialized */ - if ((resample->new_width == -1) || (resample->new_height == -1)) - return previous_response; - - /* Simply return the input, if we don't scale */ - if ((input_width == resample->new_width) && (input_height == resample->new_height)) - return previous_response; - input = rs_filter_response_get_image(previous_response); if (!RS_IS_IMAGE16(input)) From klauspost at gmail.com Sun Nov 22 16:21:23 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 22 Nov 2009 16:21:23 +0100 Subject: [Rawstudio-commit] r2753 - trunk/plugins/rotate Message-ID: Author: post Date: 2009-11-22 16:21:22 +0100 (Sun, 22 Nov 2009) New Revision: 2753 Modified: trunk/plugins/rotate/rotate.c Log: Rotate: Remove ROI, if image is rotated. Modified: trunk/plugins/rotate/rotate.c =================================================================== --- trunk/plugins/rotate/rotate.c 2009-11-22 15:19:10 UTC (rev 2752) +++ trunk/plugins/rotate/rotate.c 2009-11-22 15:21:22 UTC (rev 2753) @@ -197,11 +197,19 @@ RS_IMAGE16 *output = NULL; gboolean use_fast = FALSE; - previous_response = rs_filter_get_image(filter->previous, request); + if ((ABS(rotate->angle) < 0.001) && (rotate->orientation==0)) + return rs_filter_get_image(filter->previous, request); + + /* FIXME: Handle ROI across rotation */ + if (rs_filter_request_get_roi(request)) + { + RSFilterRequest *new_request = rs_filter_request_clone(request); + rs_filter_request_set_roi(new_request, NULL); + previous_response = rs_filter_get_image(filter->previous, new_request); + g_object_unref(new_request); + } else + previous_response = rs_filter_get_image(filter->previous, request); - if ((rotate->angle < 0.001) && (rotate->orientation==0)) - return previous_response; - input = rs_filter_response_get_image(previous_response); if (!RS_IS_IMAGE16(input)) From klauspost at gmail.com Sun Nov 22 16:23:47 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 22 Nov 2009 16:23:47 +0100 Subject: [Rawstudio-commit] r2754 - trunk/plugins/lensfun Message-ID: Author: post Date: 2009-11-22 16:23:46 +0100 (Sun, 22 Nov 2009) New Revision: 2754 Modified: trunk/plugins/lensfun/lensfun.c Log: Lensfun: Add FIXME note on initial values for Vignetting and TCA. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-22 15:21:22 UTC (rev 2753) +++ trunk/plugins/lensfun/lensfun.c 2009-11-22 15:23:46 UTC (rev 2754) @@ -448,6 +448,7 @@ { gint effective_flags; + /*FIXME: TCA and Vignetting should default to the values in lensfun db */ /* Set TCA */ lfLensCalibTCA tca; tca.Model = LF_TCA_MODEL_LINEAR; From klauspost at gmail.com Sun Nov 22 16:41:31 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 22 Nov 2009 16:41:31 +0100 Subject: [Rawstudio-commit] r2755 - trunk/plugins/lensfun Message-ID: Author: post Date: 2009-11-22 16:41:31 +0100 (Sun, 22 Nov 2009) New Revision: 2755 Modified: trunk/plugins/lensfun/lensfun.c Log: Lensfun: Make ROI respect window offset. Modified: trunk/plugins/lensfun/lensfun.c =================================================================== --- trunk/plugins/lensfun/lensfun.c 2009-11-22 15:23:46 UTC (rev 2754) +++ trunk/plugins/lensfun/lensfun.c 2009-11-22 15:41:31 UTC (rev 2755) @@ -517,7 +517,7 @@ t[i].mod = mod; t[i].start_y = y_offset; y_offset += y_per_thread; - y_offset = MIN(roi->height, y_offset); + y_offset = MIN(roi->y + roi->height, y_offset); t[i].end_y = y_offset; t[i].effective_flags = effective_flags; t[i].roi = roi; From klauspost at gmail.com Sun Nov 22 17:17:19 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 22 Nov 2009 17:17:19 +0100 Subject: [Rawstudio-commit] r2756 - trunk/plugins/crop Message-ID: Author: post Date: 2009-11-22 17:17:19 +0100 (Sun, 22 Nov 2009) New Revision: 2756 Modified: trunk/plugins/crop/crop.c Log: Add ROI for Crop. Modified: trunk/plugins/crop/crop.c =================================================================== --- trunk/plugins/crop/crop.c 2009-11-22 15:41:31 UTC (rev 2755) +++ trunk/plugins/crop/crop.c 2009-11-22 16:17:19 UTC (rev 2756) @@ -264,11 +264,40 @@ calc(crop); - previous_response = rs_filter_get_image(filter->previous, request); /* Special case for full crop */ if ((crop->width == parent_width) && (crop->height==parent_height)) - return previous_response; - + return rs_filter_get_image(filter->previous, request); + + /* Add ROI for cropped region */ + if (!rs_filter_request_get_roi(request)) + { + GdkRectangle* roi = g_new(GdkRectangle, 1); + roi->x = crop->effective.x1; + roi->y = crop->effective.y1; + roi->width = crop->width; + roi->height = crop->height; + RSFilterRequest *new_request = rs_filter_request_clone(request); + rs_filter_request_set_roi(new_request, roi); + previous_response = rs_filter_get_image(filter->previous, new_request); + g_free(roi); + g_object_unref(new_request); + } + else + { + /* Add crop to ROI */ + GdkRectangle* org_roi = rs_filter_request_get_roi(request); + GdkRectangle* roi = g_new(GdkRectangle, 1); + roi->x = org_roi->x + crop->effective.x1; + roi->y = org_roi->y + crop->effective.y1; + roi->width = MIN(org_roi->width, crop->width - org_roi->x); + roi->height = MIN(org_roi->height, crop->height - org_roi->y); + RSFilterRequest *new_request = rs_filter_request_clone(request); + rs_filter_request_set_roi(new_request, roi); + previous_response = rs_filter_get_image(filter->previous, new_request); + g_free(roi); + g_object_unref(new_request); + } + input = rs_filter_response_get_image(previous_response); if (!RS_IS_IMAGE16(input)) From klauspost at gmail.com Sun Nov 22 17:43:32 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 22 Nov 2009 17:43:32 +0100 Subject: [Rawstudio-commit] r2757 - trunk/plugins/dcp Message-ID: Author: post Date: 2009-11-22 17:43:32 +0100 (Sun, 22 Nov 2009) New Revision: 2757 Modified: trunk/plugins/dcp/dcp.c Log: DCP: Do exposure compensation in RGB mode. Modified: trunk/plugins/dcp/dcp.c =================================================================== --- trunk/plugins/dcp/dcp.c 2009-11-22 16:17:19 UTC (rev 2756) +++ trunk/plugins/dcp/dcp.c 2009-11-22 16:43:32 UTC (rev 2757) @@ -1314,12 +1314,8 @@ huesat_map_SSE2(dcp->huesatmap, &dcp->huesatmap_precalc, &h, &s, &v); } - /* Exposure */ - v = _mm_min_ps(max_val, _mm_mul_ps(v, exp)); - - /* Saturation */ - s = _mm_min_ps(max_val, _mm_mul_ps(s, sat)); + s = _mm_max_ps(min_val, _mm_min_ps(max_val, _mm_mul_ps(s, sat))); /* Hue */ __m128 six_ps = _mm_load_ps(_six_ps); @@ -1334,6 +1330,18 @@ h = _mm_sub_ps(h, six_masked_gt); h = _mm_add_ps(h, six_masked_lt); + HSVtoRGB_SSE(&h, &s, &v); + r = h; g = s; b = v; + + /* Exposure */ + r = _mm_min_ps(max_val, _mm_mul_ps(r, exp)); + g = _mm_min_ps(max_val, _mm_mul_ps(g, exp)); + b = _mm_min_ps(max_val, _mm_mul_ps(b, exp)); + + RGBtoHSV_SSE(&r, &g, &b); + h = r; s = g; v = b; + + /* Convert v to lookup values */ /* TODO: Use 8 bit fraction as interpolation, for interpolating @@ -1451,8 +1459,6 @@ if (dcp->huesatmap) huesat_map(dcp->huesatmap, &h, &s, &v); - v = MIN(v * exposure_comp, 1.0); - /* Saturation */ s *= dcp->saturation; s = MIN(s, 1.0); @@ -1460,6 +1466,17 @@ /* Hue */ h += dcp->hue; + /* Back to RGB */ + HSVtoRGB(h, s, v, &r, &g, &b); + + /* Exposure Compensation */ + r = MIN(r * exposure_comp, 1.0); + g = MIN(g * exposure_comp, 1.0); + b = MIN(b * exposure_comp, 1.0); + + /* To HSV */ + RGBtoHSV(r, g, b, &h, &s, &v); + /* Curve */ v = dcp->curve_samples[_S(v)]; From klauspost at gmail.com Mon Nov 23 22:18:48 2009 From: klauspost at gmail.com (Klaus Post) Date: Mon, 23 Nov 2009 22:18:48 +0100 Subject: [Rawstudio-commit] r2758 - trunk/plugins/dcp Message-ID: Author: post Date: 2009-11-23 22:18:48 +0100 (Mon, 23 Nov 2009) New Revision: 2758 Modified: trunk/plugins/dcp/dcp.c Log: DCP: Apply tone curve. Modified: trunk/plugins/dcp/dcp.c =================================================================== --- trunk/plugins/dcp/dcp.c 2009-11-22 16:43:32 UTC (rev 2757) +++ trunk/plugins/dcp/dcp.c 2009-11-23 21:18:48 UTC (rev 2758) @@ -65,8 +65,8 @@ gfloat temp1; gfloat temp2; - RSSpline *baseline_exposure; - gfloat *baseline_exposure_lut; + RSSpline *tone_curve; + gfloat *tone_curve_lut; gboolean has_color_matrix1; gboolean has_color_matrix2; @@ -1092,107 +1092,74 @@ gfloat r = *_r; gfloat g = *_g; gfloat b = *_b; - gfloat rr; - gfloat gg; - gfloat bb; + gfloat rr; + gfloat gg; + gfloat bb; - #define RGBTone(r, g, b, rr, gg, bb)\ - {\ - \ -/* DNG_ASSERT (r >= g && g >= b && r > b, "Logic Error RGBTone");*/\ - \ - rr = tone_lut[_S(r)];\ - bb = tone_lut[_S(b)];\ - \ - gg = bb + ((rr - bb) * (g - b) / (r - b));\ - \ - } + #define RGBTone(lg, md, sm, LG, MD, SM)\ + {\ + LG = tone_lut[_S(lg)];\ + SM = tone_lut[_S(sm)];\ + \ + MD = SM + ((LG - SM) * (md - sm) / (lg - sm));\ + \ + } + /* Tone curve is: + 1. Lookup smallest and largest of R,G,B + 2. Middle value is calculated as (CAPS is curve corrected) + MD = SM + ((LG - SM) * (md - sm) / (lg - sm)) + 3. Store. + */ + if (r >= g) + { - if (r >= g) - { - - if (g > b) - { - - // Case 1: r >= g > b - - RGBTone (r, g, b, rr, gg, bb); - - } - - else if (b > r) - { - - // Case 2: b > r >= g - - RGBTone (b, r, g, bb, rr, gg); - - } - - else if (b > g) - { - - // Case 3: r >= b > g - - RGBTone (r, b, g, rr, bb, gg); - - } - - else - { - - // Case 4: r >= g == b - -// DNG_ASSERT (r >= g && g == b, "Logic Error 2"); - - rr = tone_lut[_S(r)]; - gg = tone_lut[_S(b)]; -// rr = table.Interpolate (r); -// gg = table.Interpolate (g); - bb = gg; - - } - - } - + if (g > b) + { + // Case 1: r >= g > b; hue = 0-1 + RGBTone (r, g, b, rr, gg, bb); + } + else if (b > r) + { + // Case 2: b > r >= g; hue = 4-5 + RGBTone (b, r, g, bb, rr, gg); + } + else if (b > g) + { + // Case 3: r >= b > g; hue = 5-6 + RGBTone (r, b, g, rr, bb, gg); + } else - { + { + // Case 4: r >= g == b; s = 0; + rr = tone_lut[_S(r)]; + gg = tone_lut[_S(b)]; + bb = gg; + } + } + else // g > r + { + if (r >= b) + { + // Case 5: g > r >= b; hue = 1-2 + RGBTone (g, r, b, gg, rr, bb); + } + else if (b > g) + { + // Case 6: b > g > r; hue = 3-4 + RGBTone (b, g, r, bb, gg, rr); + } + else + { + // Case 7: g >= b > r; hue = 2-3 + RGBTone (g, b, r, gg, bb, rr); + } + } - if (r >= b) - { + #undef RGBTone + *_r = rr; + *_g = gg; + *_b = bb; - // Case 5: g > r >= b - - RGBTone (g, r, b, gg, rr, bb); - - } - - else if (b > g) - { - - // Case 6: b > g > r - - RGBTone (b, g, r, bb, gg, rr); - - } - - else - { - - // Case 7: g >= b > r - - RGBTone (g, b, r, gg, bb, rr); - - } - - } - - #undef RGBTone - - *_r = rr; - *_g = gg; - *_b = bb; - } #if defined (__SSE2__) @@ -1225,6 +1192,7 @@ RS_IMAGE16 *image = t->tmp; RSDcp *dcp = t->dcp; gint x, y; + gint i; __m128 h, s, v; __m128i p1,p2; __m128 p1f, p2f, p3f, p4f; @@ -1232,6 +1200,7 @@ __m128i zero = _mm_load_si128((__m128i*)_15_bit_epi32); int xfer[4] __attribute__ ((aligned (16))); + float xfer_ps[12] __attribute__ ((aligned (16))); const gfloat exposure_comp = pow(2.0, dcp->exposure); __m128 exp = _mm_set_ps(exposure_comp, exposure_comp, exposure_comp, exposure_comp); @@ -1370,13 +1339,29 @@ six_masked_lt = _mm_and_ps(six_ps, h_mask_lt); h = _mm_sub_ps(h, six_masked_gt); h = _mm_add_ps(h, six_masked_lt); - - /* s always slightly > 0 */ - s = _mm_max_ps(s, min_val); + /* s always slightly > 0 when converting to RGB */ + s = _mm_max_ps(s, min_val); + HSVtoRGB_SSE(&h, &s, &v); r = h; g = s; b = v; + /* Apply Tone Curve in RGB space*/ + if (dcp->tone_curve_lut) + { + _mm_store_ps(&xfer_ps[0], r); + _mm_store_ps(&xfer_ps[4], g); + _mm_store_ps(&xfer_ps[8], b); + + for( i = 0 ; i < 4 ; i++ ) + rgb_tone(&xfer_ps[i], &xfer_ps[4+i], &xfer_ps[8+i],dcp->tone_curve_lut); + + r = _mm_load_ps(&xfer_ps[0]); + g = _mm_load_ps(&xfer_ps[4]); + b = _mm_load_ps(&xfer_ps[8]); + } + + /* Convert to 16 bit */ __m128 rgb_mul = _mm_load_ps(_16_bit_ps); r = _mm_mul_ps(r, rgb_mul); g = _mm_mul_ps(g, rgb_mul); @@ -1486,6 +1471,10 @@ /* Back to RGB */ HSVtoRGB(h, s, v, &r, &g, &b); + /* Apply tone curve */ + if (dcp->tone_curve_lut) + rgb_tone(&r, &g, &b, dcp->tone_curve_lut); + /* Save as gushort */ pixel[R] = _S(r); pixel[G] = _S(g); @@ -1626,9 +1615,9 @@ dcp->temp2 = rs_dcp_file_get_illuminant2(dcp_file); /* ProfileToneCurve */ - dcp->baseline_exposure = rs_dcp_file_get_tonecurve(dcp_file); - if (dcp->baseline_exposure) - dcp->baseline_exposure_lut = rs_spline_sample(dcp->baseline_exposure, NULL, 65536); + dcp->tone_curve = rs_dcp_file_get_tonecurve(dcp_file); + if (dcp->tone_curve) + dcp->tone_curve_lut = rs_spline_sample(dcp->tone_curve, NULL, 65536); /* FIXME: Free these at some point! */ /* ForwardMatrix */ From klauspost at gmail.com Tue Nov 24 17:23:18 2009 From: klauspost at gmail.com (Klaus Post) Date: Tue, 24 Nov 2009 17:23:18 +0100 Subject: [Rawstudio-commit] r2759 - trunk/plugins/dcp Message-ID: Author: post Date: 2009-11-24 17:23:18 +0100 (Tue, 24 Nov 2009) New Revision: 2759 Modified: trunk/plugins/dcp/dcp.c Log: DCP: Added SSE2 intrinsics tone curve. Modified: trunk/plugins/dcp/dcp.c =================================================================== --- trunk/plugins/dcp/dcp.c 2009-11-23 21:18:48 UTC (rev 2758) +++ trunk/plugins/dcp/dcp.c 2009-11-24 16:23:18 UTC (rev 2759) @@ -1082,7 +1082,84 @@ *_s = s; *_v = v; } +#define DW(A) _mm_castps_si128(A) +#define PS(A) _mm_castsi128_ps(A) +static gfloat _very_small_ps[4] __attribute__ ((aligned (16))) = {1e-15, 1e-15, 1e-15, 1e-15}; +static gfloat _16_bit_ps[4] __attribute__ ((aligned (16))) = {65535.0, 65535.0, 65535.0, 65535.0}; + +void inline +rgb_tone_sse2(__m128* _r, __m128* _g, __m128* _b, const gfloat * const tone_lut) +{ + int xfer[8] __attribute__ ((aligned (16))); + + __m128 r = *_r; + __m128 g = *_g; + __m128 b = *_b; + + __m128 lg = _mm_max_ps(b, _mm_max_ps(r, g)); + __m128 sm = _mm_min_ps(b, _mm_min_ps(r, g)); + __m128i lookup_max = _mm_cvtps_epi32(_mm_mul_ps(lg, + _mm_load_ps(_16_bit_ps))); + __m128i lookup_min = _mm_cvtps_epi32(_mm_mul_ps(sm, + _mm_load_ps(_16_bit_ps))); + + _mm_store_si128((__m128i*)&xfer[0], lookup_max); + _mm_store_si128((__m128i*)&xfer[4], lookup_min); + + /* Lookup */ + __m128 LG = _mm_set_ps(tone_lut[xfer[3]], tone_lut[xfer[2]], tone_lut[xfer[1]], tone_lut[xfer[0]]); + __m128 SM = _mm_set_ps(tone_lut[xfer[7]], tone_lut[xfer[6]], tone_lut[xfer[5]], tone_lut[xfer[4]]); + + __m128i ones = _mm_cmpeq_epi32(DW(r), DW(r)); + __m128i is_r_lg = _mm_cmpeq_epi32(DW(r), DW(lg)); + __m128i is_g_lg = _mm_cmpeq_epi32(DW(g), DW(lg)); + __m128i is_b_lg = _mm_cmpeq_epi32(DW(b), DW(lg)); + + __m128i is_r_sm = _mm_andnot_si128(is_r_lg, _mm_cmpeq_epi32(DW(r), DW(sm))); + __m128i is_g_sm = _mm_andnot_si128(is_g_lg, _mm_cmpeq_epi32(DW(g), DW(sm))); + __m128i is_b_sm = _mm_andnot_si128(is_b_lg, _mm_cmpeq_epi32(DW(b), DW(sm))); + + __m128i is_r_md = _mm_xor_si128(ones, _mm_or_si128(is_r_lg, is_r_sm)); + __m128i is_g_md = _mm_xor_si128(ones, _mm_or_si128(is_g_lg, is_g_sm)); + __m128i is_b_md = _mm_xor_si128(ones, _mm_or_si128(is_b_lg, is_b_sm)); + + __m128 md = PS(_mm_or_si128(_mm_or_si128( + _mm_and_si128(DW(r), is_r_md), + _mm_and_si128(DW(g), is_g_md)), + _mm_and_si128(DW(b), is_b_md))); + + __m128 p = _mm_rcp_ps(_mm_sub_ps(lg, sm)); + __m128 q = _mm_sub_ps(md, sm); + __m128 o = _mm_sub_ps(LG, SM); + __m128 MD = _mm_add_ps(SM, _mm_mul_ps(o, _mm_mul_ps(p, q))); + + is_r_lg = _mm_cmpeq_epi32(DW(r), DW(lg)); + is_g_lg = _mm_cmpeq_epi32(DW(g), DW(lg)); + is_b_lg = _mm_cmpeq_epi32(DW(b), DW(lg)); + + r = PS(_mm_or_si128( _mm_or_si128( + _mm_and_si128(DW(LG), is_r_lg), + _mm_and_si128(DW(SM), is_r_sm)), + _mm_and_si128(DW(MD), is_r_md))); + + g = PS(_mm_or_si128( _mm_or_si128( + _mm_and_si128(DW(LG), is_g_lg), + _mm_and_si128(DW(SM), is_g_sm)), + _mm_and_si128(DW(MD), is_g_md))); + + b = PS(_mm_or_si128( _mm_or_si128( + _mm_and_si128(DW(LG), is_b_lg), + _mm_and_si128(DW(SM), is_b_sm)), + _mm_and_si128(DW(MD), is_b_md))); + *_r = r; + *_g = g; + *_b = b; +} + +#undef DW +#undef PS + #endif // defined __SSE2__ /* RefBaselineRGBTone() */ @@ -1181,8 +1258,6 @@ } static gfloat _rgb_div_ps[4] __attribute__ ((aligned (16))) = {1.0/65535.0, 1.0/65535.0, 1.0/65535.0, 1.0/65535.0}; -static gfloat _very_small_ps[4] __attribute__ ((aligned (16))) = {1e-15, 1e-15, 1e-15, 1e-15}; -static gfloat _16_bit_ps[4] __attribute__ ((aligned (16))) = {65535.0, 65535.0, 65535.0, 65535.0}; static gint _15_bit_epi32[4] __attribute__ ((aligned (16))) = { 32768, 32768, 32768, 32768}; static guint _16_bit_sign[4] __attribute__ ((aligned (16))) = {0x80008000,0x80008000,0x80008000,0x80008000}; @@ -1192,7 +1267,6 @@ RS_IMAGE16 *image = t->tmp; RSDcp *dcp = t->dcp; gint x, y; - gint i; __m128 h, s, v; __m128i p1,p2; __m128 p1f, p2f, p3f, p4f; @@ -1200,7 +1274,6 @@ __m128i zero = _mm_load_si128((__m128i*)_15_bit_epi32); int xfer[4] __attribute__ ((aligned (16))); - float xfer_ps[12] __attribute__ ((aligned (16))); const gfloat exposure_comp = pow(2.0, dcp->exposure); __m128 exp = _mm_set_ps(exposure_comp, exposure_comp, exposure_comp, exposure_comp); @@ -1349,16 +1422,7 @@ /* Apply Tone Curve in RGB space*/ if (dcp->tone_curve_lut) { - _mm_store_ps(&xfer_ps[0], r); - _mm_store_ps(&xfer_ps[4], g); - _mm_store_ps(&xfer_ps[8], b); - - for( i = 0 ; i < 4 ; i++ ) - rgb_tone(&xfer_ps[i], &xfer_ps[4+i], &xfer_ps[8+i],dcp->tone_curve_lut); - - r = _mm_load_ps(&xfer_ps[0]); - g = _mm_load_ps(&xfer_ps[4]); - b = _mm_load_ps(&xfer_ps[8]); + rgb_tone_sse2( &r, &g, &b, dcp->tone_curve_lut); } /* Convert to 16 bit */ From klauspost at gmail.com Tue Nov 24 21:08:57 2009 From: klauspost at gmail.com (Klaus Post) Date: Tue, 24 Nov 2009 21:08:57 +0100 Subject: [Rawstudio-commit] r2760 - trunk/plugins/dcp Message-ID: Author: post Date: 2009-11-24 21:08:56 +0100 (Tue, 24 Nov 2009) New Revision: 2760 Modified: trunk/plugins/dcp/dcp.c Log: DCP: Use Exposure ramp for exposure compensation. Modified: trunk/plugins/dcp/dcp.c =================================================================== --- trunk/plugins/dcp/dcp.c 2009-11-24 16:23:18 UTC (rev 2759) +++ trunk/plugins/dcp/dcp.c 2009-11-24 20:08:56 UTC (rev 2760) @@ -89,7 +89,12 @@ RS_VECTOR3 camera_white; RS_MATRIX3 camera_to_prophoto; - + + gfloat exposure_slope; + gfloat exposure_black; + gfloat exposure_radius; + gfloat exposure_qscale; + #if defined (__SSE2__) PrecalcHSM huesatmap_precalc; PrecalcHSM looktable_precalc; @@ -281,6 +286,30 @@ } static void +init_exposure(RSDcp *dcp) +{ + /* Adobe applies negative exposure to the tone curve instead */ + + /* Todo: Maybe enable shadow (black point) adjustment. */ + gfloat shadow = 5.0; + gfloat minBlack = shadow * 0.001f; + gfloat white = 1.0 / pow (2.0, dcp->exposure); + dcp->exposure_black = 0; + + dcp->exposure_slope = 1.0 / (white - dcp->exposure_black); + const gfloat kMaxCurveX = 0.5; + const gfloat kMaxCurveY = 1.0 / 16.0; + + dcp->exposure_radius = MIN (kMaxCurveX * minBlack, + kMaxCurveY / dcp->exposure_slope); + + if (dcp->exposure_radius > 0.0) + dcp->exposure_qscale = dcp->exposure_slope / (4.0 * dcp->exposure_radius); + else + dcp->exposure_qscale = 0.0; +} + +static void get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { // RSDcp *dcp = RS_DCP(object); @@ -375,6 +404,8 @@ else tmp = g_object_ref(output); + init_exposure(dcp); + guint i, y_offset, y_per_thread, threaded_h; const guint threads = rs_get_number_of_processor_cores(); ThreadInfo *t = g_new(ThreadInfo, threads); @@ -475,6 +506,20 @@ } } +inline gfloat +exposure_ramp (RSDcp *dcp, gfloat x) +{ + if (x <= dcp->exposure_black - dcp->exposure_radius) + return 0.0; + + if (x >= dcp->exposure_black + dcp->exposure_radius) + return MIN((x - dcp->exposure_black) * dcp->exposure_slope, 1.0); + + gfloat y = x - (dcp->exposure_black - dcp->exposure_radius); + + return dcp->exposure_qscale * y * y; +} + #if defined (__SSE2__) static gfloat _zero_ps[4] __attribute__ ((aligned (16))) = {0.0f, 0.0f, 0.0f, 0.0f}; @@ -1275,11 +1320,20 @@ int xfer[4] __attribute__ ((aligned (16))); - const gfloat exposure_comp = pow(2.0, dcp->exposure); - __m128 exp = _mm_set_ps(exposure_comp, exposure_comp, exposure_comp, exposure_comp); __m128 hue_add = _mm_set_ps(dcp->hue, dcp->hue, dcp->hue, dcp->hue); __m128 sat = _mm_set_ps(dcp->saturation, dcp->saturation, dcp->saturation, dcp->saturation); + gfloat e = dcp->exposure_black - dcp->exposure_radius; + __m128 black_minus_radius = _mm_set_ps(e,e,e,e); + e = dcp->exposure_black + dcp->exposure_radius; + __m128 black_plus_radius = _mm_set_ps(e,e,e,e); + e = dcp->exposure_black; + __m128 exposure_black = _mm_set_ps(e,e,e,e); + e = dcp->exposure_slope; + __m128 exposure_slope = _mm_set_ps(e,e,e,e); + e = dcp->exposure_qscale; + __m128 exposure_qscale = _mm_set_ps(e,e,e,e); + float cam_prof[4*4*3] __attribute__ ((aligned (16))); for (x = 0; x < 4; x++ ) { cam_prof[x] = dcp->camera_to_prophoto.coeff[0][0]; @@ -1376,10 +1430,37 @@ r = h; g = s; b = v; /* Exposure */ - r = _mm_min_ps(max_val, _mm_mul_ps(r, exp)); - g = _mm_min_ps(max_val, _mm_mul_ps(g, exp)); - b = _mm_min_ps(max_val, _mm_mul_ps(b, exp)); + __m128 y_r = _mm_sub_ps(r, black_minus_radius); + __m128 y_g = _mm_sub_ps(g, black_minus_radius); + __m128 y_b = _mm_sub_ps(b, black_minus_radius); + y_r = _mm_mul_ps(exposure_qscale,_mm_mul_ps(y_r, y_r)); + y_g = _mm_mul_ps(exposure_qscale,_mm_mul_ps(y_g, y_g)); + y_b = _mm_mul_ps(exposure_qscale,_mm_mul_ps(y_b, y_b)); + __m128 y2_r = _mm_mul_ps(exposure_slope, _mm_sub_ps(r, exposure_black)); + __m128 y2_g = _mm_mul_ps(exposure_slope, _mm_sub_ps(g, exposure_black)); + __m128 y2_b = _mm_mul_ps(exposure_slope, _mm_sub_ps(b, exposure_black)); + __m128 r_mask = _mm_cmpgt_ps(r, black_plus_radius); + __m128 g_mask = _mm_cmpgt_ps(g, black_plus_radius); + __m128 b_mask = _mm_cmpgt_ps(b, black_plus_radius); + y_r = _mm_andnot_ps(r_mask, y_r); + y_g = _mm_andnot_ps(g_mask, y_g); + y_b = _mm_andnot_ps(b_mask, y_b); + y_r = _mm_or_ps(y_r, _mm_and_ps(r_mask, y2_r)); + y_g = _mm_or_ps(y_g, _mm_and_ps(g_mask, y2_g)); + y_b = _mm_or_ps(y_b, _mm_and_ps(b_mask, y2_b)); + r_mask = _mm_cmple_ps(r, black_minus_radius); + g_mask = _mm_cmple_ps(g, black_minus_radius); + b_mask = _mm_cmple_ps(b, black_minus_radius); + r = _mm_andnot_ps(r_mask, y_r); + g = _mm_andnot_ps(g_mask, y_g); + b = _mm_andnot_ps(b_mask, y_b); + /* Clamp */ + max_val = _mm_load_ps(_ones_ps); + r = _mm_min_ps(r, max_val); + g = _mm_min_ps(g, max_val); + b = _mm_min_ps(b, max_val); + RGBtoHSV_SSE(&r, &g, &b); h = r; s = g; v = b; @@ -1476,8 +1557,6 @@ gfloat r, g, b; RS_VECTOR3 pix; - const gfloat exposure_comp = pow(2.0, dcp->exposure); - for(y = t->start_y ; y < t->end_y; y++) { for(x=t->start_x; x < image->w; x++) @@ -1519,9 +1598,9 @@ HSVtoRGB(h, s, v, &r, &g, &b); /* Exposure Compensation */ - r = MIN(r * exposure_comp, 1.0); - g = MIN(g * exposure_comp, 1.0); - b = MIN(b * exposure_comp, 1.0); + r = exposure_ramp(dcp, r); + g = exposure_ramp(dcp, g); + b = exposure_ramp(dcp, b); /* To HSV */ RGBtoHSV(r, g, b, &h, &s, &v); From klauspost at gmail.com Wed Nov 25 19:25:11 2009 From: klauspost at gmail.com (Klaus Post) Date: Wed, 25 Nov 2009 19:25:11 +0100 Subject: [Rawstudio-commit] r2761 - trunk/plugins/dcp Message-ID: Author: post Date: 2009-11-25 19:25:11 +0100 (Wed, 25 Nov 2009) New Revision: 2761 Modified: trunk/plugins/dcp/dcp.c Log: DCP: Enable contrast adjustment. Modified: trunk/plugins/dcp/dcp.c =================================================================== --- trunk/plugins/dcp/dcp.c 2009-11-24 20:08:56 UTC (rev 2760) +++ trunk/plugins/dcp/dcp.c 2009-11-25 18:25:11 UTC (rev 2761) @@ -55,6 +55,7 @@ gfloat exposure; gfloat saturation; + gfloat contrast; gfloat hue; RS_xy_COORD white_xy; @@ -200,6 +201,12 @@ g_object_get(settings, "saturation", &dcp->saturation, NULL); changed = TRUE; } + + if (mask & MASK_CONTRAST) + { + g_object_get(settings, "contrast", &dcp->contrast, NULL); + changed = TRUE; + } if (mask & MASK_HUE) { @@ -526,19 +533,27 @@ static gfloat _ones_ps[4] __attribute__ ((aligned (16))) = {1.0f, 1.0f, 1.0f, 1.0f}; static gfloat _two_ps[4] __attribute__ ((aligned (16))) = {2.0f, 2.0f, 2.0f, 2.0f}; static gfloat _six_ps[4] __attribute__ ((aligned (16))) = {6.0f-1e-15, 6.0f-1e-15, 6.0f-1e-15, 6.0f-1e-15}; +static gfloat _very_small_ps[4] __attribute__ ((aligned (16))) = {1e-15, 1e-15, 1e-15, 1e-15}; static inline void RGBtoHSV_SSE(__m128 *c0, __m128 *c1, __m128 *c2) { __m128 zero_ps = _mm_load_ps(_zero_ps); + __m128 small_ps = _mm_load_ps(_very_small_ps); __m128 ones_ps = _mm_load_ps(_ones_ps); + // Any number > 1 __m128 add_v = _mm_load_ps(_two_ps); __m128 r = *c0; __m128 g = *c1; __m128 b = *c2; + + /* Clamp */ + r = _mm_min_ps(_mm_max_ps(r, small_ps),ones_ps); + g = _mm_min_ps(_mm_max_ps(g, small_ps),ones_ps); + b = _mm_min_ps(_mm_max_ps(b, small_ps),ones_ps); __m128 h, v; v = _mm_max_ps(b,_mm_max_ps(r,g)); @@ -1130,7 +1145,6 @@ #define DW(A) _mm_castps_si128(A) #define PS(A) _mm_castsi128_ps(A) -static gfloat _very_small_ps[4] __attribute__ ((aligned (16))) = {1e-15, 1e-15, 1e-15, 1e-15}; static gfloat _16_bit_ps[4] __attribute__ ((aligned (16))) = {65535.0, 65535.0, 65535.0, 65535.0}; void inline @@ -1141,7 +1155,15 @@ __m128 r = *_r; __m128 g = *_g; __m128 b = *_b; + __m128 small_ps = _mm_load_ps(_very_small_ps); + __m128 ones_ps = _mm_load_ps(_ones_ps); + /* Clamp to avoid lookups out of table */ + r = _mm_min_ps(_mm_max_ps(r, small_ps),ones_ps); + g = _mm_min_ps(_mm_max_ps(g, small_ps),ones_ps); + b = _mm_min_ps(_mm_max_ps(b, small_ps),ones_ps); + + /* Find largest and smallest values */ __m128 lg = _mm_max_ps(b, _mm_max_ps(r, g)); __m128 sm = _mm_min_ps(b, _mm_min_ps(r, g)); __m128i lookup_max = _mm_cvtps_epi32(_mm_mul_ps(lg, @@ -1156,6 +1178,8 @@ __m128 LG = _mm_set_ps(tone_lut[xfer[3]], tone_lut[xfer[2]], tone_lut[xfer[1]], tone_lut[xfer[0]]); __m128 SM = _mm_set_ps(tone_lut[xfer[7]], tone_lut[xfer[6]], tone_lut[xfer[5]], tone_lut[xfer[4]]); + /* Create masks for largest, smallest and medium values */ + /* This is done in integer SSE2, since they have double the throughout */ __m128i ones = _mm_cmpeq_epi32(DW(r), DW(r)); __m128i is_r_lg = _mm_cmpeq_epi32(DW(r), DW(lg)); __m128i is_g_lg = _mm_cmpeq_epi32(DW(g), DW(lg)); @@ -1169,20 +1193,24 @@ __m128i is_g_md = _mm_xor_si128(ones, _mm_or_si128(is_g_lg, is_g_sm)); __m128i is_b_md = _mm_xor_si128(ones, _mm_or_si128(is_b_lg, is_b_sm)); + /* Find all medium values based on masks */ __m128 md = PS(_mm_or_si128(_mm_or_si128( _mm_and_si128(DW(r), is_r_md), _mm_and_si128(DW(g), is_g_md)), _mm_and_si128(DW(b), is_b_md))); - + + /* Calculate tone corrected medium value */ __m128 p = _mm_rcp_ps(_mm_sub_ps(lg, sm)); __m128 q = _mm_sub_ps(md, sm); __m128 o = _mm_sub_ps(LG, SM); __m128 MD = _mm_add_ps(SM, _mm_mul_ps(o, _mm_mul_ps(p, q))); + /* Inserted here again, to lighten register presssure */ is_r_lg = _mm_cmpeq_epi32(DW(r), DW(lg)); is_g_lg = _mm_cmpeq_epi32(DW(g), DW(lg)); is_b_lg = _mm_cmpeq_epi32(DW(b), DW(lg)); + /* Combine corrected values to output RGB */ r = PS(_mm_or_si128( _mm_or_si128( _mm_and_si128(DW(LG), is_r_lg), _mm_and_si128(DW(SM), is_r_sm)), @@ -1197,6 +1225,7 @@ _mm_and_si128(DW(LG), is_b_lg), _mm_and_si128(DW(SM), is_b_sm)), _mm_and_si128(DW(MD), is_b_md))); + *_r = r; *_g = g; *_b = b; @@ -1302,6 +1331,7 @@ return acc; } +static gfloat _half_ps[4] __attribute__ ((aligned (16))) = {0.5f,0.5f,0.5f,0.5f}; static gfloat _rgb_div_ps[4] __attribute__ ((aligned (16))) = {1.0/65535.0, 1.0/65535.0, 1.0/65535.0, 1.0/65535.0}; static gint _15_bit_epi32[4] __attribute__ ((aligned (16))) = { 32768, 32768, 32768, 32768}; static guint _16_bit_sign[4] __attribute__ ((aligned (16))) = {0x80008000,0x80008000,0x80008000,0x80008000}; @@ -1320,6 +1350,7 @@ int xfer[4] __attribute__ ((aligned (16))); + __m128 contrast = _mm_set_ps(dcp->contrast, dcp->contrast, dcp->contrast, dcp->contrast); __m128 hue_add = _mm_set_ps(dcp->hue, dcp->hue, dcp->hue, dcp->hue); __m128 sat = _mm_set_ps(dcp->saturation, dcp->saturation, dcp->saturation, dcp->saturation); @@ -1395,22 +1426,17 @@ g2 = sse_matrix3_mul(&cam_prof[12], r, g, b); b2 = sse_matrix3_mul(&cam_prof[24], r, g, b); - /* Set min/max before HSV conversion */ - __m128 min_val = _mm_load_ps(_very_small_ps); - __m128 max_val = _mm_load_ps(_ones_ps); - r = _mm_max_ps(_mm_min_ps(r2, max_val), min_val); - g = _mm_max_ps(_mm_min_ps(g2, max_val), min_val); - b = _mm_max_ps(_mm_min_ps(b2, max_val), min_val); + RGBtoHSV_SSE(&r2, &g2, &b2); + h = r2; s = g2; v = b2; - RGBtoHSV_SSE(&r, &g, &b); - h = r; s = g; v = b; - if (dcp->huesatmap) { huesat_map_SSE2(dcp->huesatmap, &dcp->huesatmap_precalc, &h, &s, &v); } /* Saturation */ + __m128 max_val = _mm_load_ps(_ones_ps); + __m128 min_val = _mm_load_ps(_very_small_ps); s = _mm_max_ps(min_val, _mm_min_ps(max_val, _mm_mul_ps(s, sat))); /* Hue */ @@ -1455,18 +1481,24 @@ g = _mm_andnot_ps(g_mask, y_g); b = _mm_andnot_ps(b_mask, y_b); - /* Clamp */ - max_val = _mm_load_ps(_ones_ps); - r = _mm_min_ps(r, max_val); - g = _mm_min_ps(g, max_val); - b = _mm_min_ps(b, max_val); - + /* Contrast in gamma 2.0 */ + __m128 half_ps = _mm_load_ps(_half_ps); + min_val = _mm_load_ps(_very_small_ps); + r = _mm_add_ps(_mm_mul_ps(contrast, _mm_sub_ps(_mm_sqrt_ps(r), half_ps)), half_ps); + g = _mm_add_ps(_mm_mul_ps(contrast, _mm_sub_ps(_mm_sqrt_ps(g), half_ps)), half_ps); + b = _mm_add_ps(_mm_mul_ps(contrast, _mm_sub_ps(_mm_sqrt_ps(b), half_ps)), half_ps); + r = _mm_max_ps(r, min_val); + g = _mm_max_ps(g, min_val); + b = _mm_max_ps(b, min_val); + r = _mm_mul_ps(r,r); + g = _mm_mul_ps(g,g); + b = _mm_mul_ps(b,b); + + /* Convert to HSV */ RGBtoHSV_SSE(&r, &g, &b); h = r; s = g; v = b; - /* Convert v to lookup values */ - /* TODO: Use 8 bit fraction as interpolation, for interpolating * a more precise lookup using linear interpolation. Maybe use less than * 16 bits for lookup for speed, 10 bits with interpolation should be enough */ @@ -1602,6 +1634,14 @@ g = exposure_ramp(dcp, g); b = exposure_ramp(dcp, b); + /* Contrast in gamma 2.0 */ + r = MAX((sqrtf(r) - 0.5) * dcp->contrast + 0.5, 0.0f); + r *= r; + g = MAX((sqrtf(g) - 0.5) * dcp->contrast + 0.5, 0.0f); + g *= g; + b = MAX((sqrtf(b) - 0.5) * dcp->contrast + 0.5, 0.0f); + b *= b; + /* To HSV */ RGBtoHSV(r, g, b, &h, &s, &v); From klauspost at gmail.com Sun Nov 29 15:32:21 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 29 Nov 2009 15:32:21 +0100 Subject: [Rawstudio-commit] r2762 - trunk/plugins/resample Message-ID: Author: post Date: 2009-11-29 15:32:21 +0100 (Sun, 29 Nov 2009) New Revision: 2762 Modified: trunk/plugins/resample/resample.c Log: Reasmpler: Fix SSE2 crash where pixelsize != 4. Removed unused timer. Modified: trunk/plugins/resample/resample.c =================================================================== --- trunk/plugins/resample/resample.c 2009-11-25 18:25:11 UTC (rev 2761) +++ trunk/plugins/resample/resample.c 2009-11-29 14:32:21 UTC (rev 2762) @@ -335,11 +335,11 @@ afterVertical = rs_image16_new(input_width, resample->new_height, input->channels, input->pixelsize); // Only even count - guint output_x_per_thread = ((input_width + threads * 2 - 1 ) / threads ) & 0xfffe; + guint output_x_per_thread = ((input_width + threads - 1 ) / threads ); + while ((output_x_per_thread * input->pixelsize) % 16 != 0) + output_x_per_thread++; guint output_x_offset = 0; - GTimer *gt = g_timer_new(); - guint i; for (i = 0; i < threads; i++) { @@ -374,8 +374,6 @@ guint input_y_offset = 0; guint input_y_per_thread = (resample->new_height+threads-1) / threads; - gt = g_timer_new(); - for (i = 0; i < threads; i++) { /* Set info for Horizontal resampler */ From klauspost at gmail.com Sun Nov 29 15:33:24 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 29 Nov 2009 15:33:24 +0100 Subject: [Rawstudio-commit] r2763 - trunk/plugins/dcp Message-ID: Author: post Date: 2009-11-29 15:33:24 +0100 (Sun, 29 Nov 2009) New Revision: 2763 Modified: trunk/plugins/dcp/dcp.c Log: DCP: Check if pixelsize is 4 before using SSE2. Modified: trunk/plugins/dcp/dcp.c =================================================================== --- trunk/plugins/dcp/dcp.c 2009-11-29 14:32:21 UTC (rev 2762) +++ trunk/plugins/dcp/dcp.c 2009-11-29 14:33:24 UTC (rev 2763) @@ -360,7 +360,7 @@ RS_IMAGE16 *tmp = t->tmp; #if defined (__SSE2__) - if (rs_detect_cpu_features() & RS_CPU_FLAG_SSE2) + if (tmp->pixelsize == 4 && (rs_detect_cpu_features() & RS_CPU_FLAG_SSE2)) { render_SSE2(t); if (tmp->w & 3) From klauspost at gmail.com Sun Nov 29 15:34:27 2009 From: klauspost at gmail.com (Klaus Post) Date: Sun, 29 Nov 2009 15:34:27 +0100 Subject: [Rawstudio-commit] r2764 - trunk/plugins/load-dcraw Message-ID: Author: post Date: 2009-11-29 15:34:27 +0100 (Sun, 29 Nov 2009) New Revision: 2764 Modified: trunk/plugins/load-dcraw/dcrawloader.c Log: dcraw will output 3-component images with pixelsize 4. Modified: trunk/plugins/load-dcraw/dcrawloader.c =================================================================== --- trunk/plugins/load-dcraw/dcrawloader.c 2009-11-29 14:33:24 UTC (rev 2763) +++ trunk/plugins/load-dcraw/dcrawloader.c 2009-11-29 14:34:27 UTC (rev 2764) @@ -115,7 +115,7 @@ g_assert(raw->black == 0); /* raw->black is always zero for foveon - I think :) */ - image = rs_image16_new(raw->raw.width, raw->raw.height, 3, 3); + image = rs_image16_new(raw->raw.width, raw->raw.height, 3, 4); /* dcraw calculates 'wrong' rgbMax for Sigma's, let's calculate our own */ for(i=0;i Author: post Date: 2009-11-29 15:41:51 +0100 (Sun, 29 Nov 2009) New Revision: 2765 Modified: trunk/plugins/crop/crop.c Log: Fix crop, if pixelsize isn't 4. Modified: trunk/plugins/crop/crop.c =================================================================== --- trunk/plugins/crop/crop.c 2009-11-29 14:34:27 UTC (rev 2764) +++ trunk/plugins/crop/crop.c 2009-11-29 14:41:51 UTC (rev 2765) @@ -306,7 +306,7 @@ response = rs_filter_response_clone(previous_response); g_object_unref(previous_response); - output = rs_image16_new(crop->width, crop->height, 3, 4); + output = rs_image16_new(crop->width, crop->height, 3, input->pixelsize); rs_filter_response_set_image(response, output); g_object_unref(output); From anders at brander.dk Mon Nov 30 17:54:40 2009 From: anders at brander.dk (Anders Brander) Date: Mon, 30 Nov 2009 17:54:40 +0100 Subject: [Rawstudio-commit] r2766 - trunk/plugins/load-dcraw Message-ID: Author: abrander Date: 2009-11-30 17:54:40 +0100 (Mon, 30 Nov 2009) New Revision: 2766 Modified: trunk/plugins/load-dcraw/dcrawloader.c Log: [312] Fixed dcraw loader for monochrome DNG images. Modified: trunk/plugins/load-dcraw/dcrawloader.c =================================================================== --- trunk/plugins/load-dcraw/dcrawloader.c 2009-11-29 14:41:51 UTC (rev 2765) +++ trunk/plugins/load-dcraw/dcrawloader.c 2009-11-30 16:54:40 UTC (rev 2766) @@ -142,7 +142,32 @@ } } } + else if (raw->raw.colors == 1) + { + dcraw_image_type *input; + image = rs_image16_new(raw->raw.width, raw->raw.height, 3, 4); + + for(row=0 ; row < image->h ; row++) + { + output = GET_PIXEL(image, 0, row); + input = raw->raw.image+row*raw->raw.width; + for(col=0 ; col < image->w ; col++) + { + /* Copy and shift our data to fill 16 bits */ + output[R] = *(*input) << shift; + output[G] = *(*input) << shift; + output[B] = *(*input) << shift; + + /* Advance input by one dcraw_image_type */ + input++; + + /* Advance output by one pixel */ + output += image->pixelsize; + } + } + } + return image; } From anders at brander.dk Mon Nov 30 18:24:55 2009 From: anders at brander.dk (Anders Brander) Date: Mon, 30 Nov 2009 18:24:55 +0100 Subject: [Rawstudio-commit] r2767 - trunk/librawstudio Message-ID: Author: abrander Date: 2009-11-30 18:24:55 +0100 (Mon, 30 Nov 2009) New Revision: 2767 Added: trunk/librawstudio/rs-color-space-icc.c trunk/librawstudio/rs-color-space-icc.h Modified: trunk/librawstudio/Makefile.am trunk/librawstudio/rawstudio.h Log: Added RSColorSpaceIcc to initiate a RSColorSpace from an ICC profile. Modified: trunk/librawstudio/Makefile.am =================================================================== --- trunk/librawstudio/Makefile.am 2009-11-30 16:54:40 UTC (rev 2766) +++ trunk/librawstudio/Makefile.am 2009-11-30 17:24:55 UTC (rev 2767) @@ -15,6 +15,7 @@ rs-1d-function.h \ rs-icc-profile.h \ rs-color-space.h \ + rs-color-space-icc.h \ rs-image.h \ rs-image16.h \ rs-lens.h \ @@ -52,6 +53,7 @@ rs-1d-function.c rs-1d-function.h \ rs-icc-profile.c rs-icc-profile.h \ rs-color-space.c rs-color-space.h \ + rs-color-space-icc.c rs-color-space-icc.h \ rs-image.c rs-image.h \ rs-image16.c rs-image16.h \ rs-lens.c rs-lens.h \ Modified: trunk/librawstudio/rawstudio.h =================================================================== --- trunk/librawstudio/rawstudio.h 2009-11-30 16:54:40 UTC (rev 2766) +++ trunk/librawstudio/rawstudio.h 2009-11-30 17:24:55 UTC (rev 2767) @@ -35,6 +35,7 @@ #include "rs-1d-function.h" #include "rs-icc-profile.h" #include "rs-color-space.h" +#include "rs-color-space-icc.h" #include "rs-image.h" #include "rs-image16.h" #include "rs-metadata.h" Added: trunk/librawstudio/rs-color-space-icc.c =================================================================== --- trunk/librawstudio/rs-color-space-icc.c (rev 0) +++ trunk/librawstudio/rs-color-space-icc.c 2009-11-30 17:24:55 UTC (rev 2767) @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2006-2009 Anders Brander and + * Anders Kvist + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "rawstudio.h" + +G_DEFINE_TYPE(RSColorSpaceIcc, rs_color_space_icc, RS_TYPE_COLOR_SPACE) + +static const RSIccProfile *get_icc_profile(const RSColorSpace *color_space); + +static void +rs_color_space_icc_dispose(GObject *object) +{ + RSColorSpaceIcc *color_space_icc = RS_COLOR_SPACE_ICC(object); + + if (!color_space_icc->dispose_has_run) + { + color_space_icc->dispose_has_run = TRUE; + if (color_space_icc->icc_profile) + g_object_unref(color_space_icc->icc_profile); + } + G_OBJECT_CLASS(rs_color_space_icc_parent_class)->dispose(object); +} + +static void +rs_color_space_icc_class_init(RSColorSpaceIccClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + object_class->dispose = rs_color_space_icc_dispose; + RSColorSpaceClass *colorclass = RS_COLOR_SPACE_CLASS(klass); + + colorclass->get_icc_profile = get_icc_profile; + colorclass->name = "ICC derived color space"; + colorclass->description = "ICC derived color space"; +} + +static void +rs_color_space_icc_init(RSColorSpaceIcc *color_space_icc) +{ +} + +RSColorSpace * +rs_color_space_icc_new_from_icc(RSIccProfile *icc_profile) +{ + RSColorSpaceIcc *color_space_icc = g_object_new(RS_TYPE_COLOR_SPACE_ICC, NULL); + + if (RS_IS_ICC_PROFILE(icc_profile)) + { + color_space_icc->icc_profile = icc_profile; + /* FIXME: Some profiles will be nothing more than a fancy container + * for a color spaces definition, we should recognize those cases and + * try to convert them to RSColorSpace without the need for a CMS */ + RS_COLOR_SPACE(color_space_icc)->flags |= RS_COLOR_SPACE_FLAG_REQUIRES_CMS; + } + + return RS_COLOR_SPACE(color_space_icc); +} + +RSColorSpace * +rs_color_space_icc_new_from_file(const gchar *path) +{ + RSIccProfile *icc_profile = rs_icc_profile_new_from_file(path); + return rs_color_space_icc_new_from_icc(icc_profile); +} + +static const +RSIccProfile *get_icc_profile(const RSColorSpace *color_space) +{ + RSColorSpaceIcc *color_space_icc = RS_COLOR_SPACE_ICC(color_space); + + return color_space_icc->icc_profile; +} Added: trunk/librawstudio/rs-color-space-icc.h =================================================================== --- trunk/librawstudio/rs-color-space-icc.h (rev 0) +++ trunk/librawstudio/rs-color-space-icc.h 2009-11-30 17:24:55 UTC (rev 2767) @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006-2009 Anders Brander and + * Anders Kvist + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef RS_COLOR_SPACE_ICC_H +#define RS_COLOR_SPACE_ICC_H + +#include +#include "rs-color-space.h" + +G_BEGIN_DECLS + +#define RS_TYPE_COLOR_SPACE_ICC rs_color_space_icc_get_type() +#define RS_COLOR_SPACE_ICC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_COLOR_SPACE_ICC, RSColorSpaceIcc)) +#define RS_COLOR_SPACE_ICC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_COLOR_SPACE_ICC, RSColorSpaceIccClass)) +#define RS_IS_COLOR_SPACE_ICC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_COLOR_SPACE_ICC)) +#define RS_IS_COLOR_SPACE_ICC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RS_TYPE_COLOR_SPACE_ICC)) +#define RS_COLOR_SPACE_ICC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RS_TYPE_COLOR_SPACE_ICC, RSColorSpaceIccClass)) + +typedef struct { + RSColorSpace parent; + gboolean dispose_has_run; + + RSIccProfile *icc_profile; +} RSColorSpaceIcc; + +typedef struct { + RSColorSpaceClass parent_class; +} RSColorSpaceIccClass; + +GType rs_color_space_icc_get_type(void); + +RSColorSpaceIcc *rs_color_space_icc_new_from_profile(RSIccProfile *icc_profile); + +RSColorSpace *rs_color_space_icc_new_from_file(const gchar *path); + +G_END_DECLS + +#endif /* RS_COLOR_SPACE_ICC_H */ From anders at brander.dk Mon Nov 30 20:43:16 2009 From: anders at brander.dk (Anders Brander) Date: Mon, 30 Nov 2009 20:43:16 +0100 Subject: [Rawstudio-commit] r2768 - trunk/librawstudio Message-ID: Author: abrander Date: 2009-11-30 20:43:15 +0100 (Mon, 30 Nov 2009) New Revision: 2768 Modified: trunk/librawstudio/rs-plugin-manager.c Log: Added comment describing the importance of initializing classes quickly. Modified: trunk/librawstudio/rs-plugin-manager.c =================================================================== --- trunk/librawstudio/rs-plugin-manager.c 2009-11-30 17:24:55 UTC (rev 2767) +++ trunk/librawstudio/rs-plugin-manager.c 2009-11-30 19:43:15 UTC (rev 2768) @@ -79,6 +79,9 @@ GParamSpec **specs; gint n_specs = 0; gint s; + /* NOTE: Some plugins depend on all classes is initialized before ANY + * instance instantiation takes place, it is NOT safe to just remove + * the next line! */ klass = g_type_class_ref(plugins[i]); g_debug("* %s: %s", g_type_name(plugins[i]), klass->name); specs = g_object_class_list_properties(G_OBJECT_CLASS(klass), &n_specs);