-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[STB] Added STBImageResize2; rewriting STBVorbis
- Loading branch information
Showing
8 changed files
with
674 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
modules/overrungl.stb/src/main/java/overrungl/stb/STBIRInputCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Overrun Organization | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
|
||
package overrungl.stb; | ||
|
||
import overrun.marshal.Upcall; | ||
import overrungl.NativeType; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
|
||
/** | ||
* INPUT CALLBACK: this callback is used for input scanlines | ||
* <p> | ||
* The input callback is super flexible - it calls you with the input address | ||
* (based on the stride and base pointer), it gives you an optional_output | ||
* pointer that you can fill, or you can just return your own pointer into | ||
* your own data. | ||
* <p> | ||
* You can also do conversion from non-supported data types if necessary - in | ||
* this case, you ignore the input_ptr and just use the x and y parameters to | ||
* calculate your own input_ptr based on the size of each non-supported pixel. | ||
* (Something like the third example below.) | ||
* <p> | ||
* You can also install just an input or just an output callback by setting the | ||
* callback that you don't want to zero. | ||
* <p> | ||
* First example, progress: (getting a callback that you can monitor the progress): | ||
* <pre>{@code void const * my_callback( void * optional_output, void const * input_ptr, int num_pixels, int x, int y, void * context ) | ||
* { | ||
* percentage_done = y / input_height; | ||
* return input_ptr; // use buffer from call | ||
* }}</pre> | ||
* <p> | ||
* Next example, copying: (copy from some other buffer or stream): | ||
* <pre>{@code void const * my_callback( void * optional_output, void const * input_ptr, int num_pixels, int x, int y, void * context ) | ||
* { | ||
* CopyOrStreamData( optional_output, other_data_src, num_pixels * pixel_width_in_bytes ); | ||
* return optional_output; // return the optional buffer that we filled | ||
* }}</pre> | ||
* <p> | ||
* Third example, input another buffer without copying: (zero-copy from other buffer): | ||
* <pre>{@code void const * my_callback( void * optional_output, void const * input_ptr, int num_pixels, int x, int y, void * context ) | ||
* { | ||
* void * pixels = ( (char*) other_image_base ) + ( y * other_image_stride ) + ( x * other_pixel_width_in_bytes ); | ||
* return pixels; // return pointer to your data without copying | ||
* }}</pre> | ||
* | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface STBIRInputCallback extends Upcall { | ||
/** | ||
* the type | ||
*/ | ||
Type<STBIRInputCallback> TYPE = Upcall.type(); | ||
|
||
@NativeType("void const *") | ||
@Stub | ||
MemorySegment invoke(@NativeType("void *") MemorySegment optional_output, @NativeType("void const *") MemorySegment input_ptr, int num_pixels, int x, int y, @NativeType("void *") MemorySegment context); | ||
|
||
@Override | ||
default MemorySegment stub(Arena arena) { | ||
return TYPE.of(arena, this); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
modules/overrungl.stb/src/main/java/overrungl/stb/STBIRKernelCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Overrun Organization | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
|
||
package overrungl.stb; | ||
|
||
import overrun.marshal.Upcall; | ||
import overrungl.NativeType; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
|
||
/** | ||
* callbacks for user installed filters | ||
* | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface STBIRKernelCallback extends Upcall { | ||
/** | ||
* the type | ||
*/ | ||
Type<STBIRKernelCallback> TYPE = Upcall.type(); | ||
|
||
// centered at zero | ||
@Stub | ||
float invoke(float x, float scale, @NativeType("void *") MemorySegment user_data); | ||
|
||
@Override | ||
default MemorySegment stub(Arena arena) { | ||
return TYPE.of(arena, this); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
modules/overrungl.stb/src/main/java/overrungl/stb/STBIROutputCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Overrun Organization | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
|
||
package overrungl.stb; | ||
|
||
import overrun.marshal.Upcall; | ||
import overrungl.NativeType; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
|
||
/** | ||
* OUTPUT CALLBACK: this callback is used for output scanlines | ||
* <p> | ||
* The output callback is considerably simpler - it just calls you so that you can dump | ||
* out each scanline. You could even directly copy out to disk if you have a simple format | ||
* like TGA or BMP. You can also convert to other output types here if you want. | ||
* <p> | ||
* Simple example: | ||
* <pre>{@code void const * my_output( void * output_ptr, int num_pixels, int y, void * context ) | ||
* { | ||
* percentage_done = y / output_height; | ||
* fwrite( output_ptr, pixel_width_in_bytes, num_pixels, output_file ); | ||
* }}</pre> | ||
* | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface STBIROutputCallback extends Upcall { | ||
/** | ||
* the type | ||
*/ | ||
Type<STBIROutputCallback> TYPE = Upcall.type(); | ||
|
||
@Stub | ||
void invoke(@NativeType("void const *") MemorySegment output_ptr, int num_pixels, int y, @NativeType("void *") MemorySegment context); | ||
|
||
@Override | ||
default MemorySegment stub(Arena arena) { | ||
return TYPE.of(arena, this); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
modules/overrungl.stb/src/main/java/overrungl/stb/STBIRRESIZE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Overrun Organization | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
|
||
package overrungl.stb; | ||
|
||
import overrun.marshal.struct.Struct; | ||
|
||
import java.lang.foreign.*; | ||
|
||
import static java.lang.foreign.ValueLayout.*; | ||
|
||
/** | ||
* {@code STBIR_RESIZE} | ||
* | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
public final class STBIRRESIZE extends Struct { | ||
/** | ||
* Layout | ||
*/ | ||
public static final StructLayout LAYOUT = MemoryLayout.structLayout( | ||
ADDRESS.withName("user_data"), | ||
ADDRESS.withName("input_pixels"), | ||
JAVA_INT.withName("input_w"), | ||
JAVA_INT.withName("input_h"), | ||
JAVA_DOUBLE.withName("input_s0"), | ||
JAVA_DOUBLE.withName("input_t0"), | ||
JAVA_DOUBLE.withName("input_s1"), | ||
JAVA_DOUBLE.withName("input_t1"), | ||
ADDRESS.withName("input_cb"), | ||
ADDRESS.withName("output_pixels"), | ||
JAVA_INT.withName("output_w"), | ||
JAVA_INT.withName("output_h"), | ||
JAVA_INT.withName("output_subx"), | ||
JAVA_INT.withName("output_suby"), | ||
JAVA_INT.withName("output_subw"), | ||
JAVA_INT.withName("output_subh"), | ||
ADDRESS.withName("output_cb"), | ||
JAVA_INT.withName("input_stride_in_bytes"), | ||
JAVA_INT.withName("output_stride_in_bytes"), | ||
JAVA_INT.withName("splits"), | ||
JAVA_INT.withName("fast_alpha"), | ||
JAVA_INT.withName("needs_rebuild"), | ||
JAVA_INT.withName("called_alloc"), | ||
JAVA_INT.withName("input_pixel_layout_public"), | ||
JAVA_INT.withName("output_pixel_layout_public"), | ||
JAVA_INT.withName("input_data_type"), | ||
JAVA_INT.withName("output_data_type"), | ||
JAVA_INT.withName("horizontal_filter"), | ||
JAVA_INT.withName("vertical_filter"), | ||
JAVA_INT.withName("horizontal_edge"), | ||
JAVA_INT.withName("vertical_edge"), | ||
ADDRESS.withName("horizontal_filter_kernel"), | ||
ADDRESS.withName("horizontal_filter_support"), | ||
ADDRESS.withName("vertical_filter_kernel"), | ||
ADDRESS.withName("vertical_filter_support"), | ||
ADDRESS.withName("samplers") | ||
); | ||
|
||
/** | ||
* Creates a struct with the given layout. | ||
* | ||
* @param segment the segment | ||
* @param elementCount the element count | ||
*/ | ||
public STBIRRESIZE(MemorySegment segment, long elementCount) { | ||
super(segment, elementCount, LAYOUT); | ||
} | ||
|
||
/** | ||
* Allocates a struct with the given layout. | ||
* | ||
* @param allocator the allocator | ||
* @param elementCount the element count | ||
*/ | ||
public STBIRRESIZE(SegmentAllocator allocator, long elementCount) { | ||
super(allocator, elementCount, LAYOUT); | ||
} | ||
|
||
/** | ||
* Creates a struct with the given layout. | ||
* | ||
* @param segment the segment | ||
*/ | ||
public STBIRRESIZE(MemorySegment segment) { | ||
super(segment, LAYOUT); | ||
} | ||
|
||
/** | ||
* Allocates a struct with the given layout. | ||
* | ||
* @param allocator the allocator | ||
*/ | ||
public STBIRRESIZE(SegmentAllocator allocator) { | ||
super(allocator, LAYOUT); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
modules/overrungl.stb/src/main/java/overrungl/stb/STBIRSupportCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2024 Overrun Organization | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
*/ | ||
|
||
package overrungl.stb; | ||
|
||
import overrun.marshal.Upcall; | ||
import overrungl.NativeType; | ||
|
||
import java.lang.foreign.Arena; | ||
import java.lang.foreign.MemorySegment; | ||
|
||
/** | ||
* callbacks for user installed filters | ||
* | ||
* @author squid233 | ||
* @since 0.1.0 | ||
*/ | ||
@FunctionalInterface | ||
public interface STBIRSupportCallback extends Upcall { | ||
/** | ||
* the type | ||
*/ | ||
Type<STBIRSupportCallback> TYPE = Upcall.type(); | ||
|
||
// centered at zero | ||
@Stub | ||
float invoke(float scale, @NativeType("void *") MemorySegment user_data); | ||
|
||
@Override | ||
default MemorySegment stub(Arena arena) { | ||
return TYPE.of(arena, this); | ||
} | ||
} |
Oops, something went wrong.