| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "../../../include/fxge/fx_dib.h" | 7 #include "../../../include/fxge/fx_dib.h" |
| 8 #include "../../../include/fxge/fx_ge.h" | 8 #include "../../../include/fxge/fx_ge.h" |
| 9 #include "../../../include/fxcodec/fx_codec.h" | 9 #include "../../../include/fxcodec/fx_codec.h" |
| 10 const FX_DWORD g_dwWinPalette[256] = { | 10 const FX_DWORD g_dwWinPalette[256] = { |
| 11 0xff000000, 0xff800000, 0xff008000, 0xff808000, 0xff000080, 0xff800080, | 11 0xff000000, 0xff800000, 0xff008000, 0xff808000, 0xff000080, 0xff800080, |
| 12 0xff008080, 0xff808080, 0xffC0DCC0, 0xffA6CAF0, 0xff2A3FAA, 0xff2A3FFF, | 12 0xff008080, 0xff808080, 0xffC0DCC0, 0xffA6CAF0, 0xff2A3FAA, 0xff2A3FFF, |
| 13 0xff2A5F00, 0xff2A5F55, 0xff2A5FAA, 0xff2A5FFF, 0xff2A7F00, 0xff2A7F55, | 13 0xff2A5F00, 0xff2A5F55, 0xff2A5FAA, 0xff2A5FFF, 0xff2A7F00, 0xff2A7F55, |
| 14 0xff2A7FAA, 0xff2A7FFF, 0xff2A9F00, 0xff2A9F55, 0xff2A9FAA, 0xff2A9FFF, | 14 0xff2A7FAA, 0xff2A7FFF, 0xff2A9F00, 0xff2A9F55, 0xff2A9FAA, 0xff2A9FFF, |
| 15 0xff2ABF00, 0xff2ABF55, 0xff2ABFAA, 0xff2ABFFF, 0xff2ADF00, 0xff2ADF55, | 15 0xff2ABF00, 0xff2ABF55, 0xff2ABFAA, 0xff2ABFFF, 0xff2ADF00, 0xff2ADF55, |
| 16 0xff2ADFAA, 0xff2ADFFF, 0xff2AFF00, 0xff2AFF55, 0xff2AFFAA, 0xff2AFFFF, | 16 0xff2ADFAA, 0xff2ADFFF, 0xff2AFF00, 0xff2AFF55, 0xff2AFFAA, 0xff2AFFFF, |
| 17 0xff550000, 0xff550055, 0xff5500AA, 0xff5500FF, 0xff551F00, 0xff551F55, | 17 0xff550000, 0xff550055, 0xff5500AA, 0xff5500FF, 0xff551F00, 0xff551F55, |
| 18 0xff551FAA, 0xff551FFF, 0xff553F00, 0xff553F55, 0xff553FAA, 0xff553FFF, | 18 0xff551FAA, 0xff551FFF, 0xff553F00, 0xff553F55, 0xff553FAA, 0xff553FFF, |
| 19 0xff555F00, 0xff555F55, 0xff555FAA, 0xff555FFF, 0xff557F00, 0xff557F55, | 19 0xff555F00, 0xff555F55, 0xff555FAA, 0xff555FFF, 0xff557F00, 0xff557F55, |
| 20 0xff557FAA, 0xff557FFF, 0xff559F00, 0xff559F55, 0xff559FAA, 0xff559FFF, | 20 0xff557FAA, 0xff557FFF, 0xff559F00, 0xff559F55, 0xff559FAA, 0xff559FFF, |
| 21 0xff55BF00, 0xff55BF55, 0xff55BFAA, 0xff55BFFF, 0xff55DF00, 0xff55DF55, | 21 0xff55BF00, 0xff55BF55, 0xff55BFAA, 0xff55BFFF, 0xff55DF00, 0xff55DF55, |
| 22 0xff55DFAA, 0xff55DFFF, 0xff55FF00, 0xff55FF55, 0xff55FFAA, 0xff55FFFF, | 22 0xff55DFAA, 0xff55DFFF, 0xff55FF00, 0xff55FF55, 0xff55FFAA, 0xff55FFFF, |
| 23 0xff7F0000, 0xff7F0055, 0xff7F00AA, 0xff7F00FF, 0xff7F1F00, 0xff7F1F55, | 23 0xff7F0000, 0xff7F0055, 0xff7F00AA, 0xff7F00FF, 0xff7F1F00, 0xff7F1F55, |
| 24 0xff7F1FAA, 0xff7F1FFF, 0xff7F3F00, 0xff7F3F55, 0xff7F3FAA, 0xff7F3FFF, | 24 0xff7F1FAA, 0xff7F1FFF, 0xff7F3F00, 0xff7F3F55, 0xff7F3FAA, 0xff7F3FFF, |
| 25 0xff7F5F00, 0xff7F5F55, 0xff7F5FAA, 0xff7F5FFF, 0xff7F7F00, 0xff7F7F55, | 25 0xff7F5F00, 0xff7F5F55, 0xff7F5FAA, 0xff7F5FFF, 0xff7F7F00, 0xff7F7F55, |
| 26 0xff7F7FAA, 0xff7F7FFF, 0xff7F9F00, 0xff7F9F55, 0xff7F9FAA, 0xff7F9FFF, | 26 0xff7F7FAA, 0xff7F7FFF, 0xff7F9F00, 0xff7F9F55, 0xff7F9FAA, 0xff7F9FFF, |
| 27 0xff7FBF00, 0xff7FBF55, 0xff7FBFAA, 0xff7FBFFF, 0xff7FDF00, 0xff7FDF55, | 27 0xff7FBF00, 0xff7FBF55, 0xff7FBFAA, 0xff7FBFFF, 0xff7FDF00, 0xff7FDF55, |
| 28 0xff7FDFAA, 0xff7FDFFF, 0xff00FF7F, 0xff7FFF55, 0xff7FFFAA, 0xff7FFFFF, | 28 0xff7FDFAA, 0xff7FDFFF, 0xff00FF7F, 0xff7FFF55, 0xff7FFFAA, 0xff7FFFFF, |
| 29 0xffAA0000, 0xffAA0055, 0xffAA00AA, 0xffAA00FF, 0xffAA1F00, 0xffAA1F55, | 29 0xffAA0000, 0xffAA0055, 0xffAA00AA, 0xffAA00FF, 0xffAA1F00, 0xffAA1F55, |
| 30 0xffAA1FAA, 0xffAA1FFF, 0xffAA3F00, 0xffAA3F55, 0xffAA3FAA, 0xffAA3FFF, | 30 0xffAA1FAA, 0xffAA1FFF, 0xffAA3F00, 0xffAA3F55, 0xffAA3FAA, 0xffAA3FFF, |
| 31 0xffAA5F00, 0xffAA5F55, 0xffAA5FAA, 0xffAA5FFF, 0xffAA7F00, 0xffAA7F55, | 31 0xffAA5F00, 0xffAA5F55, 0xffAA5FAA, 0xffAA5FFF, 0xffAA7F00, 0xffAA7F55, |
| 32 0xffAA7FAA, 0xffAA7FFF, 0xffAA9F00, 0xffAA9F55, 0xffAA9FAA, 0xffAA9FFF, | 32 0xffAA7FAA, 0xffAA7FFF, 0xffAA9F00, 0xffAA9F55, 0xffAA9FAA, 0xffAA9FFF, |
| 33 0xffAABF00, 0xffAABF55, 0xffAABFAA, 0xffAABFFF, 0xffAADF00, 0xffAADF55, | 33 0xffAABF00, 0xffAABF55, 0xffAABFAA, 0xffAABFFF, 0xffAADF00, 0xffAADF55, |
| 34 0xffAADFAA, 0xffAADFFF, 0xffAAFF00, 0xffAAFF55, 0xffAAFFAA, 0xffAAFFFF, | 34 0xffAADFAA, 0xffAADFFF, 0xffAAFF00, 0xffAAFF55, 0xffAAFFAA, 0xffAAFFFF, |
| 35 0xffD40000, 0xffD40055, 0xffD400AA, 0xffD400FF, 0xffD41F00, 0xffD41F55, | 35 0xffD40000, 0xffD40055, 0xffD400AA, 0xffD400FF, 0xffD41F00, 0xffD41F55, |
| 36 0xffD41FAA, 0xffD41FFF, 0xffD43F00, 0xffD43F55, 0xffD43FAA, 0xffD43FFF, | 36 0xffD41FAA, 0xffD41FFF, 0xffD43F00, 0xffD43F55, 0xffD43FAA, 0xffD43FFF, |
| 37 0xffD45F00, 0xffD45F55, 0xffD45FAA, 0xffD45FFF, 0xffD47F00, 0xffD47F55, | 37 0xffD45F00, 0xffD45F55, 0xffD45FAA, 0xffD45FFF, 0xffD47F00, 0xffD47F55, |
| 38 0xffD47FAA, 0xffD4F7FF, 0xffD49F00, 0xffD49F55, 0xffD49FAA, 0xffD49FFF, | 38 0xffD47FAA, 0xffD4F7FF, 0xffD49F00, 0xffD49F55, 0xffD49FAA, 0xffD49FFF, |
| 39 0xffD4BF00, 0xffD4BF55, 0xffD4BFAA, 0xffD4BFFF, 0xffD4DF00, 0xffD4DF55, | 39 0xffD4BF00, 0xffD4BF55, 0xffD4BFAA, 0xffD4BFFF, 0xffD4DF00, 0xffD4DF55, |
| 40 0xffD4DFAA, 0xffD4DFFF, 0xffD4FF00, 0xffD4FF55, 0xffD4FFAA, 0xffD4FFFF, | 40 0xffD4DFAA, 0xffD4DFFF, 0xffD4FF00, 0xffD4FF55, 0xffD4FFAA, 0xffD4FFFF, |
| 41 0xffFF0055, 0xffFF00AA, 0xffFF1F00, 0xffFF1F55, 0xffFF1FAA, 0xffFF1FFF, | 41 0xffFF0055, 0xffFF00AA, 0xffFF1F00, 0xffFF1F55, 0xffFF1FAA, 0xffFF1FFF, |
| 42 0xffFF3F00, 0xffFF3F55, 0xffFF3FAA, 0xffFF3FFF, 0xffFF5F00, 0xffFF5F55, | 42 0xffFF3F00, 0xffFF3F55, 0xffFF3FAA, 0xffFF3FFF, 0xffFF5F00, 0xffFF5F55, |
| 43 0xffFF5FAA, 0xffFF5FFF, 0xffFF7F00, 0xffFF7F55, 0xffFF7FAA, 0xffFF7FFF, | 43 0xffFF5FAA, 0xffFF5FFF, 0xffFF7F00, 0xffFF7F55, 0xffFF7FAA, 0xffFF7FFF, |
| 44 0xffFF9F00, 0xffFF9F55, 0xffFF9FAA, 0xffFF9FFF, 0xffFFBF00, 0xffFFBF55, | 44 0xffFF9F00, 0xffFF9F55, 0xffFF9FAA, 0xffFF9FFF, 0xffFFBF00, 0xffFFBF55, |
| 45 0xffFFBFAA, 0xffFFBFFF, 0xffFFDF00, 0xffFFDF55, 0xffFFDFAA, 0xffFFDFFF, | 45 0xffFFBFAA, 0xffFFBFFF, 0xffFFDF00, 0xffFFDF55, 0xffFFDFAA, 0xffFFDFFF, |
| 46 0xffFFFF55, 0xffFFFFAA, 0xffCCCCFF, 0xffFFCCFF, 0xff33FFFF, 0xff66FFFF, | 46 0xffFFFF55, 0xffFFFFAA, 0xffCCCCFF, 0xffFFCCFF, 0xff33FFFF, 0xff66FFFF, |
| 47 0xff99FFFF, 0xffCCFFFF, 0xff007F00, 0xff007F55, 0xff007FAA, 0xff007FFF, | 47 0xff99FFFF, 0xffCCFFFF, 0xff007F00, 0xff007F55, 0xff007FAA, 0xff007FFF, |
| 48 0xff009F00, 0xff009F55, 0xff009FAA, 0xff009FFF, 0xff00BF00, 0xff00BF55, | 48 0xff009F00, 0xff009F55, 0xff009FAA, 0xff009FFF, 0xff00BF00, 0xff00BF55, |
| 49 0xff00BFAA, 0xff00BFFF, 0xff00DF00, 0xff00DF55, 0xff00DFAA, 0xff00DFFF, | 49 0xff00BFAA, 0xff00BFFF, 0xff00DF00, 0xff00DF55, 0xff00DFAA, 0xff00DFFF, |
| 50 0xff00FF55, 0xff00FFAA, 0xff2A0000, 0xff2A0055, 0xff2A00AA, 0xff2A00FF, | 50 0xff00FF55, 0xff00FFAA, 0xff2A0000, 0xff2A0055, 0xff2A00AA, 0xff2A00FF, |
| 51 0xff2A1F00, 0xff2A1F55, 0xff2A1FAA, 0xff2A1FFF, 0xff2A3F00, 0xff2A3F55, | 51 0xff2A1F00, 0xff2A1F55, 0xff2A1FAA, 0xff2A1FFF, 0xff2A3F00, 0xff2A3F55, |
| 52 0xffFFFBF0, 0xffA0A0A4, 0xff808080, 0xffFF0000, 0xff00FF00, 0xffFF0000, | 52 0xffFFFBF0, 0xffA0A0A4, 0xff808080, 0xffFF0000, 0xff00FF00, 0xffFF0000, |
| 53 0xff0000FF, 0xffFF00FF, 0xff00FFFF, 0xffFFFFFF | 53 0xff0000FF, 0xffFF00FF, 0xff00FFFF, 0xffFFFFFF |
| 54 }; | 54 }; |
| 55 const FX_DWORD g_dwMacPalette[256] = { | 55 const FX_DWORD g_dwMacPalette[256] = { |
| 56 0xffFFFFFF, 0xffFFFFCC, 0xffFFFF99, 0xffFFFF66, 0xffFFFF33, 0xffFFFF00, | 56 0xffFFFFFF, 0xffFFFFCC, 0xffFFFF99, 0xffFFFF66, 0xffFFFF33, 0xffFFFF00, |
| 57 0xffFFCCFF, 0xffFFCCCC, 0xffFFCC99, 0xffFFCC66, 0xffFFCC33, 0xffFFCC00, | 57 0xffFFCCFF, 0xffFFCCCC, 0xffFFCC99, 0xffFFCC66, 0xffFFCC33, 0xffFFCC00, |
| 58 0xffFF99FF, 0xffFF99CC, 0xffFF9999, 0xffFF9966, 0xffFF9933, 0xffFF9900, | 58 0xffFF99FF, 0xffFF99CC, 0xffFF9999, 0xffFF9966, 0xffFF9933, 0xffFF9900, |
| 59 0xffFF66FF, 0xffFF66CC, 0xffFF6699, 0xffFF6666, 0xffFF6633, 0xffFF6600, | 59 0xffFF66FF, 0xffFF66CC, 0xffFF6699, 0xffFF6666, 0xffFF6633, 0xffFF6600, |
| 60 0xffFF33FF, 0xffFF33CC, 0xffFF3399, 0xffFF3366, 0xffFF3333, 0xffFF3300, | 60 0xffFF33FF, 0xffFF33CC, 0xffFF3399, 0xffFF3366, 0xffFF3333, 0xffFF3300, |
| 61 0xffFF00FF, 0xffFF00CC, 0xffFF0099, 0xffFF0066, 0xffFF0033, 0xffFF0000, | 61 0xffFF00FF, 0xffFF00CC, 0xffFF0099, 0xffFF0066, 0xffFF0033, 0xffFF0000, |
| 62 0xffCCFFFF, 0xffCCFFCC, 0xffCCFF99, 0xffCCFF66, 0xffCCFF33, 0xffCCFF00, | 62 0xffCCFFFF, 0xffCCFFCC, 0xffCCFF99, 0xffCCFF66, 0xffCCFF33, 0xffCCFF00, |
| 63 0xffCCCCFF, 0xffCCCCCC, 0xffCCCC99, 0xffCCCC66, 0xffCCCC33, 0xffCCCC00, | 63 0xffCCCCFF, 0xffCCCCCC, 0xffCCCC99, 0xffCCCC66, 0xffCCCC33, 0xffCCCC00, |
| 64 0xffCC99FF, 0xffCC99CC, 0xffCC9999, 0xffCC9966, 0xffCC9933, 0xffCC9900, | 64 0xffCC99FF, 0xffCC99CC, 0xffCC9999, 0xffCC9966, 0xffCC9933, 0xffCC9900, |
| 65 0xffCC66FF, 0xffCC66CC, 0xffCC6699, 0xffCC6666, 0xffCC6633, 0xffCC6600, | 65 0xffCC66FF, 0xffCC66CC, 0xffCC6699, 0xffCC6666, 0xffCC6633, 0xffCC6600, |
| 66 0xffCC33FF, 0xffCC33CC, 0xffCC3399, 0xffCC3366, 0xffCC3333, 0xffCC3300, | 66 0xffCC33FF, 0xffCC33CC, 0xffCC3399, 0xffCC3366, 0xffCC3333, 0xffCC3300, |
| 67 0xffCC00FF, 0xffCC00CC, 0xffCC0099, 0xffCC0066, 0xffCC0033, 0xffCC0000, | 67 0xffCC00FF, 0xffCC00CC, 0xffCC0099, 0xffCC0066, 0xffCC0033, 0xffCC0000, |
| 68 0xff99FFFF, 0xff99FFCC, 0xff99FF99, 0xff99FF66, 0xff99FF33, 0xff99FF00, | 68 0xff99FFFF, 0xff99FFCC, 0xff99FF99, 0xff99FF66, 0xff99FF33, 0xff99FF00, |
| 69 0xff99CCFF, 0xff99CCCC, 0xff99CC99, 0xff99CC66, 0xff99CC33, 0xff99CC00, | 69 0xff99CCFF, 0xff99CCCC, 0xff99CC99, 0xff99CC66, 0xff99CC33, 0xff99CC00, |
| 70 0xff9999FF, 0xff9999CC, 0xff999999, 0xff999966, 0xff999933, 0xff999900, | 70 0xff9999FF, 0xff9999CC, 0xff999999, 0xff999966, 0xff999933, 0xff999900, |
| 71 0xff9966FF, 0xff9966CC, 0xff996699, 0xff996666, 0xff996633, 0xff996600, | 71 0xff9966FF, 0xff9966CC, 0xff996699, 0xff996666, 0xff996633, 0xff996600, |
| 72 0xff9933FF, 0xff9933CC, 0xff993399, 0xff993366, 0xff993333, 0xff993300, | 72 0xff9933FF, 0xff9933CC, 0xff993399, 0xff993366, 0xff993333, 0xff993300, |
| 73 0xff9900FF, 0xff9900CC, 0xff990099, 0xff990066, 0xff990033, 0xff990000, | 73 0xff9900FF, 0xff9900CC, 0xff990099, 0xff990066, 0xff990033, 0xff990000, |
| 74 0xff66FFFF, 0xff66FFCC, 0xff66FF99, 0xff66FF66, 0xff66FF33, 0xff66FF00, | 74 0xff66FFFF, 0xff66FFCC, 0xff66FF99, 0xff66FF66, 0xff66FF33, 0xff66FF00, |
| 75 0xff66CCFF, 0xff66CCCC, 0xff66CC99, 0xff66CC66, 0xff66CC33, 0xff66CC00, | 75 0xff66CCFF, 0xff66CCCC, 0xff66CC99, 0xff66CC66, 0xff66CC33, 0xff66CC00, |
| 76 0xff6699FF, 0xff6699CC, 0xff669999, 0xff669966, 0xff669933, 0xff669900, | 76 0xff6699FF, 0xff6699CC, 0xff669999, 0xff669966, 0xff669933, 0xff669900, |
| 77 0xff6666FF, 0xff6666CC, 0xff666699, 0xff666666, 0xff666633, 0xff666600, | 77 0xff6666FF, 0xff6666CC, 0xff666699, 0xff666666, 0xff666633, 0xff666600, |
| 78 0xff6633FF, 0xff6633CC, 0xff663399, 0xff663366, 0xff663333, 0xff663300, | 78 0xff6633FF, 0xff6633CC, 0xff663399, 0xff663366, 0xff663333, 0xff663300, |
| 79 0xff6600FF, 0xff6600CC, 0xff660099, 0xff660066, 0xff660033, 0xff660000, | 79 0xff6600FF, 0xff6600CC, 0xff660099, 0xff660066, 0xff660033, 0xff660000, |
| 80 0xff33FFFF, 0xff33FFCC, 0xff33FF99, 0xff33FF66, 0xff33FF33, 0xff33FF00, | 80 0xff33FFFF, 0xff33FFCC, 0xff33FF99, 0xff33FF66, 0xff33FF33, 0xff33FF00, |
| 81 0xff33CCFF, 0xff33CCCC, 0xff33CC99, 0xff33CC66, 0xff33CC33, 0xff33CC00, | 81 0xff33CCFF, 0xff33CCCC, 0xff33CC99, 0xff33CC66, 0xff33CC33, 0xff33CC00, |
| 82 0xff3399FF, 0xff3399CC, 0xff339999, 0xff339966, 0xff339933, 0xff339900, | 82 0xff3399FF, 0xff3399CC, 0xff339999, 0xff339966, 0xff339933, 0xff339900, |
| 83 0xff3366FF, 0xff3366CC, 0xff336699, 0xff336666, 0xff336633, 0xff336600, | 83 0xff3366FF, 0xff3366CC, 0xff336699, 0xff336666, 0xff336633, 0xff336600, |
| 84 0xff3333FF, 0xff3333CC, 0xff333399, 0xff333366, 0xff333333, 0xff333300, | 84 0xff3333FF, 0xff3333CC, 0xff333399, 0xff333366, 0xff333333, 0xff333300, |
| 85 0xff3300FF, 0xff3300CC, 0xff330099, 0xff330066, 0xff330033, 0xff330000, | 85 0xff3300FF, 0xff3300CC, 0xff330099, 0xff330066, 0xff330033, 0xff330000, |
| 86 0xff00FFFF, 0xff00FFCC, 0xff00FF99, 0xff00FF66, 0xff00FF33, 0xff00FF00, | 86 0xff00FFFF, 0xff00FFCC, 0xff00FF99, 0xff00FF66, 0xff00FF33, 0xff00FF00, |
| 87 0xff00CCFF, 0xff00CCCC, 0xff00CC99, 0xff00CC66, 0xff00CC33, 0xff00CC00, | 87 0xff00CCFF, 0xff00CCCC, 0xff00CC99, 0xff00CC66, 0xff00CC33, 0xff00CC00, |
| 88 0xff0099FF, 0xff0099CC, 0xff009999, 0xff009966, 0xff009933, 0xff009900, | 88 0xff0099FF, 0xff0099CC, 0xff009999, 0xff009966, 0xff009933, 0xff009900, |
| 89 0xff0066FF, 0xff0066CC, 0xff006699, 0xff006666, 0xff006633, 0xff006600, | 89 0xff0066FF, 0xff0066CC, 0xff006699, 0xff006666, 0xff006633, 0xff006600, |
| 90 0xff0033FF, 0xff0033CC, 0xff003399, 0xff003366, 0xff003333, 0xff003300, | 90 0xff0033FF, 0xff0033CC, 0xff003399, 0xff003366, 0xff003333, 0xff003300, |
| 91 0xff0000FF, 0xff0000CC, 0xff000099, 0xff000066, 0xff000033, | 91 0xff0000FF, 0xff0000CC, 0xff000099, 0xff000066, 0xff000033, 0xffEE0000, |
| 92 0xffEE0000, 0xffDD0000, 0xffBB0000, 0xffAA0000, 0xff880000, 0xff770000, | 92 0xffDD0000, 0xffBB0000, 0xffAA0000, 0xff880000, 0xff770000, 0xff550000, |
| 93 0xff550000, 0xff440000, 0xff220000, 0xff110000, 0xff00EE00, 0xff00DD00, | 93 0xff440000, 0xff220000, 0xff110000, 0xff00EE00, 0xff00DD00, 0xff00BB00, |
| 94 0xff00BB00, 0xff00AA00, 0xff008800, 0xff007700, 0xff005500, 0xff004400, | 94 0xff00AA00, 0xff008800, 0xff007700, 0xff005500, 0xff004400, 0xff002200, |
| 95 0xff002200, 0xff001100, 0xff0000EE, 0xff0000DD, 0xff0000BB, 0xff0000AA, | 95 0xff001100, 0xff0000EE, 0xff0000DD, 0xff0000BB, 0xff0000AA, 0xff000088, |
| 96 0xff000088, 0xff000077, 0xff000055, 0xff000044, 0xff000022, 0xff000011, | 96 0xff000077, 0xff000055, 0xff000044, 0xff000022, 0xff000011, 0xffEEEEEE, |
| 97 0xffEEEEEE, 0xffDDDDDD, 0xffBBBBBB, 0xffAAAAAA, 0xff888888, 0xff777777, | 97 0xffDDDDDD, 0xffBBBBBB, 0xffAAAAAA, 0xff888888, 0xff777777, 0xff555555, |
| 98 0xff555555, 0xff444444, 0xff222222, 0xff111111, 0xff000000 | 98 0xff444444, 0xff222222, 0xff111111, 0xff000000 |
| 99 }; | 99 }; |
| 100 class CFX_Palette : public CFX_Object | 100 class CFX_Palette : public CFX_Object { |
| 101 { | 101 public: |
| 102 public: | 102 CFX_Palette(); |
| 103 CFX_Palette(); | 103 ~CFX_Palette(); |
| 104 ~CFX_Palette(); | |
| 105 public: | |
| 106 FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap, int dwPaletteType); | |
| 107 FX_DWORD* GetPalette() const | |
| 108 { | |
| 109 return m_pPalette; | |
| 110 } | |
| 111 | 104 |
| 112 FX_DWORD* GetColorLut()const | 105 public: |
| 113 { | 106 FX_BOOL BuildPalette(const CFX_DIBSource* pBitmap, int dwPaletteType); |
| 114 return m_cLut; | 107 FX_DWORD* GetPalette() const { return m_pPalette; } |
| 115 } | 108 |
| 116 FX_DWORD* GetAmountLut()const | 109 FX_DWORD* GetColorLut() const { return m_cLut; } |
| 117 { | 110 FX_DWORD* GetAmountLut() const { return m_aLut; } |
| 118 return m_aLut; | 111 FX_INT32 Getlut() const { return m_lut; } |
| 119 } | 112 |
| 120 FX_INT32 Getlut()const | 113 protected: |
| 121 { | 114 FX_DWORD* m_pPalette; |
| 122 return m_lut; | 115 FX_DWORD* m_cLut; |
| 123 } | 116 FX_DWORD* m_aLut; |
| 124 protected: | 117 int m_lut; |
| 125 FX_DWORD* m_pPalette; | |
| 126 FX_DWORD* m_cLut; | |
| 127 FX_DWORD* m_aLut; | |
| 128 int m_lut; | |
| 129 }; | 118 }; |
| 130 int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r) | 119 int _Partition(FX_DWORD* alut, FX_DWORD* clut, int l, int r) { |
| 131 { | 120 FX_DWORD p_a = alut[l]; |
| 132 FX_DWORD p_a = alut[l]; | 121 FX_DWORD p_c = clut[l]; |
| 133 FX_DWORD p_c = clut[l]; | 122 while (l < r) { |
| 134 while(l < r) { | 123 while (l < r && alut[r] >= p_a) { |
| 135 while(l < r && alut[r] >= p_a) { | 124 r--; |
| 136 r--; | 125 } |
| 137 } | 126 if (l < r) { |
| 138 if (l < r) { | 127 alut[l] = alut[r]; |
| 139 alut[l] = alut[r]; | 128 clut[l++] = clut[r]; |
| 140 clut[l++] = clut[r]; | 129 } |
| 141 } | 130 while (l < r && alut[l] <= p_a) { |
| 142 while(l < r && alut[l] <= p_a) { | 131 l++; |
| 143 l++; | 132 } |
| 144 } | 133 if (l < r) { |
| 145 if (l < r) { | 134 alut[r] = alut[l]; |
| 146 alut[r] = alut[l]; | 135 clut[r--] = clut[l]; |
| 147 clut[r--] = clut[l]; | 136 } |
| 148 } | 137 } |
| 149 } | 138 alut[l] = p_a; |
| 150 alut[l] = p_a; | 139 clut[l] = p_c; |
| 151 clut[l] = p_c; | 140 return l; |
| 152 return l; | 141 } |
| 153 } | 142 void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r) { |
| 154 void _Qsort(FX_DWORD* alut, FX_DWORD* clut, int l, int r) | 143 if (l < r) { |
| 155 { | 144 int pI = _Partition(alut, clut, l, r); |
| 156 if(l < r) { | 145 _Qsort(alut, clut, l, pI - 1); |
| 157 int pI = _Partition(alut, clut, l, r); | 146 _Qsort(alut, clut, pI + 1, r); |
| 158 _Qsort(alut, clut, l, pI - 1); | 147 } |
| 159 _Qsort(alut, clut, pI + 1, r); | 148 } |
| 160 } | 149 void _ColorDecode(FX_DWORD pal_v, FX_BYTE& r, FX_BYTE& g, FX_BYTE& b) { |
| 161 } | 150 r = (FX_BYTE)((pal_v & 0xf00) >> 4); |
| 162 void _ColorDecode(FX_DWORD pal_v, FX_BYTE& r, FX_BYTE& g, FX_BYTE& b) | 151 g = (FX_BYTE)(pal_v & 0x0f0); |
| 163 { | 152 b = (FX_BYTE)((pal_v & 0x00f) << 4); |
| 164 r = (FX_BYTE)((pal_v & 0xf00) >> 4); | 153 } |
| 165 g = (FX_BYTE)(pal_v & 0x0f0); | 154 void _Obtain_Pal(FX_DWORD* aLut, |
| 166 b = (FX_BYTE)((pal_v & 0x00f) << 4); | 155 FX_DWORD* cLut, |
| 167 } | 156 FX_DWORD* dest_pal, |
| 168 void _Obtain_Pal(FX_DWORD* aLut, FX_DWORD*cLut, FX_DWORD* dest_pal, int pal_type
, FX_DWORD* win_mac_pal, FX_DWORD lut) | 157 int pal_type, |
| 169 { | 158 FX_DWORD* win_mac_pal, |
| 170 int row, col; | 159 FX_DWORD lut) { |
| 171 FX_DWORD lut_1 = lut - 1; | 160 int row, col; |
| 172 if (pal_type == FXDIB_PALETTE_LOC) { | 161 FX_DWORD lut_1 = lut - 1; |
| 173 for (row = 0; row < 256; row++) { | 162 if (pal_type == FXDIB_PALETTE_LOC) { |
| 174 int lut_offset = lut_1 - row; | 163 for (row = 0; row < 256; row++) { |
| 175 if (lut_offset < 0) { | 164 int lut_offset = lut_1 - row; |
| 176 lut_offset += 256; | 165 if (lut_offset < 0) { |
| 177 } | 166 lut_offset += 256; |
| 178 FX_DWORD color = cLut[lut_offset]; | 167 } |
| 179 FX_BYTE r, g, b; | 168 FX_DWORD color = cLut[lut_offset]; |
| 180 _ColorDecode(color, r, g, b); | 169 FX_BYTE r, g, b; |
| 181 dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff0
00000; | 170 _ColorDecode(color, r, g, b); |
| 182 aLut[lut_offset] = row; | 171 dest_pal[row] = ((FX_DWORD)r << 16) | ((FX_DWORD)g << 8) | b | 0xff000000; |
| 183 } | 172 aLut[lut_offset] = row; |
| 173 } |
| 174 } else { |
| 175 for (row = 0; row < 256; row++) { |
| 176 int lut_offset = lut_1 - row; |
| 177 if (lut_offset < 0) { |
| 178 lut_offset += 256; |
| 179 } |
| 180 FX_BYTE r, g, b; |
| 181 _ColorDecode(cLut[lut_offset], r, g, b); |
| 182 int error, min_error = 1000000; |
| 183 int c_index = 0; |
| 184 for (col = 0; col < 256; col++) { |
| 185 FX_DWORD p_color = win_mac_pal[col]; |
| 186 int d_r = r - (FX_BYTE)(p_color >> 16); |
| 187 int d_g = g - (FX_BYTE)(p_color >> 8); |
| 188 int d_b = b - (FX_BYTE)p_color; |
| 189 error = d_r * d_r + d_g * d_g + d_b * d_b; |
| 190 if (error < min_error) { |
| 191 min_error = error; |
| 192 c_index = col; |
| 193 } |
| 194 } |
| 195 dest_pal[row] = win_mac_pal[c_index]; |
| 196 aLut[lut_offset] = row; |
| 197 } |
| 198 } |
| 199 } |
| 200 CFX_Palette::CFX_Palette() { |
| 201 m_pPalette = NULL; |
| 202 m_cLut = NULL; |
| 203 m_aLut = NULL; |
| 204 m_lut = 0; |
| 205 } |
| 206 CFX_Palette::~CFX_Palette() { |
| 207 if (m_pPalette) { |
| 208 FX_Free(m_pPalette); |
| 209 } |
| 210 if (m_cLut) { |
| 211 FX_Free(m_cLut); |
| 212 } |
| 213 if (m_aLut) { |
| 214 FX_Free(m_aLut); |
| 215 } |
| 216 m_lut = 0; |
| 217 } |
| 218 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) { |
| 219 if (pBitmap == NULL) { |
| 220 return FALSE; |
| 221 } |
| 222 if (m_pPalette != NULL) { |
| 223 FX_Free(m_pPalette); |
| 224 } |
| 225 m_pPalette = FX_Alloc(FX_DWORD, 256); |
| 226 if (!m_pPalette) { |
| 227 return FALSE; |
| 228 } |
| 229 int bpp = pBitmap->GetBPP() / 8; |
| 230 int width = pBitmap->GetWidth(); |
| 231 int height = pBitmap->GetHeight(); |
| 232 if (m_cLut) { |
| 233 FX_Free(m_cLut); |
| 234 m_cLut = NULL; |
| 235 } |
| 236 if (m_aLut) { |
| 237 FX_Free(m_aLut); |
| 238 m_aLut = NULL; |
| 239 } |
| 240 m_cLut = FX_Alloc(FX_DWORD, 4096); |
| 241 if (!m_cLut) { |
| 242 return FALSE; |
| 243 } |
| 244 m_aLut = FX_Alloc(FX_DWORD, 4096); |
| 245 if (!m_aLut) { |
| 246 return FALSE; |
| 247 } |
| 248 int row, col; |
| 249 m_lut = 0; |
| 250 for (row = 0; row < height; row++) { |
| 251 FX_BYTE* scan_line = (FX_BYTE*)pBitmap->GetScanline(row); |
| 252 for (col = 0; col < width; col++) { |
| 253 FX_BYTE* src_port = scan_line + col * bpp; |
| 254 FX_DWORD b = src_port[0] & 0xf0; |
| 255 FX_DWORD g = src_port[1] & 0xf0; |
| 256 FX_DWORD r = src_port[2] & 0xf0; |
| 257 FX_DWORD index = (r << 4) + g + (b >> 4); |
| 258 m_aLut[index]++; |
| 259 } |
| 260 } |
| 261 for (row = 0; row < 4096; row++) { |
| 262 if (m_aLut[row] != 0) { |
| 263 m_aLut[m_lut] = m_aLut[row]; |
| 264 m_cLut[m_lut] = row; |
| 265 m_lut++; |
| 266 } |
| 267 } |
| 268 _Qsort(m_aLut, m_cLut, 0, m_lut - 1); |
| 269 FX_DWORD* win_mac_pal = NULL; |
| 270 if (pal_type == FXDIB_PALETTE_WIN) { |
| 271 win_mac_pal = (FX_DWORD*)g_dwWinPalette; |
| 272 } else if (pal_type == FXDIB_PALETTE_MAC) { |
| 273 win_mac_pal = (FX_DWORD*)g_dwMacPalette; |
| 274 } |
| 275 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, pal_type, win_mac_pal, m_lut); |
| 276 return TRUE; |
| 277 } |
| 278 FX_BOOL _ConvertBuffer_1bppMask2Gray(FX_LPBYTE dest_buf, |
| 279 int dest_pitch, |
| 280 int width, |
| 281 int height, |
| 282 const CFX_DIBSource* pSrcBitmap, |
| 283 int src_left, |
| 284 int src_top) { |
| 285 FX_BYTE set_gray, reset_gray; |
| 286 set_gray = 0xff; |
| 287 reset_gray = 0x00; |
| 288 for (int row = 0; row < height; row++) { |
| 289 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 290 FXSYS_memset8(dest_scan, reset_gray, width); |
| 291 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); |
| 292 for (int col = src_left; col < src_left + width; col++) { |
| 293 if (src_scan[col / 8] & (1 << (7 - col % 8))) { |
| 294 *dest_scan = set_gray; |
| 295 } |
| 296 dest_scan++; |
| 297 } |
| 298 } |
| 299 return TRUE; |
| 300 } |
| 301 FX_BOOL _ConvertBuffer_8bppMask2Gray(FX_LPBYTE dest_buf, |
| 302 int dest_pitch, |
| 303 int width, |
| 304 int height, |
| 305 const CFX_DIBSource* pSrcBitmap, |
| 306 int src_left, |
| 307 int src_top) { |
| 308 for (int row = 0; row < height; row++) { |
| 309 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 310 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 311 FXSYS_memcpy32(dest_scan, src_scan, width); |
| 312 } |
| 313 return TRUE; |
| 314 } |
| 315 FX_BOOL _ConvertBuffer_1bppPlt2Gray(FX_LPBYTE dest_buf, |
| 316 int dest_pitch, |
| 317 int width, |
| 318 int height, |
| 319 const CFX_DIBSource* pSrcBitmap, |
| 320 int src_left, |
| 321 int src_top, |
| 322 void* pIccTransform) { |
| 323 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); |
| 324 FX_BYTE gray[2]; |
| 325 if (pIccTransform) { |
| 326 FX_DWORD plt[2]; |
| 327 if (pSrcBitmap->IsCmykImage()) { |
| 328 plt[0] = FXCMYK_TODIB(src_plt[0]); |
| 329 plt[1] = FXCMYK_TODIB(src_plt[1]); |
| 184 } else { | 330 } else { |
| 185 for (row = 0; row < 256; row++) { | 331 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; |
| 186 int lut_offset = lut_1 - row; | 332 bgr_ptr[0] = FXARGB_B(src_plt[0]); |
| 187 if (lut_offset < 0) { | 333 bgr_ptr[1] = FXARGB_G(src_plt[0]); |
| 188 lut_offset += 256; | 334 bgr_ptr[2] = FXARGB_R(src_plt[0]); |
| 189 } | 335 bgr_ptr[3] = FXARGB_B(src_plt[1]); |
| 190 FX_BYTE r, g, b; | 336 bgr_ptr[4] = FXARGB_G(src_plt[1]); |
| 191 _ColorDecode(cLut[lut_offset], r, g, b); | 337 bgr_ptr[5] = FXARGB_R(src_plt[1]); |
| 192 int error, min_error = 1000000; | 338 } |
| 193 int c_index = 0; | 339 ICodec_IccModule* pIccModule = |
| 194 for (col = 0; col < 256; col++) { | 340 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 195 FX_DWORD p_color = win_mac_pal[col]; | 341 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 2); |
| 196 int d_r = r - (FX_BYTE)(p_color >> 16); | 342 } else { |
| 197 int d_g = g - (FX_BYTE)(p_color >> 8); | 343 FX_BYTE reset_r, reset_g, reset_b, set_r, set_g, set_b; |
| 198 int d_b = b - (FX_BYTE)p_color; | 344 if (pSrcBitmap->IsCmykImage()) { |
| 199 error = d_r * d_r + d_g * d_g + d_b * d_b; | 345 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), |
| 200 if (error < min_error) { | 346 FXSYS_GetMValue(src_plt[0]), |
| 201 min_error = error; | 347 FXSYS_GetYValue(src_plt[0]), |
| 202 c_index = col; | 348 FXSYS_GetKValue(src_plt[0]), |
| 203 } | 349 reset_r, |
| 204 } | 350 reset_g, |
| 205 dest_pal[row] = win_mac_pal[c_index]; | 351 reset_b); |
| 206 aLut[lut_offset] = row; | 352 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), |
| 207 } | 353 FXSYS_GetMValue(src_plt[1]), |
| 208 } | 354 FXSYS_GetYValue(src_plt[1]), |
| 209 } | 355 FXSYS_GetKValue(src_plt[1]), |
| 210 CFX_Palette::CFX_Palette() | 356 set_r, |
| 211 { | 357 set_g, |
| 212 m_pPalette = NULL; | 358 set_b); |
| 213 m_cLut = NULL; | 359 } else { |
| 214 m_aLut = NULL; | 360 reset_r = FXARGB_R(src_plt[0]); |
| 215 m_lut = 0; | 361 reset_g = FXARGB_G(src_plt[0]); |
| 216 } | 362 reset_b = FXARGB_B(src_plt[0]); |
| 217 CFX_Palette::~CFX_Palette() | 363 set_r = FXARGB_R(src_plt[1]); |
| 218 { | 364 set_g = FXARGB_G(src_plt[1]); |
| 219 if (m_pPalette) { | 365 set_b = FXARGB_B(src_plt[1]); |
| 220 FX_Free(m_pPalette); | 366 } |
| 221 } | 367 gray[0] = FXRGB2GRAY(reset_r, reset_g, reset_b); |
| 222 if (m_cLut) { | 368 gray[1] = FXRGB2GRAY(set_r, set_g, set_b); |
| 223 FX_Free(m_cLut); | 369 } |
| 224 } | 370 for (int row = 0; row < height; row++) { |
| 225 if (m_aLut) { | 371 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 226 FX_Free(m_aLut); | 372 FXSYS_memset8(dest_scan, gray[0], width); |
| 227 } | 373 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); |
| 228 m_lut = 0; | 374 for (int col = src_left; col < src_left + width; col++) { |
| 229 } | 375 if (src_scan[col / 8] & (1 << (7 - col % 8))) { |
| 230 FX_BOOL CFX_Palette::BuildPalette(const CFX_DIBSource* pBitmap, int pal_type) | 376 *dest_scan = gray[1]; |
| 231 { | 377 } |
| 232 if (pBitmap == NULL) { | 378 dest_scan++; |
| 233 return FALSE; | 379 } |
| 234 } | 380 } |
| 235 if (m_pPalette != NULL) { | 381 return TRUE; |
| 236 FX_Free(m_pPalette); | 382 } |
| 237 } | 383 FX_BOOL _ConvertBuffer_8bppPlt2Gray(FX_LPBYTE dest_buf, |
| 238 m_pPalette = FX_Alloc(FX_DWORD, 256); | 384 int dest_pitch, |
| 239 if (!m_pPalette) { | 385 int width, |
| 240 return FALSE; | 386 int height, |
| 241 } | 387 const CFX_DIBSource* pSrcBitmap, |
| 242 int bpp = pBitmap->GetBPP() / 8; | 388 int src_left, |
| 243 int width = pBitmap->GetWidth(); | 389 int src_top, |
| 244 int height = pBitmap->GetHeight(); | 390 void* pIccTransform) { |
| 245 if (m_cLut) { | 391 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); |
| 246 FX_Free(m_cLut); | 392 FX_BYTE gray[256]; |
| 247 m_cLut = NULL; | 393 if (pIccTransform) { |
| 248 } | 394 FX_DWORD plt[256]; |
| 249 if (m_aLut) { | 395 if (pSrcBitmap->IsCmykImage()) { |
| 250 FX_Free(m_aLut); | 396 for (int i = 0; i < 256; i++) { |
| 251 m_aLut = NULL; | 397 plt[i] = FXCMYK_TODIB(src_plt[i]); |
| 252 } | 398 } |
| 253 m_cLut = FX_Alloc(FX_DWORD, 4096); | 399 } else { |
| 254 if (!m_cLut) { | 400 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; |
| 255 return FALSE; | 401 for (int i = 0; i < 256; i++) { |
| 256 } | 402 *bgr_ptr++ = FXARGB_B(src_plt[i]); |
| 257 m_aLut = FX_Alloc(FX_DWORD, 4096); | 403 *bgr_ptr++ = FXARGB_G(src_plt[i]); |
| 258 if (!m_aLut) { | 404 *bgr_ptr++ = FXARGB_R(src_plt[i]); |
| 259 return FALSE; | 405 } |
| 260 } | 406 } |
| 261 int row, col; | 407 ICodec_IccModule* pIccModule = |
| 262 m_lut = 0; | 408 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 263 for (row = 0; row < height; row++) { | 409 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 256); |
| 264 FX_BYTE* scan_line = (FX_BYTE*)pBitmap->GetScanline(row); | 410 } else { |
| 265 for (col = 0; col < width; col++) { | 411 if (pSrcBitmap->IsCmykImage()) { |
| 266 FX_BYTE* src_port = scan_line + col * bpp; | 412 FX_BYTE r, g, b; |
| 267 FX_DWORD b = src_port[0] & 0xf0; | 413 for (int i = 0; i < 256; i++) { |
| 268 FX_DWORD g = src_port[1] & 0xf0; | 414 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), |
| 269 FX_DWORD r = src_port[2] & 0xf0; | 415 FXSYS_GetMValue(src_plt[i]), |
| 270 FX_DWORD index = (r << 4) + g + (b >> 4); | 416 FXSYS_GetYValue(src_plt[i]), |
| 271 m_aLut[index]++; | 417 FXSYS_GetKValue(src_plt[i]), |
| 272 } | 418 r, |
| 273 } | 419 g, |
| 274 for (row = 0; row < 4096; row++) { | 420 b); |
| 275 if (m_aLut[row] != 0) { | 421 gray[i] = FXRGB2GRAY(r, g, b); |
| 276 m_aLut[m_lut] = m_aLut[row]; | 422 } |
| 277 m_cLut[m_lut] = row; | 423 } else |
| 278 m_lut++; | 424 for (int i = 0; i < 256; i++) { |
| 279 } | 425 gray[i] = FXRGB2GRAY( |
| 280 } | 426 FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]), FXARGB_B(src_plt[i])); |
| 281 _Qsort(m_aLut, m_cLut, 0, m_lut - 1); | 427 } |
| 282 FX_DWORD* win_mac_pal = NULL; | 428 } |
| 283 if (pal_type == FXDIB_PALETTE_WIN) { | 429 for (int row = 0; row < height; row++) { |
| 284 win_mac_pal = (FX_DWORD*)g_dwWinPalette; | 430 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 285 } else if (pal_type == FXDIB_PALETTE_MAC) { | 431 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 286 win_mac_pal = (FX_DWORD*)g_dwMacPalette; | 432 for (int col = 0; col < width; col++) { |
| 287 } | 433 *dest_scan++ = gray[*src_scan++]; |
| 288 _Obtain_Pal(m_aLut, m_cLut, m_pPalette, pal_type, win_mac_pal, m_lut); | 434 } |
| 289 return TRUE; | 435 } |
| 290 } | 436 return TRUE; |
| 291 FX_BOOL _ConvertBuffer_1bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int wid
th, int height, | 437 } |
| 292 const CFX_DIBSource* pSrcBitmap, int src_le
ft, int src_top) | 438 FX_BOOL _ConvertBuffer_RgbOrCmyk2Gray(FX_LPBYTE dest_buf, |
| 293 { | 439 int dest_pitch, |
| 294 FX_BYTE set_gray, reset_gray; | 440 int width, |
| 295 set_gray = 0xff; | 441 int height, |
| 296 reset_gray = 0x00; | 442 const CFX_DIBSource* pSrcBitmap, |
| 297 for (int row = 0; row < height; row ++) { | 443 int src_left, |
| 444 int src_top, |
| 445 void* pIccTransform) { |
| 446 int Bpp = pSrcBitmap->GetBPP() / 8; |
| 447 if (pIccTransform) { |
| 448 ICodec_IccModule* pIccModule = |
| 449 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 450 if (Bpp == 3 || pSrcBitmap->IsCmykImage()) { |
| 451 for (int row = 0; row < height; row++) { |
| 298 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 452 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 299 FXSYS_memset8(dest_scan, reset_gray, width); | 453 FX_LPCBYTE src_scan = |
| 300 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); | 454 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; |
| 301 for (int col = src_left; col < src_left + width; col ++) { | 455 pIccModule->TranslateScanline( |
| 302 if (src_scan[col / 8] & (1 << (7 - col % 8))) { | 456 pIccTransform, dest_scan, src_scan, width); |
| 303 *dest_scan = set_gray; | 457 } |
| 304 } | 458 } else { |
| 305 dest_scan ++; | 459 for (int row = 0; row < height; row++) { |
| 306 } | |
| 307 } | |
| 308 return TRUE; | |
| 309 } | |
| 310 FX_BOOL _ConvertBuffer_8bppMask2Gray(FX_LPBYTE dest_buf, int dest_pitch, int wid
th, int height, | |
| 311 const CFX_DIBSource* pSrcBitmap, int src_le
ft, int src_top) | |
| 312 { | |
| 313 for (int row = 0; row < height; row ++) { | |
| 314 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 460 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 315 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; | 461 FX_LPCBYTE src_scan = |
| 316 FXSYS_memcpy32(dest_scan, src_scan, width); | 462 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 317 } | 463 for (int col = 0; col < width; col++) { |
| 318 return TRUE; | 464 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1); |
| 319 } | 465 dest_scan++; |
| 320 FX_BOOL _ConvertBuffer_1bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int widt
h, int height, | 466 src_scan += 4; |
| 321 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top, void* pIccTransform) | 467 } |
| 322 { | 468 } |
| 323 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 469 } |
| 324 FX_BYTE gray[2]; | 470 } else { |
| 325 if (pIccTransform) { | 471 if (pSrcBitmap->IsCmykImage()) { |
| 326 FX_DWORD plt[2]; | 472 for (int row = 0; row < height; row++) { |
| 327 if (pSrcBitmap->IsCmykImage()) { | 473 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 328 plt[0] = FXCMYK_TODIB(src_plt[0]); | 474 FX_LPCBYTE src_scan = |
| 329 plt[1] = FXCMYK_TODIB(src_plt[1]); | 475 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 330 } else { | 476 for (int col = 0; col < width; col++) { |
| 331 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; | 477 FX_BYTE r, g, b; |
| 332 bgr_ptr[0] = FXARGB_B(src_plt[0]); | 478 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((FX_DWORD)src_scan[0]), |
| 333 bgr_ptr[1] = FXARGB_G(src_plt[0]); | 479 FXSYS_GetMValue((FX_DWORD)src_scan[1]), |
| 334 bgr_ptr[2] = FXARGB_R(src_plt[0]); | 480 FXSYS_GetYValue((FX_DWORD)src_scan[2]), |
| 335 bgr_ptr[3] = FXARGB_B(src_plt[1]); | 481 FXSYS_GetKValue((FX_DWORD)src_scan[3]), |
| 336 bgr_ptr[4] = FXARGB_G(src_plt[1]); | 482 r, |
| 337 bgr_ptr[5] = FXARGB_R(src_plt[1]); | 483 g, |
| 338 } | 484 b); |
| 339 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | 485 *dest_scan++ = FXRGB2GRAY(r, g, b); |
| 340 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 2); | 486 src_scan += 4; |
| 487 } |
| 488 } |
| 341 } else { | 489 } else { |
| 342 FX_BYTE reset_r, reset_g, reset_b, | 490 for (int row = 0; row < height; row++) { |
| 343 set_r, set_g, set_b; | |
| 344 if (pSrcBitmap->IsCmykImage()) { | |
| 345 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_
plt[0]), FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]), | |
| 346 reset_r, reset_g, reset_b); | |
| 347 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_
plt[1]), FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]), | |
| 348 set_r, set_g, set_b); | |
| 349 } else { | |
| 350 reset_r = FXARGB_R(src_plt[0]); | |
| 351 reset_g = FXARGB_G(src_plt[0]); | |
| 352 reset_b = FXARGB_B(src_plt[0]); | |
| 353 set_r = FXARGB_R(src_plt[1]); | |
| 354 set_g = FXARGB_G(src_plt[1]); | |
| 355 set_b = FXARGB_B(src_plt[1]); | |
| 356 } | |
| 357 gray[0] = FXRGB2GRAY(reset_r, reset_g, reset_b); | |
| 358 gray[1] = FXRGB2GRAY(set_r, set_g, set_b); | |
| 359 } | |
| 360 for (int row = 0; row < height; row ++) { | |
| 361 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 491 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 362 FXSYS_memset8(dest_scan, gray[0], width); | 492 FX_LPCBYTE src_scan = |
| 363 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); | 493 pSrcBitmap->GetScanline(src_top + row) + src_left * Bpp; |
| 364 for (int col = src_left; col < src_left + width; col ++) { | 494 for (int col = 0; col < width; col++) { |
| 365 if (src_scan[col / 8] & (1 << (7 - col % 8))) { | 495 *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan[0]); |
| 366 *dest_scan = gray[1]; | 496 src_scan += Bpp; |
| 367 } | 497 } |
| 368 dest_scan ++; | 498 } |
| 369 } | 499 } |
| 370 } | 500 } |
| 371 return TRUE; | 501 return TRUE; |
| 372 } | 502 } |
| 373 FX_BOOL _ConvertBuffer_8bppPlt2Gray(FX_LPBYTE dest_buf, int dest_pitch, int widt
h, int height, | 503 inline void _ConvertBuffer_IndexCopy(FX_LPBYTE dest_buf, |
| 374 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top, void* pIccTransform) | 504 int dest_pitch, |
| 375 { | 505 int width, |
| 376 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 506 int height, |
| 377 FX_BYTE gray[256]; | 507 const CFX_DIBSource* pSrcBitmap, |
| 378 if (pIccTransform) { | 508 int src_left, |
| 379 FX_DWORD plt[256]; | 509 int src_top) { |
| 380 if (pSrcBitmap->IsCmykImage()) { | 510 if (pSrcBitmap->GetBPP() == 1) { |
| 381 for (int i = 0; i < 256; i ++) { | 511 for (int row = 0; row < height; row++) { |
| 382 plt[i] = FXCMYK_TODIB(src_plt[i]); | 512 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 383 } | 513 FXSYS_memset32(dest_scan, 0, width); |
| 384 } else { | 514 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); |
| 385 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; | 515 for (int col = src_left; col < src_left + width; col++) { |
| 386 for (int i = 0; i < 256; i ++) { | 516 if (src_scan[col / 8] & (1 << (7 - col % 8))) { |
| 387 *bgr_ptr++ = FXARGB_B(src_plt[i]); | 517 *dest_scan = 1; |
| 388 *bgr_ptr++ = FXARGB_G(src_plt[i]); | 518 } |
| 389 *bgr_ptr++ = FXARGB_R(src_plt[i]); | 519 dest_scan++; |
| 390 } | 520 } |
| 391 } | 521 } |
| 392 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | 522 } else { |
| 393 pIccModule->TranslateScanline(pIccTransform, gray, (FX_LPCBYTE)plt, 256)
; | 523 for (int row = 0; row < height; row++) { |
| 394 } else { | 524 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 395 if (pSrcBitmap->IsCmykImage()) { | 525 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 396 FX_BYTE r, g, b; | 526 FXSYS_memcpy32(dest_scan, src_scan, width); |
| 397 for (int i = 0; i < 256; i ++) { | 527 } |
| 398 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(
src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), | 528 } |
| 399 r, g, b); | 529 } |
| 400 gray[i] = FXRGB2GRAY(r, g, b); | 530 FX_BOOL _ConvertBuffer_Plt2PltRgb8(FX_LPBYTE dest_buf, |
| 401 } | 531 int dest_pitch, |
| 402 } else | 532 int width, |
| 403 for (int i = 0; i < 256; i ++) { | 533 int height, |
| 404 gray[i] = FXRGB2GRAY(FXARGB_R(src_plt[i]), FXARGB_G(src_plt[i]),
FXARGB_B(src_plt[i])); | 534 const CFX_DIBSource* pSrcBitmap, |
| 405 } | 535 int src_left, |
| 406 } | 536 int src_top, |
| 407 for (int row = 0; row < height; row ++) { | 537 FX_DWORD* dst_plt, |
| 408 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 538 void* pIccTransform) { |
| 409 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; | 539 _ConvertBuffer_IndexCopy( |
| 410 for (int col = 0; col < width; col ++) { | 540 dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top); |
| 411 *dest_scan++ = gray[*src_scan++]; | 541 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); |
| 412 } | 542 int plt_size = pSrcBitmap->GetPaletteSize(); |
| 413 } | 543 if (pIccTransform) { |
| 414 return TRUE; | 544 FX_DWORD plt[256]; |
| 415 } | |
| 416 FX_BOOL _ConvertBuffer_RgbOrCmyk2Gray(FX_LPBYTE dest_buf, int dest_pitch, int wi
dth, int height, | |
| 417 const CFX_DIBSource* pSrcBitmap, int src_l
eft, int src_top, void* pIccTransform) | |
| 418 { | |
| 419 int Bpp = pSrcBitmap->GetBPP() / 8; | |
| 420 if (pIccTransform) { | |
| 421 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | |
| 422 if (Bpp == 3 || pSrcBitmap->IsCmykImage()) { | |
| 423 for (int row = 0; row < height; row ++) { | |
| 424 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 425 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s
rc_left * Bpp; | |
| 426 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan
, width); | |
| 427 } | |
| 428 } else { | |
| 429 for (int row = 0; row < height; row ++) { | |
| 430 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 431 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s
rc_left * 4; | |
| 432 for (int col = 0; col < width; col ++) { | |
| 433 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_
scan, 1); | |
| 434 dest_scan++; | |
| 435 src_scan += 4; | |
| 436 } | |
| 437 } | |
| 438 } | |
| 439 } else { | |
| 440 if (pSrcBitmap->IsCmykImage()) { | |
| 441 for (int row = 0; row < height; row ++) { | |
| 442 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 443 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s
rc_left * 4; | |
| 444 for (int col = 0; col < width; col ++) { | |
| 445 FX_BYTE r, g, b; | |
| 446 AdobeCMYK_to_sRGB1(FXSYS_GetCValue((FX_DWORD)src_scan[0]), F
XSYS_GetMValue((FX_DWORD)src_scan[1]), FXSYS_GetYValue((FX_DWORD)src_scan[2]), F
XSYS_GetKValue((FX_DWORD)src_scan[3]), | |
| 447 r, g, b); | |
| 448 *dest_scan++ = FXRGB2GRAY(r, g, b); | |
| 449 src_scan += 4; | |
| 450 } | |
| 451 } | |
| 452 } else { | |
| 453 for (int row = 0; row < height; row ++) { | |
| 454 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 455 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + s
rc_left * Bpp; | |
| 456 for (int col = 0; col < width; col ++) { | |
| 457 *dest_scan++ = FXRGB2GRAY(src_scan[2], src_scan[1], src_scan
[0]); | |
| 458 src_scan += Bpp; | |
| 459 } | |
| 460 } | |
| 461 } | |
| 462 } | |
| 463 return TRUE; | |
| 464 } | |
| 465 inline void _ConvertBuffer_IndexCopy(FX_LPBYTE dest_buf, int dest_pitch, int wid
th, int height, | |
| 466 const CFX_DIBSource* pSrcBitmap, int src_le
ft, int src_top) | |
| 467 { | |
| 468 if (pSrcBitmap->GetBPP() == 1) { | |
| 469 for (int row = 0; row < height; row ++) { | |
| 470 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 471 FXSYS_memset32(dest_scan, 0, width); | |
| 472 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); | |
| 473 for (int col = src_left; col < src_left + width; col ++) { | |
| 474 if (src_scan[col / 8] & (1 << (7 - col % 8))) { | |
| 475 *dest_scan = 1; | |
| 476 } | |
| 477 dest_scan ++; | |
| 478 } | |
| 479 } | |
| 480 } else { | |
| 481 for (int row = 0; row < height; row ++) { | |
| 482 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 483 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l
eft; | |
| 484 FXSYS_memcpy32(dest_scan, src_scan, width); | |
| 485 } | |
| 486 } | |
| 487 } | |
| 488 FX_BOOL _ConvertBuffer_Plt2PltRgb8(FX_LPBYTE dest_buf, int dest_pitch, int width
, int height, | |
| 489 const CFX_DIBSource* pSrcBitmap, int src_left
, int src_top, FX_DWORD* dst_plt, void* pIccTransform) | |
| 490 { | |
| 491 _ConvertBuffer_IndexCopy(dest_buf, dest_pitch, width, height, pSrcBitmap, sr
c_left, src_top); | |
| 492 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | |
| 493 int plt_size = pSrcBitmap->GetPaletteSize(); | |
| 494 if (pIccTransform) { | |
| 495 FX_DWORD plt[256]; | |
| 496 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; | |
| 497 if (pSrcBitmap->IsCmykImage()) { | |
| 498 for (int i = 0; i < plt_size; i ++) { | |
| 499 plt[i] = FXCMYK_TODIB(src_plt[i]); | |
| 500 } | |
| 501 } else { | |
| 502 for (int i = 0; i < plt_size; i ++) { | |
| 503 *bgr_ptr++ = FXARGB_B(src_plt[i]); | |
| 504 *bgr_ptr++ = FXARGB_G(src_plt[i]); | |
| 505 *bgr_ptr++ = FXARGB_R(src_plt[i]); | |
| 506 } | |
| 507 bgr_ptr = (FX_LPBYTE)plt; | |
| 508 } | |
| 509 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | |
| 510 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE
)plt, plt_size); | |
| 511 for (int i = 0; i < plt_size; i ++) { | |
| 512 dst_plt[i] = FXARGB_MAKE(0xff, bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]); | |
| 513 bgr_ptr += 3; | |
| 514 } | |
| 515 } else { | |
| 516 if (pSrcBitmap->IsCmykImage()) { | |
| 517 for (int i = 0; i < plt_size; i ++) { | |
| 518 FX_BYTE r, g, b; | |
| 519 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(
src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), | |
| 520 r, g, b); | |
| 521 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b); | |
| 522 } | |
| 523 } else { | |
| 524 FXSYS_memcpy32(dst_plt, src_plt, plt_size * 4); | |
| 525 } | |
| 526 } | |
| 527 return TRUE; | |
| 528 } | |
| 529 inline FX_BOOL _ConvertBuffer_Rgb2PltRgb8_NoTransform(FX_LPBYTE dest_buf, int de
st_pitch, int width, int height, | |
| 530 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top, FX_DWORD* ds
t_plt) | |
| 531 { | |
| 532 int bpp = pSrcBitmap->GetBPP() / 8; | |
| 533 int row, col; | |
| 534 CFX_Palette palette; | |
| 535 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC); | |
| 536 FX_DWORD* cLut = palette.GetColorLut(); | |
| 537 FX_DWORD* aLut = palette.GetAmountLut(); | |
| 538 if (cLut == NULL || aLut == NULL) { | |
| 539 return FALSE; | |
| 540 } | |
| 541 int lut = palette.Getlut(); | |
| 542 FX_DWORD* pPalette = palette.GetPalette(); | |
| 543 if (lut > 256) { | |
| 544 int err, min_err; | |
| 545 int lut_256 = lut - 256; | |
| 546 for (row = 0; row < lut_256; row++) { | |
| 547 min_err = 1000000; | |
| 548 FX_BYTE r, g, b; | |
| 549 _ColorDecode(cLut[row], r, g, b); | |
| 550 int clrindex = 0; | |
| 551 for (int col = 0; col < 256; col++) { | |
| 552 FX_DWORD p_color = *(pPalette + col); | |
| 553 int d_r = r - (FX_BYTE)(p_color >> 16); | |
| 554 int d_g = g - (FX_BYTE)(p_color >> 8); | |
| 555 int d_b = b - (FX_BYTE)(p_color); | |
| 556 err = d_r * d_r + d_g * d_g + d_b * d_b; | |
| 557 if (err < min_err) { | |
| 558 min_err = err; | |
| 559 clrindex = col; | |
| 560 } | |
| 561 } | |
| 562 aLut[row] = clrindex; | |
| 563 } | |
| 564 } | |
| 565 FX_INT32 lut_1 = lut - 1; | |
| 566 for (row = 0; row < height; row ++) { | |
| 567 FX_BYTE* src_scan = (FX_BYTE*)pSrcBitmap->GetScanline(src_top + row) + s
rc_left; | |
| 568 FX_BYTE* dest_scan = dest_buf + row * dest_pitch; | |
| 569 for (col = 0; col < width; col++) { | |
| 570 FX_BYTE* src_port = src_scan + col * bpp; | |
| 571 int r = src_port[2] & 0xf0; | |
| 572 int g = src_port[1] & 0xf0; | |
| 573 int b = src_port[0] & 0xf0; | |
| 574 FX_DWORD clrindex = (r << 4) + g + (b >> 4); | |
| 575 for (int i = lut_1; i >= 0; i--) | |
| 576 if (clrindex == cLut[i]) { | |
| 577 *(dest_scan + col) = (FX_BYTE)(aLut[i]); | |
| 578 break; | |
| 579 } | |
| 580 } | |
| 581 } | |
| 582 FXSYS_memcpy32(dst_plt, pPalette, sizeof(FX_DWORD) * 256); | |
| 583 return TRUE; | |
| 584 } | |
| 585 FX_BOOL _ConvertBuffer_Rgb2PltRgb8(FX_LPBYTE dest_buf, int dest_pitch, int width
, int height, | |
| 586 const CFX_DIBSource* pSrcBitmap, int src_left
, int src_top, FX_DWORD* dst_plt, void* pIccTransform) | |
| 587 { | |
| 588 ICodec_IccModule* pIccModule = NULL; | |
| 589 if (pIccTransform) { | |
| 590 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); | |
| 591 } | |
| 592 FX_BOOL ret = _ConvertBuffer_Rgb2PltRgb8_NoTransform(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, dst_plt); | |
| 593 if (ret && pIccTransform) { | |
| 594 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | |
| 595 for (int i = 0; i < 256; i++) { | |
| 596 FX_ARGB* plt = dst_plt + i; | |
| 597 FX_ARGB plt_entry = FXARGB_TODIB(*plt); | |
| 598 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)&plt_entry,
(FX_LPCBYTE)&plt_entry, 1); | |
| 599 *plt = FXARGB_TODIB(plt_entry); | |
| 600 } | |
| 601 } | |
| 602 return ret; | |
| 603 } | |
| 604 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, | |
| 605 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top) | |
| 606 { | |
| 607 int comps = (dst_format & 0xff) / 8; | |
| 608 FX_BYTE set_gray, reset_gray; | |
| 609 set_gray = 0xff; | |
| 610 reset_gray = 0x00; | |
| 611 for (int row = 0; row < height; row ++) { | |
| 612 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 613 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); | |
| 614 for (int col = src_left; col < src_left + width; col ++) { | |
| 615 if (src_scan[col / 8] & (1 << (7 - col % 8))) { | |
| 616 dest_scan[0] = set_gray; | |
| 617 dest_scan[1] = set_gray; | |
| 618 dest_scan[2] = set_gray; | |
| 619 } else { | |
| 620 dest_scan[0] = reset_gray; | |
| 621 dest_scan[1] = reset_gray; | |
| 622 dest_scan[2] = reset_gray; | |
| 623 } | |
| 624 dest_scan += comps; | |
| 625 } | |
| 626 } | |
| 627 return TRUE; | |
| 628 } | |
| 629 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, | |
| 630 const CFX_DIBSource* pSrcBitmap, int src_lef
t, int src_top) | |
| 631 { | |
| 632 int comps = (dst_format & 0xff) / 8; | |
| 633 for (int row = 0; row < height; row ++) { | |
| 634 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 635 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; | |
| 636 FX_BYTE src_pixel; | |
| 637 for (int col = 0; col < width; col ++) { | |
| 638 src_pixel = *src_scan++; | |
| 639 *dest_scan++ = src_pixel; | |
| 640 *dest_scan++ = src_pixel; | |
| 641 *dest_scan = src_pixel; | |
| 642 dest_scan += comps - 2; | |
| 643 } | |
| 644 } | |
| 645 return TRUE; | |
| 646 } | |
| 647 FX_BOOL _ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, | |
| 648 const CFX_DIBSource* pSrcBitmap, int src_left
, int src_top, void* pIccTransform) | |
| 649 { | |
| 650 int comps = (dst_format & 0xff) / 8; | |
| 651 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | |
| 652 FX_DWORD plt[2]; | |
| 653 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; | 545 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; |
| 654 if (pSrcBitmap->IsCmykImage()) { | 546 if (pSrcBitmap->IsCmykImage()) { |
| 655 plt[0] = FXCMYK_TODIB(src_plt[0]); | 547 for (int i = 0; i < plt_size; i++) { |
| 656 plt[1] = FXCMYK_TODIB(src_plt[1]); | 548 plt[i] = FXCMYK_TODIB(src_plt[i]); |
| 549 } |
| 657 } else { | 550 } else { |
| 658 bgr_ptr[0] = FXARGB_B(src_plt[0]); | 551 for (int i = 0; i < plt_size; i++) { |
| 659 bgr_ptr[1] = FXARGB_G(src_plt[0]); | 552 *bgr_ptr++ = FXARGB_B(src_plt[i]); |
| 660 bgr_ptr[2] = FXARGB_R(src_plt[0]); | 553 *bgr_ptr++ = FXARGB_G(src_plt[i]); |
| 661 bgr_ptr[3] = FXARGB_B(src_plt[1]); | 554 *bgr_ptr++ = FXARGB_R(src_plt[i]); |
| 662 bgr_ptr[4] = FXARGB_G(src_plt[1]); | 555 } |
| 663 bgr_ptr[5] = FXARGB_R(src_plt[1]); | 556 bgr_ptr = (FX_LPBYTE)plt; |
| 664 } | 557 } |
| 665 if (pIccTransform) { | 558 ICodec_IccModule* pIccModule = |
| 666 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | 559 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 667 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE
)plt, 2); | 560 pIccModule->TranslateScanline( |
| 561 pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE)plt, plt_size); |
| 562 for (int i = 0; i < plt_size; i++) { |
| 563 dst_plt[i] = FXARGB_MAKE(0xff, bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]); |
| 564 bgr_ptr += 3; |
| 565 } |
| 566 } else { |
| 567 if (pSrcBitmap->IsCmykImage()) { |
| 568 for (int i = 0; i < plt_size; i++) { |
| 569 FX_BYTE r, g, b; |
| 570 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), |
| 571 FXSYS_GetMValue(src_plt[i]), |
| 572 FXSYS_GetYValue(src_plt[i]), |
| 573 FXSYS_GetKValue(src_plt[i]), |
| 574 r, |
| 575 g, |
| 576 b); |
| 577 dst_plt[i] = FXARGB_MAKE(0xff, r, g, b); |
| 578 } |
| 668 } else { | 579 } else { |
| 669 if (pSrcBitmap->IsCmykImage()) { | 580 FXSYS_memcpy32(dst_plt, src_plt, plt_size * 4); |
| 670 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), FXSYS_GetMValue(src_
plt[0]), FXSYS_GetYValue(src_plt[0]), FXSYS_GetKValue(src_plt[0]), | 581 } |
| 671 bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]); | 582 } |
| 672 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), FXSYS_GetMValue(src_
plt[1]), FXSYS_GetYValue(src_plt[1]), FXSYS_GetKValue(src_plt[1]), | 583 return TRUE; |
| 673 bgr_ptr[5], bgr_ptr[4], bgr_ptr[3]); | 584 } |
| 674 } | 585 inline FX_BOOL _ConvertBuffer_Rgb2PltRgb8_NoTransform( |
| 675 } | 586 FX_LPBYTE dest_buf, |
| 676 for (int row = 0; row < height; row ++) { | 587 int dest_pitch, |
| 677 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 588 int width, |
| 678 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); | 589 int height, |
| 679 for (int col = src_left; col < src_left + width; col ++) { | 590 const CFX_DIBSource* pSrcBitmap, |
| 680 if (src_scan[col / 8] & (1 << (7 - col % 8))) { | 591 int src_left, |
| 681 *dest_scan++ = bgr_ptr[3]; | 592 int src_top, |
| 682 *dest_scan++ = bgr_ptr[4]; | 593 FX_DWORD* dst_plt) { |
| 683 *dest_scan = bgr_ptr[5]; | 594 int bpp = pSrcBitmap->GetBPP() / 8; |
| 684 } else { | 595 int row, col; |
| 685 *dest_scan++ = bgr_ptr[0]; | 596 CFX_Palette palette; |
| 686 *dest_scan++ = bgr_ptr[1]; | 597 palette.BuildPalette(pSrcBitmap, FXDIB_PALETTE_LOC); |
| 687 *dest_scan = bgr_ptr[2]; | 598 FX_DWORD* cLut = palette.GetColorLut(); |
| 688 } | 599 FX_DWORD* aLut = palette.GetAmountLut(); |
| 689 dest_scan += comps - 2; | 600 if (cLut == NULL || aLut == NULL) { |
| 690 } | 601 return FALSE; |
| 691 } | 602 } |
| 603 int lut = palette.Getlut(); |
| 604 FX_DWORD* pPalette = palette.GetPalette(); |
| 605 if (lut > 256) { |
| 606 int err, min_err; |
| 607 int lut_256 = lut - 256; |
| 608 for (row = 0; row < lut_256; row++) { |
| 609 min_err = 1000000; |
| 610 FX_BYTE r, g, b; |
| 611 _ColorDecode(cLut[row], r, g, b); |
| 612 int clrindex = 0; |
| 613 for (int col = 0; col < 256; col++) { |
| 614 FX_DWORD p_color = *(pPalette + col); |
| 615 int d_r = r - (FX_BYTE)(p_color >> 16); |
| 616 int d_g = g - (FX_BYTE)(p_color >> 8); |
| 617 int d_b = b - (FX_BYTE)(p_color); |
| 618 err = d_r * d_r + d_g * d_g + d_b * d_b; |
| 619 if (err < min_err) { |
| 620 min_err = err; |
| 621 clrindex = col; |
| 622 } |
| 623 } |
| 624 aLut[row] = clrindex; |
| 625 } |
| 626 } |
| 627 FX_INT32 lut_1 = lut - 1; |
| 628 for (row = 0; row < height; row++) { |
| 629 FX_BYTE* src_scan = |
| 630 (FX_BYTE*)pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 631 FX_BYTE* dest_scan = dest_buf + row * dest_pitch; |
| 632 for (col = 0; col < width; col++) { |
| 633 FX_BYTE* src_port = src_scan + col * bpp; |
| 634 int r = src_port[2] & 0xf0; |
| 635 int g = src_port[1] & 0xf0; |
| 636 int b = src_port[0] & 0xf0; |
| 637 FX_DWORD clrindex = (r << 4) + g + (b >> 4); |
| 638 for (int i = lut_1; i >= 0; i--) |
| 639 if (clrindex == cLut[i]) { |
| 640 *(dest_scan + col) = (FX_BYTE)(aLut[i]); |
| 641 break; |
| 642 } |
| 643 } |
| 644 } |
| 645 FXSYS_memcpy32(dst_plt, pPalette, sizeof(FX_DWORD) * 256); |
| 646 return TRUE; |
| 647 } |
| 648 FX_BOOL _ConvertBuffer_Rgb2PltRgb8(FX_LPBYTE dest_buf, |
| 649 int dest_pitch, |
| 650 int width, |
| 651 int height, |
| 652 const CFX_DIBSource* pSrcBitmap, |
| 653 int src_left, |
| 654 int src_top, |
| 655 FX_DWORD* dst_plt, |
| 656 void* pIccTransform) { |
| 657 ICodec_IccModule* pIccModule = NULL; |
| 658 if (pIccTransform) { |
| 659 pIccModule = CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 660 } |
| 661 FX_BOOL ret = _ConvertBuffer_Rgb2PltRgb8_NoTransform(dest_buf, |
| 662 dest_pitch, |
| 663 width, |
| 664 height, |
| 665 pSrcBitmap, |
| 666 src_left, |
| 667 src_top, |
| 668 dst_plt); |
| 669 if (ret && pIccTransform) { |
| 670 ICodec_IccModule* pIccModule = |
| 671 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 672 for (int i = 0; i < 256; i++) { |
| 673 FX_ARGB* plt = dst_plt + i; |
| 674 FX_ARGB plt_entry = FXARGB_TODIB(*plt); |
| 675 pIccModule->TranslateScanline( |
| 676 pIccTransform, (FX_LPBYTE)&plt_entry, (FX_LPCBYTE)&plt_entry, 1); |
| 677 *plt = FXARGB_TODIB(plt_entry); |
| 678 } |
| 679 } |
| 680 return ret; |
| 681 } |
| 682 FX_BOOL _ConvertBuffer_1bppMask2Rgb(FXDIB_Format dst_format, |
| 683 FX_LPBYTE dest_buf, |
| 684 int dest_pitch, |
| 685 int width, |
| 686 int height, |
| 687 const CFX_DIBSource* pSrcBitmap, |
| 688 int src_left, |
| 689 int src_top) { |
| 690 int comps = (dst_format & 0xff) / 8; |
| 691 FX_BYTE set_gray, reset_gray; |
| 692 set_gray = 0xff; |
| 693 reset_gray = 0x00; |
| 694 for (int row = 0; row < height; row++) { |
| 695 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 696 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); |
| 697 for (int col = src_left; col < src_left + width; col++) { |
| 698 if (src_scan[col / 8] & (1 << (7 - col % 8))) { |
| 699 dest_scan[0] = set_gray; |
| 700 dest_scan[1] = set_gray; |
| 701 dest_scan[2] = set_gray; |
| 702 } else { |
| 703 dest_scan[0] = reset_gray; |
| 704 dest_scan[1] = reset_gray; |
| 705 dest_scan[2] = reset_gray; |
| 706 } |
| 707 dest_scan += comps; |
| 708 } |
| 709 } |
| 710 return TRUE; |
| 711 } |
| 712 FX_BOOL _ConvertBuffer_8bppMask2Rgb(FXDIB_Format dst_format, |
| 713 FX_LPBYTE dest_buf, |
| 714 int dest_pitch, |
| 715 int width, |
| 716 int height, |
| 717 const CFX_DIBSource* pSrcBitmap, |
| 718 int src_left, |
| 719 int src_top) { |
| 720 int comps = (dst_format & 0xff) / 8; |
| 721 for (int row = 0; row < height; row++) { |
| 722 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 723 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 724 FX_BYTE src_pixel; |
| 725 for (int col = 0; col < width; col++) { |
| 726 src_pixel = *src_scan++; |
| 727 *dest_scan++ = src_pixel; |
| 728 *dest_scan++ = src_pixel; |
| 729 *dest_scan = src_pixel; |
| 730 dest_scan += comps - 2; |
| 731 } |
| 732 } |
| 733 return TRUE; |
| 734 } |
| 735 FX_BOOL _ConvertBuffer_1bppPlt2Rgb(FXDIB_Format dst_format, |
| 736 FX_LPBYTE dest_buf, |
| 737 int dest_pitch, |
| 738 int width, |
| 739 int height, |
| 740 const CFX_DIBSource* pSrcBitmap, |
| 741 int src_left, |
| 742 int src_top, |
| 743 void* pIccTransform) { |
| 744 int comps = (dst_format & 0xff) / 8; |
| 745 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); |
| 746 FX_DWORD plt[2]; |
| 747 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; |
| 748 if (pSrcBitmap->IsCmykImage()) { |
| 749 plt[0] = FXCMYK_TODIB(src_plt[0]); |
| 750 plt[1] = FXCMYK_TODIB(src_plt[1]); |
| 751 } else { |
| 752 bgr_ptr[0] = FXARGB_B(src_plt[0]); |
| 753 bgr_ptr[1] = FXARGB_G(src_plt[0]); |
| 754 bgr_ptr[2] = FXARGB_R(src_plt[0]); |
| 755 bgr_ptr[3] = FXARGB_B(src_plt[1]); |
| 756 bgr_ptr[4] = FXARGB_G(src_plt[1]); |
| 757 bgr_ptr[5] = FXARGB_R(src_plt[1]); |
| 758 } |
| 759 if (pIccTransform) { |
| 760 ICodec_IccModule* pIccModule = |
| 761 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 762 pIccModule->TranslateScanline( |
| 763 pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE)plt, 2); |
| 764 } else { |
| 765 if (pSrcBitmap->IsCmykImage()) { |
| 766 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[0]), |
| 767 FXSYS_GetMValue(src_plt[0]), |
| 768 FXSYS_GetYValue(src_plt[0]), |
| 769 FXSYS_GetKValue(src_plt[0]), |
| 770 bgr_ptr[2], |
| 771 bgr_ptr[1], |
| 772 bgr_ptr[0]); |
| 773 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[1]), |
| 774 FXSYS_GetMValue(src_plt[1]), |
| 775 FXSYS_GetYValue(src_plt[1]), |
| 776 FXSYS_GetKValue(src_plt[1]), |
| 777 bgr_ptr[5], |
| 778 bgr_ptr[4], |
| 779 bgr_ptr[3]); |
| 780 } |
| 781 } |
| 782 for (int row = 0; row < height; row++) { |
| 783 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 784 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row); |
| 785 for (int col = src_left; col < src_left + width; col++) { |
| 786 if (src_scan[col / 8] & (1 << (7 - col % 8))) { |
| 787 *dest_scan++ = bgr_ptr[3]; |
| 788 *dest_scan++ = bgr_ptr[4]; |
| 789 *dest_scan = bgr_ptr[5]; |
| 790 } else { |
| 791 *dest_scan++ = bgr_ptr[0]; |
| 792 *dest_scan++ = bgr_ptr[1]; |
| 793 *dest_scan = bgr_ptr[2]; |
| 794 } |
| 795 dest_scan += comps - 2; |
| 796 } |
| 797 } |
| 798 return TRUE; |
| 799 } |
| 800 FX_BOOL _ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, |
| 801 FX_LPBYTE dest_buf, |
| 802 int dest_pitch, |
| 803 int width, |
| 804 int height, |
| 805 const CFX_DIBSource* pSrcBitmap, |
| 806 int src_left, |
| 807 int src_top, |
| 808 void* pIccTransform) { |
| 809 int comps = (dst_format & 0xff) / 8; |
| 810 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); |
| 811 FX_DWORD plt[256]; |
| 812 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; |
| 813 if (!pSrcBitmap->IsCmykImage()) { |
| 814 for (int i = 0; i < 256; i++) { |
| 815 *bgr_ptr++ = FXARGB_B(src_plt[i]); |
| 816 *bgr_ptr++ = FXARGB_G(src_plt[i]); |
| 817 *bgr_ptr++ = FXARGB_R(src_plt[i]); |
| 818 } |
| 819 bgr_ptr = (FX_LPBYTE)plt; |
| 820 } |
| 821 if (pIccTransform) { |
| 822 if (pSrcBitmap->IsCmykImage()) { |
| 823 for (int i = 0; i < 256; i++) { |
| 824 plt[i] = FXCMYK_TODIB(src_plt[i]); |
| 825 } |
| 826 } |
| 827 ICodec_IccModule* pIccModule = |
| 828 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 829 pIccModule->TranslateScanline( |
| 830 pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE)plt, 256); |
| 831 } else { |
| 832 if (pSrcBitmap->IsCmykImage()) { |
| 833 for (int i = 0; i < 256; i++) { |
| 834 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), |
| 835 FXSYS_GetMValue(src_plt[i]), |
| 836 FXSYS_GetYValue(src_plt[i]), |
| 837 FXSYS_GetKValue(src_plt[i]), |
| 838 bgr_ptr[2], |
| 839 bgr_ptr[1], |
| 840 bgr_ptr[0]); |
| 841 bgr_ptr += 3; |
| 842 } |
| 843 bgr_ptr = (FX_LPBYTE)plt; |
| 844 } |
| 845 } |
| 846 for (int row = 0; row < height; row++) { |
| 847 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 848 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; |
| 849 for (int col = 0; col < width; col++) { |
| 850 FX_LPBYTE src_pixel = bgr_ptr + 3 * (*src_scan++); |
| 851 *dest_scan++ = *src_pixel++; |
| 852 *dest_scan++ = *src_pixel++; |
| 853 *dest_scan = *src_pixel++; |
| 854 dest_scan += comps - 2; |
| 855 } |
| 856 } |
| 857 return TRUE; |
| 858 } |
| 859 FX_BOOL _ConvertBuffer_24bppRgb2Rgb24(FX_LPBYTE dest_buf, |
| 860 int dest_pitch, |
| 861 int width, |
| 862 int height, |
| 863 const CFX_DIBSource* pSrcBitmap, |
| 864 int src_left, |
| 865 int src_top, |
| 866 void* pIccTransform) { |
| 867 if (pIccTransform) { |
| 868 ICodec_IccModule* pIccModule = |
| 869 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 870 for (int row = 0; row < height; row++) { |
| 871 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 872 FX_LPCBYTE src_scan = |
| 873 pSrcBitmap->GetScanline(src_top + row) + src_left * 3; |
| 874 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, width); |
| 875 } |
| 876 } else { |
| 877 for (int row = 0; row < height; row++) { |
| 878 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 879 FX_LPCBYTE src_scan = |
| 880 pSrcBitmap->GetScanline(src_top + row) + src_left * 3; |
| 881 FXSYS_memcpy32(dest_scan, src_scan, width * 3); |
| 882 } |
| 883 } |
| 884 return TRUE; |
| 885 } |
| 886 FX_BOOL _ConvertBuffer_32bppRgb2Rgb24(FX_LPBYTE dest_buf, |
| 887 int dest_pitch, |
| 888 int width, |
| 889 int height, |
| 890 const CFX_DIBSource* pSrcBitmap, |
| 891 int src_left, |
| 892 int src_top, |
| 893 void* pIccTransform) { |
| 894 for (int row = 0; row < height; row++) { |
| 895 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 896 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 897 for (int col = 0; col < width; col++) { |
| 898 *dest_scan++ = *src_scan++; |
| 899 *dest_scan++ = *src_scan++; |
| 900 *dest_scan++ = *src_scan++; |
| 901 src_scan++; |
| 902 } |
| 903 } |
| 904 if (pIccTransform) { |
| 905 ICodec_IccModule* pIccModule = |
| 906 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 907 for (int row = 0; row < height; row++) { |
| 908 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 909 pIccModule->TranslateScanline(pIccTransform, dest_scan, dest_scan, width); |
| 910 } |
| 911 } |
| 912 return TRUE; |
| 913 } |
| 914 FX_BOOL _ConvertBuffer_Rgb2Rgb32(FX_LPBYTE dest_buf, |
| 915 int dest_pitch, |
| 916 int width, |
| 917 int height, |
| 918 const CFX_DIBSource* pSrcBitmap, |
| 919 int src_left, |
| 920 int src_top, |
| 921 void* pIccTransform) { |
| 922 int comps = pSrcBitmap->GetBPP() / 8; |
| 923 if (pIccTransform) { |
| 924 ICodec_IccModule* pIccModule = |
| 925 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 926 for (int row = 0; row < height; row++) { |
| 927 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 928 FX_LPCBYTE src_scan = |
| 929 pSrcBitmap->GetScanline(src_top + row) + src_left * comps; |
| 930 for (int col = 0; col < width; col++) { |
| 931 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1); |
| 932 dest_scan += 4; |
| 933 src_scan += comps; |
| 934 } |
| 935 } |
| 936 } else { |
| 937 for (int row = 0; row < height; row++) { |
| 938 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 939 FX_LPCBYTE src_scan = |
| 940 pSrcBitmap->GetScanline(src_top + row) + src_left * comps; |
| 941 for (int col = 0; col < width; col++) { |
| 942 *dest_scan++ = *src_scan++; |
| 943 *dest_scan++ = *src_scan++; |
| 944 *dest_scan++ = *src_scan++; |
| 945 dest_scan++; |
| 946 src_scan += comps - 3; |
| 947 } |
| 948 } |
| 949 } |
| 950 return TRUE; |
| 951 } |
| 952 FX_BOOL _ConvertBuffer_32bppCmyk2Rgb32(FX_LPBYTE dest_buf, |
| 953 int dest_pitch, |
| 954 int width, |
| 955 int height, |
| 956 const CFX_DIBSource* pSrcBitmap, |
| 957 int src_left, |
| 958 int src_top, |
| 959 void* pIccTransform) { |
| 960 if (pIccTransform) { |
| 961 ICodec_IccModule* pIccModule = |
| 962 CFX_GEModule::Get()->GetCodecModule()->GetIccModule(); |
| 963 for (int row = 0; row < height; row++) { |
| 964 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 965 FX_LPCBYTE src_scan = |
| 966 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 967 for (int col = 0; col < width; col++) { |
| 968 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, 1); |
| 969 dest_scan += 4; |
| 970 src_scan += 4; |
| 971 } |
| 972 } |
| 973 } else { |
| 974 for (int row = 0; row < height; row++) { |
| 975 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; |
| 976 FX_LPCBYTE src_scan = |
| 977 pSrcBitmap->GetScanline(src_top + row) + src_left * 4; |
| 978 for (int col = 0; col < width; col++) { |
| 979 AdobeCMYK_to_sRGB1(src_scan[0], |
| 980 src_scan[1], |
| 981 src_scan[2], |
| 982 src_scan[3], |
| 983 dest_scan[2], |
| 984 dest_scan[1], |
| 985 dest_scan[0]); |
| 986 dest_scan += 4; |
| 987 src_scan += 4; |
| 988 } |
| 989 } |
| 990 } |
| 991 return TRUE; |
| 992 } |
| 993 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, |
| 994 FX_LPBYTE dest_buf, |
| 995 int dest_pitch, |
| 996 int width, |
| 997 int height, |
| 998 const CFX_DIBSource* pSrcBitmap, |
| 999 int src_left, |
| 1000 int src_top, |
| 1001 FX_DWORD*& d_pal, |
| 1002 void* pIccTransform) { |
| 1003 FXDIB_Format src_format = pSrcBitmap->GetFormat(); |
| 1004 if (!CFX_GEModule::Get()->GetCodecModule() || |
| 1005 !CFX_GEModule::Get()->GetCodecModule()->GetIccModule()) { |
| 1006 pIccTransform = NULL; |
| 1007 } |
| 1008 switch (dest_format) { |
| 1009 case FXDIB_Invalid: |
| 1010 case FXDIB_1bppCmyk: |
| 1011 case FXDIB_1bppMask: |
| 1012 case FXDIB_1bppRgb: |
| 1013 ASSERT(FALSE); |
| 1014 return FALSE; |
| 1015 case FXDIB_8bppMask: { |
| 1016 if ((src_format & 0xff) == 1) { |
| 1017 if (pSrcBitmap->GetPalette()) { |
| 1018 return _ConvertBuffer_1bppPlt2Gray(dest_buf, |
| 1019 dest_pitch, |
| 1020 width, |
| 1021 height, |
| 1022 pSrcBitmap, |
| 1023 src_left, |
| 1024 src_top, |
| 1025 pIccTransform); |
| 1026 } |
| 1027 return _ConvertBuffer_1bppMask2Gray( |
| 1028 dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top); |
| 1029 } else if ((src_format & 0xff) == 8) { |
| 1030 if (pSrcBitmap->GetPalette()) { |
| 1031 return _ConvertBuffer_8bppPlt2Gray(dest_buf, |
| 1032 dest_pitch, |
| 1033 width, |
| 1034 height, |
| 1035 pSrcBitmap, |
| 1036 src_left, |
| 1037 src_top, |
| 1038 pIccTransform); |
| 1039 } |
| 1040 return _ConvertBuffer_8bppMask2Gray( |
| 1041 dest_buf, dest_pitch, width, height, pSrcBitmap, src_left, src_top); |
| 1042 } else if ((src_format & 0xff) >= 24) { |
| 1043 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, |
| 1044 dest_pitch, |
| 1045 width, |
| 1046 height, |
| 1047 pSrcBitmap, |
| 1048 src_left, |
| 1049 src_top, |
| 1050 pIccTransform); |
| 1051 } |
| 1052 return FALSE; |
| 1053 } |
| 1054 case FXDIB_8bppRgb: |
| 1055 case FXDIB_8bppRgba: { |
| 1056 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL) { |
| 1057 return ConvertBuffer(FXDIB_8bppMask, |
| 1058 dest_buf, |
| 1059 dest_pitch, |
| 1060 width, |
| 1061 height, |
| 1062 pSrcBitmap, |
| 1063 src_left, |
| 1064 src_top, |
| 1065 d_pal, |
| 1066 pIccTransform); |
| 1067 } |
| 1068 d_pal = FX_Alloc(FX_DWORD, 256); |
| 1069 if (!d_pal) { |
| 1070 return FALSE; |
| 1071 } |
| 1072 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && |
| 1073 pSrcBitmap->GetPalette()) { |
| 1074 return _ConvertBuffer_Plt2PltRgb8(dest_buf, |
| 1075 dest_pitch, |
| 1076 width, |
| 1077 height, |
| 1078 pSrcBitmap, |
| 1079 src_left, |
| 1080 src_top, |
| 1081 d_pal, |
| 1082 pIccTransform); |
| 1083 } else if ((src_format & 0xff) >= 24) { |
| 1084 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, |
| 1085 dest_pitch, |
| 1086 width, |
| 1087 height, |
| 1088 pSrcBitmap, |
| 1089 src_left, |
| 1090 src_top, |
| 1091 d_pal, |
| 1092 pIccTransform); |
| 1093 } |
| 1094 return FALSE; |
| 1095 } |
| 1096 case FXDIB_Rgb: |
| 1097 case FXDIB_Rgba: { |
| 1098 if ((src_format & 0xff) == 1) { |
| 1099 if (pSrcBitmap->GetPalette()) { |
| 1100 return _ConvertBuffer_1bppPlt2Rgb(dest_format, |
| 1101 dest_buf, |
| 1102 dest_pitch, |
| 1103 width, |
| 1104 height, |
| 1105 pSrcBitmap, |
| 1106 src_left, |
| 1107 src_top, |
| 1108 pIccTransform); |
| 1109 } |
| 1110 return _ConvertBuffer_1bppMask2Rgb(dest_format, |
| 1111 dest_buf, |
| 1112 dest_pitch, |
| 1113 width, |
| 1114 height, |
| 1115 pSrcBitmap, |
| 1116 src_left, |
| 1117 src_top); |
| 1118 } else if ((src_format & 0xff) == 8) { |
| 1119 if (pSrcBitmap->GetPalette()) { |
| 1120 return _ConvertBuffer_8bppPlt2Rgb(dest_format, |
| 1121 dest_buf, |
| 1122 dest_pitch, |
| 1123 width, |
| 1124 height, |
| 1125 pSrcBitmap, |
| 1126 src_left, |
| 1127 src_top, |
| 1128 pIccTransform); |
| 1129 } |
| 1130 return _ConvertBuffer_8bppMask2Rgb(dest_format, |
| 1131 dest_buf, |
| 1132 dest_pitch, |
| 1133 width, |
| 1134 height, |
| 1135 pSrcBitmap, |
| 1136 src_left, |
| 1137 src_top); |
| 1138 } else if ((src_format & 0xff) == 24) { |
| 1139 return _ConvertBuffer_24bppRgb2Rgb24(dest_buf, |
| 1140 dest_pitch, |
| 1141 width, |
| 1142 height, |
| 1143 pSrcBitmap, |
| 1144 src_left, |
| 1145 src_top, |
| 1146 pIccTransform); |
| 1147 } else if ((src_format & 0xff) == 32) { |
| 1148 return _ConvertBuffer_32bppRgb2Rgb24(dest_buf, |
| 1149 dest_pitch, |
| 1150 width, |
| 1151 height, |
| 1152 pSrcBitmap, |
| 1153 src_left, |
| 1154 src_top, |
| 1155 pIccTransform); |
| 1156 } |
| 1157 return FALSE; |
| 1158 } |
| 1159 case FXDIB_Argb: |
| 1160 case FXDIB_Rgb32: { |
| 1161 if ((src_format & 0xff) == 1) { |
| 1162 if (pSrcBitmap->GetPalette()) { |
| 1163 return _ConvertBuffer_1bppPlt2Rgb(dest_format, |
| 1164 dest_buf, |
| 1165 dest_pitch, |
| 1166 width, |
| 1167 height, |
| 1168 pSrcBitmap, |
| 1169 src_left, |
| 1170 src_top, |
| 1171 pIccTransform); |
| 1172 } |
| 1173 return _ConvertBuffer_1bppMask2Rgb(dest_format, |
| 1174 dest_buf, |
| 1175 dest_pitch, |
| 1176 width, |
| 1177 height, |
| 1178 pSrcBitmap, |
| 1179 src_left, |
| 1180 src_top); |
| 1181 } else if ((src_format & 0xff) == 8) { |
| 1182 if (pSrcBitmap->GetPalette()) { |
| 1183 return _ConvertBuffer_8bppPlt2Rgb(dest_format, |
| 1184 dest_buf, |
| 1185 dest_pitch, |
| 1186 width, |
| 1187 height, |
| 1188 pSrcBitmap, |
| 1189 src_left, |
| 1190 src_top, |
| 1191 pIccTransform); |
| 1192 } |
| 1193 return _ConvertBuffer_8bppMask2Rgb(dest_format, |
| 1194 dest_buf, |
| 1195 dest_pitch, |
| 1196 width, |
| 1197 height, |
| 1198 pSrcBitmap, |
| 1199 src_left, |
| 1200 src_top); |
| 1201 } else if ((src_format & 0xff) >= 24) { |
| 1202 if (src_format & 0x0400) { |
| 1203 return _ConvertBuffer_32bppCmyk2Rgb32(dest_buf, |
| 1204 dest_pitch, |
| 1205 width, |
| 1206 height, |
| 1207 pSrcBitmap, |
| 1208 src_left, |
| 1209 src_top, |
| 1210 pIccTransform); |
| 1211 } |
| 1212 return _ConvertBuffer_Rgb2Rgb32(dest_buf, |
| 1213 dest_pitch, |
| 1214 width, |
| 1215 height, |
| 1216 pSrcBitmap, |
| 1217 src_left, |
| 1218 src_top, |
| 1219 pIccTransform); |
| 1220 } |
| 1221 return FALSE; |
| 1222 } |
| 1223 default: |
| 1224 return FALSE; |
| 1225 } |
| 1226 return FALSE; |
| 1227 } |
| 1228 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, |
| 1229 const FX_RECT* pClip, |
| 1230 void* pIccTransform) const { |
| 1231 if (dest_format == GetFormat() && pIccTransform == NULL) { |
| 1232 return Clone(pClip); |
| 1233 } |
| 1234 if (pClip) { |
| 1235 CFX_DIBitmap* pClone = Clone(pClip); |
| 1236 if (pClone == NULL) { |
| 1237 return NULL; |
| 1238 } |
| 1239 if (!pClone->ConvertFormat(dest_format, pIccTransform)) { |
| 1240 delete pClone; |
| 1241 return NULL; |
| 1242 } |
| 1243 return pClone; |
| 1244 } |
| 1245 CFX_DIBitmap* pClone = FX_NEW CFX_DIBitmap; |
| 1246 if (!pClone) { |
| 1247 return NULL; |
| 1248 } |
| 1249 if (!pClone->Create(m_Width, m_Height, dest_format)) { |
| 1250 delete pClone; |
| 1251 return NULL; |
| 1252 } |
| 1253 FX_BOOL ret = TRUE; |
| 1254 CFX_DIBitmap* pSrcAlpha = NULL; |
| 1255 if (m_AlphaFlag & 2) { |
| 1256 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; |
| 1257 if (pSrcAlpha == NULL) { |
| 1258 delete pClone; |
| 1259 return NULL; |
| 1260 } |
| 1261 } |
| 1262 if (dest_format & 0x0200) { |
| 1263 if (dest_format == FXDIB_Argb) |
| 1264 ret = pSrcAlpha ? pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) |
| 1265 : pClone->LoadChannel(FXDIB_Alpha, 0xff); |
| 1266 else { |
| 1267 ret = pClone->CopyAlphaMask(pSrcAlpha); |
| 1268 } |
| 1269 } |
| 1270 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { |
| 1271 delete pSrcAlpha; |
| 1272 pSrcAlpha = NULL; |
| 1273 } |
| 1274 if (!ret) { |
| 1275 delete pClone; |
| 1276 return NULL; |
| 1277 } |
| 1278 FX_DWORD* pal_8bpp = NULL; |
| 1279 ret = ConvertBuffer(dest_format, |
| 1280 pClone->GetBuffer(), |
| 1281 pClone->GetPitch(), |
| 1282 m_Width, |
| 1283 m_Height, |
| 1284 this, |
| 1285 0, |
| 1286 0, |
| 1287 pal_8bpp, |
| 1288 pIccTransform); |
| 1289 if (!ret) { |
| 1290 if (pal_8bpp) { |
| 1291 FX_Free(pal_8bpp); |
| 1292 } |
| 1293 delete pClone; |
| 1294 return NULL; |
| 1295 } |
| 1296 if (pal_8bpp) { |
| 1297 pClone->CopyPalette(pal_8bpp); |
| 1298 FX_Free(pal_8bpp); |
| 1299 pal_8bpp = NULL; |
| 1300 } |
| 1301 return pClone; |
| 1302 } |
| 1303 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, |
| 1304 void* pIccTransform) { |
| 1305 FXDIB_Format src_format = GetFormat(); |
| 1306 if (dest_format == src_format && pIccTransform == NULL) { |
| 692 return TRUE; | 1307 return TRUE; |
| 693 } | 1308 } |
| 694 FX_BOOL _ConvertBuffer_8bppPlt2Rgb(FXDIB_Format dst_format, FX_LPBYTE dest_buf,
int dest_pitch, int width, int height, | 1309 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && |
| 695 const CFX_DIBSource* pSrcBitmap, int src_left
, int src_top, void* pIccTransform) | 1310 m_pPalette == NULL) { |
| 696 { | 1311 m_AlphaFlag = 1; |
| 697 int comps = (dst_format & 0xff) / 8; | 1312 return TRUE; |
| 698 FX_DWORD* src_plt = pSrcBitmap->GetPalette(); | 1313 } |
| 699 FX_DWORD plt[256]; | 1314 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && |
| 700 FX_LPBYTE bgr_ptr = (FX_LPBYTE)plt; | 1315 pIccTransform == NULL) { |
| 701 if (!pSrcBitmap->IsCmykImage()) { | 1316 m_AlphaFlag = 2; |
| 702 for (int i = 0; i < 256; i++) { | 1317 for (int row = 0; row < m_Height; row++) { |
| 703 *bgr_ptr++ = FXARGB_B(src_plt[i]); | 1318 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch + 3; |
| 704 *bgr_ptr++ = FXARGB_G(src_plt[i]); | 1319 for (int col = 0; col < m_Width; col++) { |
| 705 *bgr_ptr++ = FXARGB_R(src_plt[i]); | 1320 *scanline = 0xff; |
| 706 } | 1321 scanline += 4; |
| 707 bgr_ptr = (FX_LPBYTE)plt; | 1322 } |
| 708 } | 1323 } |
| 709 if (pIccTransform) { | 1324 return TRUE; |
| 710 if (pSrcBitmap->IsCmykImage()) { | 1325 } |
| 711 for (int i = 0; i < 256; i++) { | 1326 int dest_bpp = dest_format & 0xff; |
| 712 plt[i] = FXCMYK_TODIB(src_plt[i]); | 1327 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; |
| 713 } | 1328 FX_LPBYTE dest_buf = FX_AllocNL(FX_BYTE, dest_pitch * m_Height + 4); |
| 714 } | 1329 if (dest_buf == NULL) { |
| 715 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | 1330 return FALSE; |
| 716 pIccModule->TranslateScanline(pIccTransform, (FX_LPBYTE)plt, (FX_LPCBYTE
)plt, 256); | 1331 } |
| 1332 CFX_DIBitmap* pAlphaMask = NULL; |
| 1333 if (dest_format == FXDIB_Argb) { |
| 1334 FXSYS_memset8(dest_buf, 0xff, dest_pitch * m_Height + 4); |
| 1335 if (m_pAlphaMask) { |
| 1336 for (int row = 0; row < m_Height; row++) { |
| 1337 FX_LPBYTE pDstScanline = dest_buf + row * dest_pitch + 3; |
| 1338 FX_LPCBYTE pSrcScanline = m_pAlphaMask->GetScanline(row); |
| 1339 for (int col = 0; col < m_Width; col++) { |
| 1340 *pDstScanline = *pSrcScanline++; |
| 1341 pDstScanline += 4; |
| 1342 } |
| 1343 } |
| 1344 } |
| 1345 } else if (dest_format & 0x0200) { |
| 1346 if (src_format == FXDIB_Argb) { |
| 1347 pAlphaMask = GetAlphaMask(); |
| 1348 if (pAlphaMask == NULL) { |
| 1349 FX_Free(dest_buf); |
| 1350 return FALSE; |
| 1351 } |
| 717 } else { | 1352 } else { |
| 718 if (pSrcBitmap->IsCmykImage()) { | 1353 if (m_pAlphaMask == NULL) { |
| 719 for (int i = 0; i < 256; i++) { | 1354 if (!BuildAlphaMask()) { |
| 720 AdobeCMYK_to_sRGB1(FXSYS_GetCValue(src_plt[i]), FXSYS_GetMValue(
src_plt[i]), FXSYS_GetYValue(src_plt[i]), FXSYS_GetKValue(src_plt[i]), | 1355 FX_Free(dest_buf); |
| 721 bgr_ptr[2], bgr_ptr[1], bgr_ptr[0]); | 1356 return FALSE; |
| 722 bgr_ptr += 3; | 1357 } |
| 723 } | 1358 pAlphaMask = m_pAlphaMask; |
| 724 bgr_ptr = (FX_LPBYTE)plt; | 1359 m_pAlphaMask = NULL; |
| 725 } | 1360 } else { |
| 726 } | 1361 pAlphaMask = m_pAlphaMask; |
| 727 for (int row = 0; row < height; row ++) { | 1362 } |
| 728 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 1363 } |
| 729 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left; | 1364 } |
| 730 for (int col = 0; col < width; col ++) { | 1365 FX_BOOL ret = FALSE; |
| 731 FX_LPBYTE src_pixel = bgr_ptr + 3 * (*src_scan++); | 1366 FX_DWORD* pal_8bpp = NULL; |
| 732 *dest_scan++ = *src_pixel++; | 1367 ret = ConvertBuffer(dest_format, |
| 733 *dest_scan++ = *src_pixel++; | 1368 dest_buf, |
| 734 *dest_scan = *src_pixel++; | 1369 dest_pitch, |
| 735 dest_scan += comps - 2; | 1370 m_Width, |
| 736 } | 1371 m_Height, |
| 737 } | 1372 this, |
| 738 return TRUE; | 1373 0, |
| 739 } | 1374 0, |
| 740 FX_BOOL _ConvertBuffer_24bppRgb2Rgb24(FX_LPBYTE dest_buf, int dest_pitch, int wi
dth, int height, | 1375 pal_8bpp, |
| 741 const CFX_DIBSource* pSrcBitmap, int src_l
eft, int src_top, void* pIccTransform) | 1376 pIccTransform); |
| 742 { | 1377 if (!ret) { |
| 743 if (pIccTransform) { | 1378 if (pal_8bpp) { |
| 744 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | 1379 FX_Free(pal_8bpp); |
| 745 for (int row = 0; row < height; row ++) { | 1380 } |
| 746 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | 1381 if (pAlphaMask != m_pAlphaMask) { |
| 747 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l
eft * 3; | 1382 delete pAlphaMask; |
| 748 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan, wi
dth); | 1383 } |
| 749 } | 1384 if (dest_buf) { |
| 750 } else { | 1385 FX_Free(dest_buf); |
| 751 for (int row = 0; row < height; row ++) { | |
| 752 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 753 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l
eft * 3; | |
| 754 FXSYS_memcpy32(dest_scan, src_scan, width * 3); | |
| 755 } | |
| 756 } | |
| 757 return TRUE; | |
| 758 } | |
| 759 FX_BOOL _ConvertBuffer_32bppRgb2Rgb24(FX_LPBYTE dest_buf, int dest_pitch, int wi
dth, int height, | |
| 760 const CFX_DIBSource* pSrcBitmap, int src_l
eft, int src_top, void* pIccTransform) | |
| 761 { | |
| 762 for (int row = 0; row < height; row ++) { | |
| 763 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 764 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_left
* 4; | |
| 765 for (int col = 0; col < width; col ++) { | |
| 766 *dest_scan++ = *src_scan++; | |
| 767 *dest_scan++ = *src_scan++; | |
| 768 *dest_scan++ = *src_scan++; | |
| 769 src_scan++; | |
| 770 } | |
| 771 } | |
| 772 if (pIccTransform) { | |
| 773 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | |
| 774 for (int row = 0; row < height; row ++) { | |
| 775 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 776 pIccModule->TranslateScanline(pIccTransform, dest_scan, dest_scan, w
idth); | |
| 777 } | |
| 778 } | |
| 779 return TRUE; | |
| 780 } | |
| 781 FX_BOOL _ConvertBuffer_Rgb2Rgb32(FX_LPBYTE dest_buf, int dest_pitch, int width,
int height, | |
| 782 const CFX_DIBSource* pSrcBitmap, int src_left,
int src_top, void* pIccTransform) | |
| 783 { | |
| 784 int comps = pSrcBitmap->GetBPP() / 8; | |
| 785 if (pIccTransform) { | |
| 786 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | |
| 787 for (int row = 0; row < height; row ++) { | |
| 788 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 789 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l
eft * comps; | |
| 790 for (int col = 0; col < width; col ++) { | |
| 791 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan
, 1); | |
| 792 dest_scan += 4; | |
| 793 src_scan += comps; | |
| 794 } | |
| 795 } | |
| 796 } else { | |
| 797 for (int row = 0; row < height; row ++) { | |
| 798 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 799 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l
eft * comps; | |
| 800 for (int col = 0; col < width; col ++) { | |
| 801 *dest_scan++ = *src_scan++; | |
| 802 *dest_scan++ = *src_scan++; | |
| 803 *dest_scan++ = *src_scan++; | |
| 804 dest_scan++; | |
| 805 src_scan += comps - 3; | |
| 806 } | |
| 807 } | |
| 808 } | |
| 809 return TRUE; | |
| 810 } | |
| 811 FX_BOOL _ConvertBuffer_32bppCmyk2Rgb32(FX_LPBYTE dest_buf, int dest_pitch, int w
idth, int height, | |
| 812 const CFX_DIBSource* pSrcBitmap, int src_
left, int src_top, void* pIccTransform) | |
| 813 { | |
| 814 if (pIccTransform) { | |
| 815 ICodec_IccModule* pIccModule = CFX_GEModule::Get()->GetCodecModule()->Ge
tIccModule(); | |
| 816 for (int row = 0; row < height; row ++) { | |
| 817 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 818 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l
eft * 4; | |
| 819 for (int col = 0; col < width; col ++) { | |
| 820 pIccModule->TranslateScanline(pIccTransform, dest_scan, src_scan
, 1); | |
| 821 dest_scan += 4; | |
| 822 src_scan += 4; | |
| 823 } | |
| 824 } | |
| 825 } else { | |
| 826 for (int row = 0; row < height; row ++) { | |
| 827 FX_LPBYTE dest_scan = dest_buf + row * dest_pitch; | |
| 828 FX_LPCBYTE src_scan = pSrcBitmap->GetScanline(src_top + row) + src_l
eft * 4; | |
| 829 for (int col = 0; col < width; col ++) { | |
| 830 AdobeCMYK_to_sRGB1(src_scan[0], src_scan[1], src_scan[2], src_sc
an[3], | |
| 831 dest_scan[2], dest_scan[1], dest_scan[0]); | |
| 832 dest_scan += 4; | |
| 833 src_scan += 4; | |
| 834 } | |
| 835 } | |
| 836 } | |
| 837 return TRUE; | |
| 838 } | |
| 839 FX_BOOL ConvertBuffer(FXDIB_Format dest_format, FX_LPBYTE dest_buf, int dest_pit
ch, int width, int height, | |
| 840 const CFX_DIBSource* pSrcBitmap, int src_left, int src_top
, FX_DWORD*& d_pal, void* pIccTransform) | |
| 841 { | |
| 842 FXDIB_Format src_format = pSrcBitmap->GetFormat(); | |
| 843 if (!CFX_GEModule::Get()->GetCodecModule() || !CFX_GEModule::Get()->GetCodec
Module()->GetIccModule()) { | |
| 844 pIccTransform = NULL; | |
| 845 } | |
| 846 switch (dest_format) { | |
| 847 case FXDIB_Invalid: | |
| 848 case FXDIB_1bppCmyk: | |
| 849 case FXDIB_1bppMask: | |
| 850 case FXDIB_1bppRgb: | |
| 851 ASSERT(FALSE); | |
| 852 return FALSE; | |
| 853 case FXDIB_8bppMask: { | |
| 854 if ((src_format & 0xff) == 1) { | |
| 855 if (pSrcBitmap->GetPalette()) { | |
| 856 return _ConvertBuffer_1bppPlt2Gray(dest_buf, dest_pitch,
width, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 857 } | |
| 858 return _ConvertBuffer_1bppMask2Gray(dest_buf, dest_pitch, wi
dth, height, pSrcBitmap, src_left, src_top); | |
| 859 } else if ((src_format & 0xff) == 8) { | |
| 860 if (pSrcBitmap->GetPalette()) { | |
| 861 return _ConvertBuffer_8bppPlt2Gray(dest_buf, dest_pitch,
width, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 862 } | |
| 863 return _ConvertBuffer_8bppMask2Gray(dest_buf, dest_pitch, wi
dth, height, pSrcBitmap, src_left, src_top); | |
| 864 } else if ((src_format & 0xff) >= 24) { | |
| 865 return _ConvertBuffer_RgbOrCmyk2Gray(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 866 } | |
| 867 return FALSE; | |
| 868 } | |
| 869 case FXDIB_8bppRgb: | |
| 870 case FXDIB_8bppRgba: { | |
| 871 if ((src_format & 0xff) == 8 && pSrcBitmap->GetPalette() == NULL
) { | |
| 872 return ConvertBuffer(FXDIB_8bppMask, dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | |
| 873 } | |
| 874 d_pal = FX_Alloc(FX_DWORD, 256); | |
| 875 if (!d_pal) { | |
| 876 return FALSE; | |
| 877 } | |
| 878 if (((src_format & 0xff) == 1 || (src_format & 0xff) == 8) && pS
rcBitmap->GetPalette()) { | |
| 879 return _ConvertBuffer_Plt2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | |
| 880 } else if ((src_format & 0xff) >= 24) { | |
| 881 return _ConvertBuffer_Rgb2PltRgb8(dest_buf, dest_pitch, widt
h, height, pSrcBitmap, src_left, src_top, d_pal, pIccTransform); | |
| 882 } | |
| 883 return FALSE; | |
| 884 } | |
| 885 case FXDIB_Rgb: | |
| 886 case FXDIB_Rgba: { | |
| 887 if ((src_format & 0xff) == 1) { | |
| 888 if (pSrcBitmap->GetPalette()) { | |
| 889 return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf,
dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 890 } | |
| 891 return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, de
st_pitch, width, height, pSrcBitmap, src_left, src_top); | |
| 892 } else if ((src_format & 0xff) == 8) { | |
| 893 if (pSrcBitmap->GetPalette()) { | |
| 894 return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf,
dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 895 } | |
| 896 return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, de
st_pitch, width, height, pSrcBitmap, src_left, src_top); | |
| 897 } else if ((src_format & 0xff) == 24) { | |
| 898 return _ConvertBuffer_24bppRgb2Rgb24(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 899 } else if ((src_format & 0xff) == 32) { | |
| 900 return _ConvertBuffer_32bppRgb2Rgb24(dest_buf, dest_pitch, w
idth, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 901 } | |
| 902 return FALSE; | |
| 903 } | |
| 904 case FXDIB_Argb: | |
| 905 case FXDIB_Rgb32: { | |
| 906 if ((src_format & 0xff) == 1) { | |
| 907 if (pSrcBitmap->GetPalette()) { | |
| 908 return _ConvertBuffer_1bppPlt2Rgb(dest_format, dest_buf,
dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 909 } | |
| 910 return _ConvertBuffer_1bppMask2Rgb(dest_format, dest_buf, de
st_pitch, width, height, pSrcBitmap, src_left, src_top); | |
| 911 } else if ((src_format & 0xff) == 8) { | |
| 912 if (pSrcBitmap->GetPalette()) { | |
| 913 return _ConvertBuffer_8bppPlt2Rgb(dest_format, dest_buf,
dest_pitch, width, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 914 } | |
| 915 return _ConvertBuffer_8bppMask2Rgb(dest_format, dest_buf, de
st_pitch, width, height, pSrcBitmap, src_left, src_top); | |
| 916 } else if ((src_format & 0xff) >= 24) { | |
| 917 if (src_format & 0x0400) { | |
| 918 return _ConvertBuffer_32bppCmyk2Rgb32(dest_buf, dest_pit
ch, width, height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 919 } | |
| 920 return _ConvertBuffer_Rgb2Rgb32(dest_buf, dest_pitch, width,
height, pSrcBitmap, src_left, src_top, pIccTransform); | |
| 921 } | |
| 922 return FALSE; | |
| 923 } | |
| 924 default: | |
| 925 return FALSE; | |
| 926 } | 1386 } |
| 927 return FALSE; | 1387 return FALSE; |
| 928 } | 1388 } |
| 929 CFX_DIBitmap* CFX_DIBSource::CloneConvert(FXDIB_Format dest_format, const FX_REC
T* pClip, void* pIccTransform) const | 1389 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { |
| 930 { | 1390 delete m_pAlphaMask; |
| 931 if(dest_format == GetFormat() && pIccTransform == NULL) { | 1391 } |
| 932 return Clone(pClip); | 1392 m_pAlphaMask = pAlphaMask; |
| 933 } | 1393 if (m_pPalette) { |
| 934 if (pClip) { | 1394 FX_Free(m_pPalette); |
| 935 CFX_DIBitmap* pClone = Clone(pClip); | 1395 } |
| 936 if (pClone == NULL) { | 1396 m_pPalette = pal_8bpp; |
| 937 return NULL; | 1397 if (!m_bExtBuf) { |
| 938 } | 1398 FX_Free(m_pBuffer); |
| 939 if(!pClone->ConvertFormat(dest_format, pIccTransform)) { | 1399 } |
| 940 delete pClone; | 1400 m_bExtBuf = FALSE; |
| 941 return NULL; | 1401 m_pBuffer = dest_buf; |
| 942 } | 1402 m_bpp = (FX_BYTE)dest_format; |
| 943 return pClone; | 1403 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); |
| 944 } | 1404 m_Pitch = dest_pitch; |
| 945 CFX_DIBitmap* pClone = FX_NEW CFX_DIBitmap; | 1405 return TRUE; |
| 946 if (!pClone) { | 1406 } |
| 947 return NULL; | |
| 948 } | |
| 949 if(!pClone->Create(m_Width, m_Height, dest_format)) { | |
| 950 delete pClone; | |
| 951 return NULL; | |
| 952 } | |
| 953 FX_BOOL ret = TRUE; | |
| 954 CFX_DIBitmap* pSrcAlpha = NULL; | |
| 955 if (m_AlphaFlag & 2) { | |
| 956 pSrcAlpha = (GetFormat() == FXDIB_Argb) ? GetAlphaMask() : m_pAlphaMask; | |
| 957 if (pSrcAlpha == NULL) { | |
| 958 delete pClone; | |
| 959 return NULL; | |
| 960 } | |
| 961 } | |
| 962 if (dest_format & 0x0200) { | |
| 963 if (dest_format == FXDIB_Argb) | |
| 964 ret = pSrcAlpha ? | |
| 965 pClone->LoadChannel(FXDIB_Alpha, pSrcAlpha, FXDIB_Alpha) : | |
| 966 pClone->LoadChannel(FXDIB_Alpha, 0xff); | |
| 967 else { | |
| 968 ret = pClone->CopyAlphaMask(pSrcAlpha); | |
| 969 } | |
| 970 } | |
| 971 if (pSrcAlpha && pSrcAlpha != m_pAlphaMask) { | |
| 972 delete pSrcAlpha; | |
| 973 pSrcAlpha = NULL; | |
| 974 } | |
| 975 if (!ret) { | |
| 976 delete pClone; | |
| 977 return NULL; | |
| 978 } | |
| 979 FX_DWORD* pal_8bpp = NULL; | |
| 980 ret = ConvertBuffer(dest_format, pClone->GetBuffer(), pClone->GetPitch(), m_
Width, m_Height, this, 0, 0, pal_8bpp, pIccTransform); | |
| 981 if (!ret) { | |
| 982 if (pal_8bpp) { | |
| 983 FX_Free(pal_8bpp); | |
| 984 } | |
| 985 delete pClone; | |
| 986 return NULL; | |
| 987 } | |
| 988 if (pal_8bpp) { | |
| 989 pClone->CopyPalette(pal_8bpp); | |
| 990 FX_Free(pal_8bpp); | |
| 991 pal_8bpp = NULL; | |
| 992 } | |
| 993 return pClone; | |
| 994 } | |
| 995 FX_BOOL CFX_DIBitmap::ConvertFormat(FXDIB_Format dest_format, void* pIccTransfor
m) | |
| 996 { | |
| 997 FXDIB_Format src_format = GetFormat(); | |
| 998 if (dest_format == src_format && pIccTransform == NULL) { | |
| 999 return TRUE; | |
| 1000 } | |
| 1001 if (dest_format == FXDIB_8bppMask && src_format == FXDIB_8bppRgb && m_pPalet
te == NULL) { | |
| 1002 m_AlphaFlag = 1; | |
| 1003 return TRUE; | |
| 1004 } | |
| 1005 if (dest_format == FXDIB_Argb && src_format == FXDIB_Rgb32 && pIccTransform
== NULL) { | |
| 1006 m_AlphaFlag = 2; | |
| 1007 for (int row = 0; row < m_Height; row ++) { | |
| 1008 FX_LPBYTE scanline = m_pBuffer + row * m_Pitch + 3; | |
| 1009 for (int col = 0; col < m_Width; col ++) { | |
| 1010 *scanline = 0xff; | |
| 1011 scanline += 4; | |
| 1012 } | |
| 1013 } | |
| 1014 return TRUE; | |
| 1015 } | |
| 1016 int dest_bpp = dest_format & 0xff; | |
| 1017 int dest_pitch = (dest_bpp * m_Width + 31) / 32 * 4; | |
| 1018 FX_LPBYTE dest_buf = FX_AllocNL(FX_BYTE, dest_pitch * m_Height + 4); | |
| 1019 if (dest_buf == NULL) { | |
| 1020 return FALSE; | |
| 1021 } | |
| 1022 CFX_DIBitmap* pAlphaMask = NULL; | |
| 1023 if (dest_format == FXDIB_Argb) { | |
| 1024 FXSYS_memset8(dest_buf, 0xff, dest_pitch * m_Height + 4); | |
| 1025 if (m_pAlphaMask) { | |
| 1026 for (int row = 0; row < m_Height; row ++) { | |
| 1027 FX_LPBYTE pDstScanline = dest_buf + row * dest_pitch + 3; | |
| 1028 FX_LPCBYTE pSrcScanline = m_pAlphaMask->GetScanline(row); | |
| 1029 for (int col = 0; col < m_Width; col ++) { | |
| 1030 *pDstScanline = *pSrcScanline++; | |
| 1031 pDstScanline += 4; | |
| 1032 } | |
| 1033 } | |
| 1034 } | |
| 1035 } else if (dest_format & 0x0200) { | |
| 1036 if (src_format == FXDIB_Argb) { | |
| 1037 pAlphaMask = GetAlphaMask(); | |
| 1038 if (pAlphaMask == NULL) { | |
| 1039 FX_Free(dest_buf); | |
| 1040 return FALSE; | |
| 1041 } | |
| 1042 } else { | |
| 1043 if (m_pAlphaMask == NULL) { | |
| 1044 if (!BuildAlphaMask()) { | |
| 1045 FX_Free(dest_buf); | |
| 1046 return FALSE; | |
| 1047 } | |
| 1048 pAlphaMask = m_pAlphaMask; | |
| 1049 m_pAlphaMask = NULL; | |
| 1050 } else { | |
| 1051 pAlphaMask = m_pAlphaMask; | |
| 1052 } | |
| 1053 } | |
| 1054 } | |
| 1055 FX_BOOL ret = FALSE; | |
| 1056 FX_DWORD* pal_8bpp = NULL; | |
| 1057 ret = ConvertBuffer(dest_format, dest_buf, dest_pitch, m_Width, m_Height, th
is, 0, 0, pal_8bpp, pIccTransform); | |
| 1058 if (!ret) { | |
| 1059 if (pal_8bpp) { | |
| 1060 FX_Free(pal_8bpp); | |
| 1061 } | |
| 1062 if (pAlphaMask != m_pAlphaMask) { | |
| 1063 delete pAlphaMask; | |
| 1064 } | |
| 1065 if (dest_buf) { | |
| 1066 FX_Free(dest_buf); | |
| 1067 } | |
| 1068 return FALSE; | |
| 1069 } | |
| 1070 if (m_pAlphaMask && pAlphaMask != m_pAlphaMask) { | |
| 1071 delete m_pAlphaMask; | |
| 1072 } | |
| 1073 m_pAlphaMask = pAlphaMask; | |
| 1074 if (m_pPalette) { | |
| 1075 FX_Free(m_pPalette); | |
| 1076 } | |
| 1077 m_pPalette = pal_8bpp; | |
| 1078 if (!m_bExtBuf) { | |
| 1079 FX_Free(m_pBuffer); | |
| 1080 } | |
| 1081 m_bExtBuf = FALSE; | |
| 1082 m_pBuffer = dest_buf; | |
| 1083 m_bpp = (FX_BYTE)dest_format; | |
| 1084 m_AlphaFlag = (FX_BYTE)(dest_format >> 8); | |
| 1085 m_Pitch = dest_pitch; | |
| 1086 return TRUE; | |
| 1087 } | |
| OLD | NEW |