mirror of
https://github.com/defold/extension-camera
synced 2025-06-27 18:37:43 +02:00
Compare commits
No commits in common. "master" and "2.1.0" have entirely different histories.
@ -1,10 +1,18 @@
|
|||||||
name: "Camera"
|
name: "Camera"
|
||||||
|
|
||||||
platforms:
|
platforms:
|
||||||
osx:
|
x86_64-osx:
|
||||||
|
context:
|
||||||
|
frameworks: ["AVFoundation", "CoreMedia"]
|
||||||
|
|
||||||
|
x86-osx:
|
||||||
context:
|
context:
|
||||||
frameworks: ["AVFoundation", "CoreMedia"]
|
frameworks: ["AVFoundation", "CoreMedia"]
|
||||||
|
|
||||||
ios:
|
arm64-ios:
|
||||||
|
context:
|
||||||
|
frameworks: ["AVFoundation", "CoreMedia", "UIKit"]
|
||||||
|
|
||||||
|
armv7-ios:
|
||||||
context:
|
context:
|
||||||
frameworks: ["AVFoundation", "CoreMedia", "UIKit"]
|
frameworks: ["AVFoundation", "CoreMedia", "UIKit"]
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'androidx.core:core:1.2.0'
|
compile 'androidx.core:core:1.2.0'
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class AndroidCamera extends Fragment
|
|||||||
private boolean newFrame;
|
private boolean newFrame;
|
||||||
private int position;
|
private int position;
|
||||||
private int quality;
|
private int quality;
|
||||||
private Camera.Size previewSize;
|
private Camera.Size size;
|
||||||
|
|
||||||
private static Context context;
|
private static Context context;
|
||||||
|
|
||||||
@ -132,43 +132,26 @@ public class AndroidCamera extends Fragment
|
|||||||
|
|
||||||
Camera.Parameters params = camera.getParameters();
|
Camera.Parameters params = camera.getParameters();
|
||||||
|
|
||||||
List<Camera.Size> previewSizes = params.getSupportedPreviewSizes();
|
List<Camera.Size> sizes = params.getSupportedPreviewSizes();
|
||||||
List<String> focusModes = params.getSupportedFocusModes();
|
|
||||||
List<Camera.Size> pictureSizes = params.getSupportedPictureSizes();
|
|
||||||
List<Integer> supportedFormats = params.getSupportedPictureFormats();
|
|
||||||
|
|
||||||
Camera.Size pictureSize;
|
|
||||||
switch(this.quality)
|
switch(this.quality)
|
||||||
{
|
{
|
||||||
case CAPTURE_QUALITY_HIGH:
|
case CAPTURE_QUALITY_HIGH:
|
||||||
this.previewSize = previewSizes.get(previewSizes.size() - 1);
|
this.size = sizes.get(sizes.size() - 1);
|
||||||
pictureSize = pictureSizes.get(previewSizes.size() - 1);
|
|
||||||
break;
|
break;
|
||||||
case CAPTURE_QUALITY_LOW:
|
case CAPTURE_QUALITY_LOW:
|
||||||
this.previewSize = previewSizes.get(0);
|
this.size = sizes.get(0);
|
||||||
pictureSize = pictureSizes.get(0);
|
|
||||||
break;
|
break;
|
||||||
case CAPTURE_QUALITY_MEDIUM:
|
case CAPTURE_QUALITY_MEDIUM:
|
||||||
default:
|
default:
|
||||||
this.previewSize = previewSizes.get((int)Math.ceil(previewSizes.size() / 2));
|
this.size = sizes.get((int)Math.ceil(sizes.size() / 2));
|
||||||
pictureSize = pictureSizes.get((int)Math.ceil(previewSizes.size() / 2));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
|
params.setPreviewSize(this.size.width, this.size.height);
|
||||||
{
|
params.setPictureSize(this.size.width, this.size.height);
|
||||||
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
|
params.setPictureFormat(PixelFormat.JPEG);
|
||||||
}
|
params.setJpegQuality(90);
|
||||||
|
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
|
||||||
params.setPreviewSize(this.previewSize.width, this.previewSize.height);
|
|
||||||
params.setPictureSize(pictureSize.width, pictureSize.height);
|
|
||||||
|
|
||||||
if (supportedFormats.contains(PixelFormat.JPEG))
|
|
||||||
{
|
|
||||||
params.setPictureFormat(PixelFormat.JPEG);
|
|
||||||
params.setJpegQuality(90);
|
|
||||||
}
|
|
||||||
|
|
||||||
camera.setParameters(params);
|
camera.setParameters(params);
|
||||||
|
|
||||||
final Activity activity = (Activity)context;
|
final Activity activity = (Activity)context;
|
||||||
@ -183,7 +166,7 @@ public class AndroidCamera extends Fragment
|
|||||||
if(rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270)
|
if(rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270)
|
||||||
flip = true;
|
flip = true;
|
||||||
|
|
||||||
int[] pixels = convertYUV420_NV21toARGB8888(data, AndroidCamera.this.previewSize.width, AndroidCamera.this.previewSize.height, flip);
|
int[] pixels = convertYUV420_NV21toARGB8888(data, AndroidCamera.this.size.width, AndroidCamera.this.size.height, flip);
|
||||||
frameUpdate(pixels);
|
frameUpdate(pixels);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -196,7 +179,7 @@ public class AndroidCamera extends Fragment
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
captureStarted(this.previewSize.width, this.previewSize.height);
|
captureStarted(this.size.width, this.size.height);
|
||||||
camera.startPreview();
|
camera.startPreview();
|
||||||
queueMessage(CAMERA_STARTED);
|
queueMessage(CAMERA_STARTED);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#define MODULE_NAME "camera"
|
#define MODULE_NAME "camera"
|
||||||
|
|
||||||
// Defold SDK
|
// Defold SDK
|
||||||
|
#define DLIB_LOG_DOMAIN LIB_NAME
|
||||||
#include <dmsdk/sdk.h>
|
#include <dmsdk/sdk.h>
|
||||||
|
|
||||||
#if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_OSX) || defined(DM_PLATFORM_ANDROID)
|
#if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_OSX) || defined(DM_PLATFORM_ANDROID)
|
||||||
@ -70,7 +71,7 @@ static void Camera_ProcessQueue()
|
|||||||
if (message == CAMERA_STARTED)
|
if (message == CAMERA_STARTED)
|
||||||
{
|
{
|
||||||
// Increase ref count
|
// Increase ref count
|
||||||
dmScript::LuaHBuffer luabuffer(g_DefoldCamera.m_VideoBuffer, dmScript::OWNER_C);
|
dmScript::LuaHBuffer luabuffer = {g_DefoldCamera.m_VideoBuffer, false};
|
||||||
dmScript::PushBuffer(L, luabuffer);
|
dmScript::PushBuffer(L, luabuffer);
|
||||||
g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
|
g_DefoldCamera.m_VideoBufferLuaRef = dmScript::Ref(L, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,37 @@ https://github.com/defold/extension-camera/archive/master.zip
|
|||||||
We recommend using a link to a zip file of a [specific release](https://github.com/defold/extension-camera/releases).
|
We recommend using a link to a zip file of a [specific release](https://github.com/defold/extension-camera/releases).
|
||||||
|
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
The extension can be configured by adding the following fields to game.project:
|
||||||
|
|
||||||
|
```
|
||||||
|
[adinfo]
|
||||||
|
tracking_usage_description = We would like to show you relevant ads.
|
||||||
|
register_for_attribution = 1
|
||||||
|
```
|
||||||
|
|
||||||
|
### tracking_usage_description
|
||||||
|
|
||||||
|
Before requesting advertising info and status on iOS 14 the application must request user authorization to access app-related data for tracking the user or the device. This is done automatically when `adinfo.get()` is called. The string set in `adinfo.tracking_usage_description` will be shown to the user.
|
||||||
|
|
||||||
|
Apple documentation: https://developer.apple.com/documentation/apptrackingtransparency?language=objc
|
||||||
|
|
||||||
|
### register_for_attribution
|
||||||
|
|
||||||
|
The extension can automatically register the application for ad network attribution using `SkAdNetwork` and the `registerAppForAdNetworkAttribution()` function. Enable this functionality by setting `adinfo.register_for_attribution` to 1 in game.project.
|
||||||
|
|
||||||
|
Apple documentation: https://developer.apple.com/documentation/storekit/skadnetwork
|
||||||
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Refer to the [example project](https://github.com/defold/extension-camera/blob/master/main/main.script).
|
```lua
|
||||||
|
function init(self)
|
||||||
|
adinfo.get(function(self, info)
|
||||||
|
print(info.ad_ident, info.ad_tracking_enabled)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
@ -34,4 +61,7 @@ tccutil reset Camera
|
|||||||
|
|
||||||
## Source code
|
## Source code
|
||||||
|
|
||||||
The source code is available on [GitHub](https://github.com/defold/extension-camera)
|
The source code is available on [GitHub](https://github.com/defold/extension-adinfo)
|
||||||
|
|
||||||
|
|
||||||
|
## API reference
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
font: "/builtins/fonts/vera_mo_bd.ttf"
|
|
||||||
material: "/builtins/fonts/font-df.material"
|
|
||||||
size: 14
|
|
||||||
antialias: 1
|
|
||||||
alpha: 1.0
|
|
||||||
shadow_alpha: 0.0
|
|
||||||
shadow_blur: 0
|
|
||||||
output_format: TYPE_DISTANCE_FIELD
|
|
@ -16,19 +16,14 @@ embedded_instances {
|
|||||||
" z: 0.0\n"
|
" z: 0.0\n"
|
||||||
" w: 1.0\n"
|
" w: 1.0\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" property_decls {\n"
|
|
||||||
" }\n"
|
|
||||||
"}\n"
|
"}\n"
|
||||||
"embedded_components {\n"
|
"embedded_components {\n"
|
||||||
" id: \"sprite\"\n"
|
" id: \"sprite\"\n"
|
||||||
" type: \"sprite\"\n"
|
" type: \"sprite\"\n"
|
||||||
" data: \"default_animation: \\\"logo\\\"\\n"
|
" data: \"tile_set: \\\"/main/camera.atlas\\\"\\n"
|
||||||
|
"default_animation: \\\"logo\\\"\\n"
|
||||||
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
|
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
|
||||||
"blend_mode: BLEND_MODE_ALPHA\\n"
|
"blend_mode: BLEND_MODE_ALPHA\\n"
|
||||||
"textures {\\n"
|
|
||||||
" sampler: \\\"texture_sampler\\\"\\n"
|
|
||||||
" texture: \\\"/main/camera.atlas\\\"\\n"
|
|
||||||
"}\\n"
|
|
||||||
"\"\n"
|
"\"\n"
|
||||||
" position {\n"
|
" position {\n"
|
||||||
" x: 0.0\n"
|
" x: 0.0\n"
|
||||||
@ -65,13 +60,10 @@ embedded_instances {
|
|||||||
data: "embedded_components {\n"
|
data: "embedded_components {\n"
|
||||||
" id: \"sprite\"\n"
|
" id: \"sprite\"\n"
|
||||||
" type: \"sprite\"\n"
|
" type: \"sprite\"\n"
|
||||||
" data: \"default_animation: \\\"logo\\\"\\n"
|
" data: \"tile_set: \\\"/main/logo.atlas\\\"\\n"
|
||||||
|
"default_animation: \\\"logo\\\"\\n"
|
||||||
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
|
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
|
||||||
"blend_mode: BLEND_MODE_ALPHA\\n"
|
"blend_mode: BLEND_MODE_ALPHA\\n"
|
||||||
"textures {\\n"
|
|
||||||
" sampler: \\\"texture_sampler\\\"\\n"
|
|
||||||
" texture: \\\"/main/logo.atlas\\\"\\n"
|
|
||||||
"}\\n"
|
|
||||||
"\"\n"
|
"\"\n"
|
||||||
" position {\n"
|
" position {\n"
|
||||||
" x: 0.0\n"
|
" x: 0.0\n"
|
||||||
@ -94,6 +86,12 @@ embedded_instances {
|
|||||||
" z: 0.0\\n"
|
" z: 0.0\\n"
|
||||||
" w: 0.0\\n"
|
" w: 0.0\\n"
|
||||||
"}\\n"
|
"}\\n"
|
||||||
|
"scale {\\n"
|
||||||
|
" x: 1.0\\n"
|
||||||
|
" y: 1.0\\n"
|
||||||
|
" z: 1.0\\n"
|
||||||
|
" w: 0.0\\n"
|
||||||
|
"}\\n"
|
||||||
"color {\\n"
|
"color {\\n"
|
||||||
" x: 1.0\\n"
|
" x: 1.0\\n"
|
||||||
" y: 1.0\\n"
|
" y: 1.0\\n"
|
||||||
@ -118,8 +116,8 @@ embedded_instances {
|
|||||||
"blend_mode: BLEND_MODE_ALPHA\\n"
|
"blend_mode: BLEND_MODE_ALPHA\\n"
|
||||||
"line_break: false\\n"
|
"line_break: false\\n"
|
||||||
"text: \\\"Space/Touch to toggle capture\\\"\\n"
|
"text: \\\"Space/Touch to toggle capture\\\"\\n"
|
||||||
"font: \\\"/main/default.font\\\"\\n"
|
"font: \\\"/builtins/fonts/system_font.font\\\"\\n"
|
||||||
"material: \\\"/builtins/fonts/label-df.material\\\"\\n"
|
"material: \\\"/builtins/fonts/label.material\\\"\\n"
|
||||||
"\"\n"
|
"\"\n"
|
||||||
" position {\n"
|
" position {\n"
|
||||||
" x: 90.0\n"
|
" x: 90.0\n"
|
||||||
@ -142,6 +140,12 @@ embedded_instances {
|
|||||||
" z: 0.0\\n"
|
" z: 0.0\\n"
|
||||||
" w: 0.0\\n"
|
" w: 0.0\\n"
|
||||||
"}\\n"
|
"}\\n"
|
||||||
|
"scale {\\n"
|
||||||
|
" x: 1.0\\n"
|
||||||
|
" y: 1.0\\n"
|
||||||
|
" z: 1.0\\n"
|
||||||
|
" w: 0.0\\n"
|
||||||
|
"}\\n"
|
||||||
"color {\\n"
|
"color {\\n"
|
||||||
" x: 1.0\\n"
|
" x: 1.0\\n"
|
||||||
" y: 1.0\\n"
|
" y: 1.0\\n"
|
||||||
@ -168,8 +172,8 @@ embedded_instances {
|
|||||||
"text: \\\"label\\\\n"
|
"text: \\\"label\\\\n"
|
||||||
"\\\"\\n"
|
"\\\"\\n"
|
||||||
" \\\"\\\"\\n"
|
" \\\"\\\"\\n"
|
||||||
"font: \\\"/main/default.font\\\"\\n"
|
"font: \\\"/builtins/fonts/system_font.font\\\"\\n"
|
||||||
"material: \\\"/builtins/fonts/label-df.material\\\"\\n"
|
"material: \\\"/builtins/fonts/label.material\\\"\\n"
|
||||||
"\"\n"
|
"\"\n"
|
||||||
" position {\n"
|
" position {\n"
|
||||||
" x: 90.0\n"
|
" x: 90.0\n"
|
||||||
|
@ -3,6 +3,7 @@ local function stop_capture(self)
|
|||||||
if self.cameraframe == nil then
|
if self.cameraframe == nil then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.cameraframe = nil
|
self.cameraframe = nil
|
||||||
camera.stop_capture()
|
camera.stop_capture()
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ local function start_capture(self)
|
|||||||
type = camera.CAMERA_TYPE_BACK
|
type = camera.CAMERA_TYPE_BACK
|
||||||
quality = camera.CAPTURE_QUALITY_MEDIUM
|
quality = camera.CAPTURE_QUALITY_MEDIUM
|
||||||
end
|
end
|
||||||
|
|
||||||
camera.start_capture(type, quality, function(self, status)
|
camera.start_capture(type, quality, function(self, status)
|
||||||
if status == camera.CAMERA_STARTED then
|
if status == camera.CAMERA_STARTED then
|
||||||
self.cameraframe = camera.get_frame()
|
self.cameraframe = camera.get_frame()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user