Skip to content

Instantly share code, notes, and snippets.

@kallisti5
Created April 16, 2024 15:28
Show Gist options
  • Save kallisti5/e044abdf7bbee95dedc984cbf7941ece to your computer and use it in GitHub Desktop.
Save kallisti5/e044abdf7bbee95dedc984cbf7941ece to your computer and use it in GitHub Desktop.
diff --git a/src/add-ons/translators/hvif/HVIFTranslator.cpp b/src/add-ons/translators/hvif/HVIFTranslator.cpp
index 78f52a4587..b8bdd87e61 100644
--- a/src/add-ons/translators/hvif/HVIFTranslator.cpp
+++ b/src/add-ons/translators/hvif/HVIFTranslator.cpp
@@ -1,9 +1,10 @@
/*
- * Copyright 2009, Haiku, Inc.
+ * Copyright 2009-2024, Haiku, Inc., All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Michael Lotz, mmlr@mlotz.ch
+ * Alexander von Gluck, alex@terarocket.io
*/
#include "HVIFTranslator.h"
@@ -19,9 +20,13 @@
#include <string.h>
#define HVIF_FORMAT_CODE 'HVIF'
+
#define HVIF_TRANSLATION_QUALITY 1.0
#define HVIF_TRANSLATION_CAPABILITY 1.0
+#define TEXT_IN_QUALITY 0.4
+#define TEXT_IN_CAPABILITY 0.6
+
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "HVIFTranslator"
@@ -46,7 +51,15 @@ static const translation_format sOutputFormats[] = {
0.4,
"image/x-be-bitmap",
"Be Bitmap format (HVIFTranslator)"
- }
+ },
+ {
+ B_TRANSLATOR_TEXT,
+ B_TRANSLATOR_TEXT,
+ TEXT_IN_QUALITY,
+ TEXT_IN_CAPABILITY,
+ "text/plain",
+ "Plain text file"
+ },
};
@@ -93,7 +106,7 @@ HVIFTranslator::DerivedIdentify(BPositionIO *inSource,
translator_info *outInfo, uint32 outType)
{
// TODO: we do the fully work twice!
- if (outType != B_TRANSLATOR_BITMAP)
+ if (outType != B_TRANSLATOR_BITMAP && outType != B_TRANSLATOR_TEXT)
return B_NO_TRANSLATOR;
// filter out invalid sizes
@@ -135,7 +148,7 @@ HVIFTranslator::DerivedTranslate(BPositionIO *inSource,
const translator_info *inInfo, BMessage *ioExtension, uint32 outType,
BPositionIO *outDestination, int32 baseType)
{
- if (outType != B_TRANSLATOR_BITMAP)
+ if (outType != B_TRANSLATOR_BITMAP && outType != B_TRANSLATOR_TEXT)
return B_NO_TRANSLATOR;
// filter out invalid sizes
@@ -152,26 +165,34 @@ HVIFTranslator::DerivedTranslate(BPositionIO *inSource,
return B_NO_TRANSLATOR;
}
- int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE);
- if (renderSize <= 0 || renderSize > 1024)
- renderSize = 64;
-
- BBitmap rendered(BRect(0, 0, renderSize - 1, renderSize - 1),
- B_BITMAP_NO_SERVER_LINK, B_RGBA32);
- if (BIconUtils::GetVectorIcon(buffer, size, &rendered) != B_OK) {
- free(buffer);
- return B_NO_TRANSLATOR;
+ switch (outType) {
+ case B_TRANSLATOR_TEXT:
+ // TODO lol
+ break;
+ case B_TRANSLATOR_BITMAP:
+ int32 renderSize = fSettings->SetGetInt32(HVIF_SETTING_RENDER_SIZE);
+ if (renderSize <= 0 || renderSize > 1024)
+ renderSize = 64;
+
+ BBitmap rendered(BRect(0, 0, renderSize - 1, renderSize - 1),
+ B_BITMAP_NO_SERVER_LINK, B_RGBA32);
+ if (BIconUtils::GetVectorIcon(buffer, size, &rendered) != B_OK) {
+ free(buffer);
+ return B_NO_TRANSLATOR;
+ }
+
+ BBitmapStream stream(&rendered);
+ stream.Seek(0, SEEK_SET);
+ ssize_t read = 0;
+
+ while ((read = stream.Read(buffer, size)) > 0)
+ outDestination->Write(buffer, read);
+
+ BBitmap *dummy = NULL;
+ stream.DetachBitmap(&dummy);
+ break;
}
- BBitmapStream stream(&rendered);
- stream.Seek(0, SEEK_SET);
- ssize_t read = 0;
-
- while ((read = stream.Read(buffer, size)) > 0)
- outDestination->Write(buffer, read);
-
- BBitmap *dummy = NULL;
- stream.DetachBitmap(&dummy);
free(buffer);
return B_OK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment