Fractal Image Compression of BMPs lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2023-11-01 09:45 Just converted a Fractal Image Compression of BMPs to play around with. I love fractals and found this Fractal Compression Source in Delphi that I converted to Lazarus. Has a free licence. Made by some Russian Dude on Github. Don't yet fully understand it but thought I would share with everyone here. ---------------------------------------------------------------------- Dzandaa · 2023-11-01 09:58 Hi Great job!!! I know that technique of compression. B-> ---------------------------------------------------------------------- Josh · 2023-11-01 11:16 Hi Nice Please respect the original author, and leave the original authors copyright info in. https://github.com/loginov- dmitry/loginovprojects/tree/master/someprojects/fractalcompression Code: [Select]{ Copyright (c) 2006-2009, Loginov Dmitry Sergeevich All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this    list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice,    this list of conditions and the following disclaimer in the documentation    and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } { ******************************************************************** ******* } {                                                                           } {                                                                           } {                                                                           } { Ìîäóëü FractalCompression - ñîäåðæèò êëàññ TFractal, èñïîëüçóåìûé äëÿ       } { ôðàêòàëüíîãî ñæàòèÿ / ðàñïàêîâêè èçîáðàæåíèé                              } { (c) 2006-2009 Ëîãèíîâ Äìèòðèé Ñåðãååâè÷                                   } { Àäðåñ ñàéòà: http://matrix.kladovka.net.ru/                               } { e-mail: loginov_d@inbox.ru                                                } { Ïîñëåäíåå èçìåíåíèå: 07.06.2009                                           } {                                                                           } { ******************************************************************** ******* } { Èçìåíåíèÿ è èñïðàâëåíèÿ:   * 07.06.2009 *   - âìåñòî ìàññèâîâ PByteArray èñïîëüçóþòñÿ îáúåêòû èç ìîäóëÿ Matrix32.     Çà ñ÷åò ýòîãî êîä ñòàë ïðîùå äëÿ ïîíèìàíèÿ, åãî ïðîùå ìîäèôèöèðîâàòü.   - èçìåíåíà ñòðóêòóðà TIfsRec (ñåé÷àñ íàçûâàåòñÿ TMemIfsRec).     Ðàíüøå áûëî Betta: Byte, ñòàëî Betta: ShortInt     âíåñåíû ñîîòâåòñòâóþùèå èñïðàâëåíèÿ. Ìîäóëü íåêîððåêòíî ðàáîòàë ñ ÷åðíî-     áåëûìè èçîáðàæåíèÿìè - îíè ñòàíîâèëèñü ñëèøêîì áëåäíûìè äàæå ïðè ìèíèìàëüíîì     ðàçìåðå ðåãèîíà. Ðàíüøå íà ôîòîãðàôè÷åñêèõ èçîáðàæåíèÿõ ÷àñòî ïîÿâëÿëèñü     áåëûå ïÿòíà íåîáúÿñíèìîé ïðèðîäû. Òåïåðü îíè íå ïîÿâëÿþòñÿ. Äëÿ òîãî, ÷òîáû     ïîìåñòèòü ðàçíèöó ÿðêîñòè ìåæäó îáëàñòÿìè â ïåðåìåííóþ ShortInt îíà     ïðåäâàðèòåëüíî äåëèòñÿ íà 2. Ïðè äåêîìïðåññèè îíà óìíîæàåòñÿ íà 2.   - èñïðàâëåíà îøèáêà, ñâÿçàííàÿ ñ íåêîððåêòíîé îðãàíèçàöèåé öèêëà ïî îáëàñòÿì     äîìåííîãî èçîáðàæåíèÿ. Ìîãëà ïðîèçîéòè îøèáêà äîñòóïà ê ïàìÿòè, èíîãäà     ïðîèñõîäèëî íåïðàâèëüíîå âîññòàíîâëåíèå èçîáðàæåíèÿ ïî äîìåíàì ñ ïîìîùüþ     ôóíêöèè BuildImageWithDomains(). Îøèáêó óäàëîñü îáðàðóæèòü áëàãîäàðÿ     èñïîëüçîâàíèþ ñèñòåìû Matrix32 ñ ïîäêëþ÷åíèåì îïöèè MatrixCheckRange.   - èçìåíåíà ñòðóêòóðà TIfsHeader. Òåïåðü ïîëå FileExt ñîñòîèò èç 4õ ñèìâîëîâ.      íåì äîëæíî áûòü çàïèñàíî "2IFS".   - äàííûå õðàíÿòñÿ â IFS-ôàéëå â êîìïàêòíîì ôîðìàòå. Ñòðóêòóðà TFileIfsRec     çàíèìàåò òåïåðü 5 áàéò (ðàíüøå áûëî 6). Îñîáûì îáðàçîì îáðàáàòûâàåòñÿ     ñèòóàöèÿ, êîãäà äðóã çà äðóãîì èäóì íåñêîëüêî ðåãèîíîâ ñ îäèíàêîâûì îïèñàíèåì.     Ñìîòðèòå ðåàëèçàöèþ ôóíêöèé SaveToFile() è LoadFromFile().   * 11.06.2009 *   - â ìåòîäû Decompress è BuildImageWithDomains äîáàâëåíà äîïîëíèòåëüíàÿ ïðîâåðêà,     îãðàíè÷èâàþùàÿ ÿðêîñòü çíà÷åíèÿìè îò 0 äî 255. Èçîáðàæåíèÿ ïîëó÷àþòñÿ çàìåòíî     áîëåå ÷èñòûìè. Íå âîçíèêàþò áåëûå èëè ÷åðíûå êðàïèíêè, êîòîðûå ðàíüøå ðåçàëè ãëàç. } ---------------------------------------------------------------------- domasz · 2023-11-01 11:29 I love these comments A few things to do: 1) translate comments to English, you can use Google Translate or ChatGPT 2) add the copyright info to the header 3) consider putting it on Github ---------------------------------------------------------------------- Josh · 2023-11-01 16:53 added in copyright info, added a language define for english, this allows errors to be in english,if not defined then defaults to russian. google translated comments and errors. i have not thoroughly tested. ---------------------------------------------------------------------- domasz · 2023-11-01 17:09 Good job! ---------------------------------------------------------------------- Boleeman · 2023-11-02 05:31 I downloaded from another Github repository. Also tried Google Translator but some text was still garbled. Is there something extra that needs to be done to translate? Ðàçëè÷èå â ÿðêîñòè, Íîìåð ïðåîáðàçîâàíèÿ   was translated as Ðàçëè÷èå â ÿðêîñòè, Íîìåð ïðåîáðàçîâàíèÿ Actually now I see autodetect in Google Translate selected Corsican ---------------------------------------------------------------------- Awkward · 2023-11-02 05:57 i guess, that garbled text is russian just with wrong codepage. Like 1251 (or 866) in 1252 encoding. ---------------------------------------------------------------------- wp · 2023-11-02 09:39 Load the ORIGINAL pas files downloaded from the github site into the Lazarus IDE. Without doing anything else, load the first .pas file. Right-click on the text in the editor. Select "File Settings" > "Encoding" > "CP1251" > "Reopen with another encoding". Then right- click again and repeat "File Settings" > "Encoding", but now switch to "UTF8", and "Reopen with another encoding". Repeat with the other .pas files. Now you can copy the kyrillic texts into google-translate for English translation. Select Russian as the source language, it works in my test. ---------------------------------------------------------------------- Boleeman · 2023-11-03 07:07 Thanks for the tip WP. Still cannot translate at line 93 in UMain         ImPreview.Canvas.TextOut(5, 10, 'Îøèáêà'); Also looking for the Titlebar Caption of the popups when clicking View result button and Fully Button and Unpack/View Button? (as shown in attachment) ---------------------------------------------------------------------- wp · 2023-11-03 13:24 Quote from: Boleeman on November 03, 2023, 08:07:18 amStill cannot translate at line 93 in UMain         ImPreview.Canvas.TextOut(5, 10, 'Îøèáêà'); Either you did not process UMain in the same way, or its encoding has been destroyed in previous experiments. Restore the original file and retry. Quote from: Boleeman on November 03, 2023, 08:07:18 amAlso looking for the Titlebar Caption of the popups when clicking View result button and Fully Button and Unpack/View Button? (as shown in attachment) There are lots of Russian texts also in the lfm files. But since the lfm contains non-ASCII stringw in an encoded way (each byte converted to an ASCII hex string), the google translator cannot process it in the normal way. A possibility is to select the controls with Russian captions and hints, copy their caption/hint from the object inspector to the clipboard, paste it into google-translate, translate it, copy the translation to the clipboard again and finally pasting it into the caption. It's a bit monotonous, mechanical work, but not difficult. However, you can also find in the attachment my translation of the entire project to English (well - not completely: I skipped the 11,000 lines of the Matrix32 unit because google-translate only handles 5000 character per request). ---------------------------------------------------------------------- Boleeman · 2023-11-03 17:23 Now I get an error saying ShowImage.lfm is not there U_ShowImage.pas(59,1) Error: Can't open resource file "C:\Files2\Lazarus\Graphics\Fractal Comp Laz\Fractal Compression\U_ShowImage.lfm" ---------------------------------------------------------------------- wp · 2023-11-03 17:33 Sorry - I had both delphi and lazarus files in the same dir and my click selected the delphi file rather than the lazarus file. The new attachment should be correct. ---------------------------------------------------------------------- Boleeman · 2023-11-03 19:40 No luck WP still getting this error: Compile Project, Target: FractComp.exe: Exit code 1, Errors: 1 U_Main.pas(246,1) Error: Can't open resource file "C:\Files2\Lazarus\Graphics\Fractal Comp Laz\FractComp\U_Main.lfm" ---------------------------------------------------------------------- tetrastes · 2023-11-03 19:47 Just in case Quote from: Boleeman on November 03, 2023, 08:07:18 amStill cannot translate at line 93 in UMain         ImPreview.Canvas.TextOut(5, 10, 'Îøèáêà'); This is 'Ошибка' in CP1251 -> 'Error' Quote from: Boleeman on November 03, 2023, 08:07:18 amAlso looking for the Titlebar Caption of the popups when clicking View result button and Fully Button and Unpack/View Button? (as shown in attachment) This is in U_ShowImage.lfm: object fmShowImage: TfmShowImage   Left = 192   Top = 114   BorderStyle = bsDialog   Caption = 'Просмотр изображения' -> 'View image'   ... ---------------------------------------------------------------------- wp · 2023-11-03 21:01 Quote from: Boleeman on November 03, 2023, 08:40:37 pmNo luck WP still getting this error: Compile Project, Target: FractComp.exe: Exit code 1, Errors: 1 U_Main.pas(246,1) Error: Can't open resource file "C:\Files2\Lazarus\Graphics\Fractal Comp Laz\FractComp\U_Main.lfm" Updated again... ---------------------------------------------------------------------- Boleeman · 2023-11-04 09:11 Thanks WP this one works OK.