Skip to content

Commit

Permalink
edit readme, and some cosmetics.
Browse files Browse the repository at this point in the history
  • Loading branch information
chikuzen committed May 28, 2016
1 parent c8f7be5 commit 444ed16
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 31 deletions.
11 changes: 11 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
RawSource26 - reads raw video data files
Author: Oka Motofumi (chikuzen.mo at gmail dot com)
This program is rewriting of RawSource.dll(original author is Ernst Pech)
for avisynth2.6x/Avisynth+.
*/


#ifndef RAWSOURCE_COMMON_H
#define RAWSOURCE_COMMON_H

Expand Down Expand Up @@ -32,6 +42,7 @@ struct rindex {
struct i_struct {
int64_t index;
char type; //Key, Delta, Bigdelta
i_struct() : index(0), type(0) {}
};


Expand Down
42 changes: 26 additions & 16 deletions src/rawsource26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
Author: Oka Motofumi (chikuzen.mo at gmail dot com)
This program is rewriting of RawSource.dll(original author is Pech Ernst)
for avisynth2.6.
This program is rewriting of RawSource.dll(original author is Ernst Pech)
for avisynth2.6x/Avisynth+.
*/


#include <io.h>
#include <fcntl.h>
#include <cinttypes>
Expand Down Expand Up @@ -90,8 +91,8 @@ void RawSource::setProcess(const char* pix_type)
{ pix_type, VideoInfo::CS_UNKNOWN, {0, 0, 0, 0}, 0, nullptr }
};
int i = 0;
while (stricmp(pix_type, pixelformats[i].fmt_name))
i++;
while (stricmp(pix_type, pixelformats[i].fmt_name)) ++i;

validate(pixelformats[i].avs_pix_type == VideoInfo::CS_UNKNOWN,
"Invalid pixel type. Supported: RGB, RGBA, BGR, BGRA, ARGB,"
" ABGR, YV24, I444, YUY2, YUYV, UYVY, YVYU, VYUY, YV16, I422,"
Expand Down Expand Up @@ -126,10 +127,10 @@ RawSource::RawSource (const char *source, const int width, const int height,
int64_t header_offset = 0;
int64_t frame_offset = 0;

if (strlen(a_index) == 0) { //use header if valid else width, height, pixel_type from AVS are used
if (strlen(a_index) == 0) { //use header if valid else width, height, pixel_type from AVS are used
std::vector<char> read_buff(256, 0);
char* data = read_buff.data();
_read(fileHandle, data, read_buff.size()); //read some bytes and test on header
_read(fileHandle, data, read_buff.size()); //read some bytes and test on header
bool ret = parse_y4m(read_buff, vi, header_offset, frame_offset);

if (vi.width > MAX_WIDTH || vi.height > MAX_HEIGHT) {
Expand All @@ -152,18 +153,17 @@ RawSource::RawSource (const char *source, const int width, const int height,

validate(maxframe < 1, "File too small for even one frame.");

index.resize(maxframe + 1);

rawbuf = reinterpret_cast<uint8_t*>(
_aligned_malloc(vi.IsPlanar() ? vi.width * vi.height : framesize, 16));
validate(rawbuf == nullptr, "failed to allocate read buffer.");

//index build using string descriptor
std::vector<rindex> rawindex;
set_rawindex(rawindex, a_index, header_offset, frame_offset, framesize);

//create full index and get number of frames.
index.resize(maxframe + 1);
vi.num_frames = generate_index(index, rawindex, framesize, fileSize);

rawbuf = reinterpret_cast<uint8_t*>(
_aligned_malloc(vi.IsPlanar() ? vi.width * vi.height : framesize, 16));
validate(rawbuf == nullptr, "failed to allocate read buffer.");
}


Expand Down Expand Up @@ -192,7 +192,7 @@ PVideoFrame __stdcall RawSource::GetFrame(int n, ise_t* env)
}


AVSValue __cdecl CreateRawSource(AVSValue args, void* user_data, ise_t* env)
AVSValue __cdecl create_rawsource(AVSValue args, void* user_data, ise_t* env)
{
char buff[128] = {};

Expand Down Expand Up @@ -239,9 +239,18 @@ extern "C" __declspec(dllexport) const char* __stdcall
AvisynthPluginInit3(ise_t* env, const AVS_Linkage* const vectors)
{
AVS_linkage = vectors;
env->AddFunction("RawSource",
"[file]s[width]i[height]i[pixel_type]s[fpsnum]i[fpsden]i[index]s[show]b",
CreateRawSource, 0);

const char* args =
"[file]s"
"[width]i"
"[height]i"
"[pixel_type]s"
"[fpsnum]i"
"[fpsden]i"
"[index]s"
"[show]b";

env->AddFunction("RawSource", args, create_rawsource, nullptr);

if (env->FunctionExists("SetFilterMTMode")) {
static_cast<IScriptEnvironment2*>(
Expand All @@ -250,3 +259,4 @@ AvisynthPluginInit3(ise_t* env, const AVS_Linkage* const vectors)

return "RawSource for AviSynth2.6x/Avisynth+.";
}

36 changes: 23 additions & 13 deletions src/rawsource26.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<html>
<DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>RawSource26</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#BED8CB" text="#000000">
<h1>RawSource26</h1>
<h3>Loading raw video data from files</h3>
<p>for AviSynth 2.6.0 alpha2 or later<br>
</p>
<p>for AviSynth 2.6.0 / Avisynth+ r1576 or greater</p>
<h4>requirements</h4>
<ul>
<li>Windows Vista sp2 or later</li>
<li>avisynth2.6.0 or later / Avisynth+ r1576 or greater</li>
<li>Visual C++ Redistributable for Visual Studio 2015</li>
</ul>
<h4>How to use</h4>
<p><code>RawSource</code> (<var>string &quot;file&quot;, int &quot;width&quot;,
int &quot;height&quot;, string &quot;pixel_type&quot;, int &quot;fpsnum&quot;,
int &quot;fpsden&quot;, string &quot;index&quot;, bool &quot;show&quot;</var>)<br>
Expand Down Expand Up @@ -42,7 +49,7 @@ <h3>Loading raw video data from files</h3>
&nbsp;D = position by adding current delta is used<br>
&nbsp;B = position by adding currend big_delta is used</p>
<h4><b>Some simple examples:</b></h4>
<table width="75%" border="1">
<table border="1">
<tr>
<td>
<pre>RawSource(&quot;d:\yuv4mpeg.y4m&quot;) #this assumes there is a valid YUV4MPEG2-header inside.
Expand All @@ -51,7 +58,7 @@ <h4><b>Some simple examples:</b></h4>
</tr>
</table>
<br>
<table width="75%" border="1">
<table border="1">
<tr>
<td>
<pre>RawSource(&quot;d:\src6_625.raw&quot;,720,576,&quot;BGRA&quot;) # really a raw file<br> # if you are unsure about the pixel_type, simply try out all possible values.</pre>
Expand All @@ -60,7 +67,7 @@ <h4><b>Some simple examples:</b></h4>
</table>
<h4><b>Using an index-string:</b></h4>
<p>You can enter the byte positions of the video frames directly.</p>
<table width="75%" border="1">
<table border="1">
<tr>
<td>
<pre>RawSource(&quot;d:\yuv.mov&quot;,720,576,&quot;UYVY&quot;, index=&quot;0:192512 1:1021952 25:21120512 50:42048512 75:62976512&quot;)</pre>
Expand All @@ -84,7 +91,7 @@ <h4><b>Using an index-string:</b></h4>
<var>big_delta</var> is reset to 0 if the resulting position would be behind the
given one (see beyond).</p>
<p>Here are some possible cases:</p>
<table width="75%" border="1">
<table border="1">
<tr valign="top">
<td width="11%">
<pre> 0: 0</pre>
Expand Down Expand Up @@ -162,7 +169,7 @@ <h4><b>Using an index-string:</b></h4>
</table>
<p>The index string is treated as a filename, if there is an &quot;.&quot; inside.
The data is then read from that file, line breaks don't matter.</p>
<h4><b>Finding those byte positions:</b></h4>
<h4>Finding those byte positions:</h4>
<p>With <font color="#0033FF">yuvscan.exe</font> you can try to analyze files
which contain YUV-data with only valid luma and chroma data (~16-240).<br>
The program searches for big uninterrupted blocks without bytes &lt; 16 or &gt;240
Expand All @@ -178,12 +185,15 @@ <h4><b>Finding those byte positions:</b></h4>
10 ... 255-10)<br>
<tt>round_by_bytes</tt>: as most data is stored at nice positions, the output
can be rounded. default 9 which means 2^9 = $100</p>
<p>&nbsp;</p>
<h4>Ernst Pech&eacute;, 2005-10-13</h4>
<h4>Oka Motofumi, 2011-06-14</h4>
<br><br>
<h4>note:</h4>
<p>On Avisynth+ MT, this filter is automatically registerd as MT_SERIALIZED.<br>
You don't have to set it yourself.</p>
<h4>original author:Ernst Pech&eacute;, 2005-10-13</h4>
<h4>modified by Oka Motofumi, 2011-06-14</h4>
<p>
Version 2011-06-14 - First release.<br>
Version 2011-09-25 - Change maximum width into 65536.<br>
Version 2012-08-31 - Expand the size of read buffer to one frame at maximum, and change writing algorithm.<br>
Version 2016-05-29 - Add 64bit binary</p>
</body>
</html>
13 changes: 12 additions & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
RawSource26 - reads raw video data files
Author: Oka Motofumi (chikuzen.mo at gmail dot com)
This program is rewriting of RawSource.dll(original author is Ernst Pech)
for avisynth2.6x/Avisynth+.
*/


#include <cstdio>
#include <cinttypes>
#include "common.h"
Expand Down Expand Up @@ -210,4 +220,5 @@ int generate_index(std::vector<i_struct>& index, std::vector<rindex>& rawindex,
}
}
return frame;
}
}

13 changes: 12 additions & 1 deletion src/write_frame.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
RawSource26 - reads raw video data files
Author: Oka Motofumi (chikuzen.mo at gmail dot com)
This program is rewriting of RawSource.dll(original author is Ernst Pech)
for avisynth2.6x/Avisynth+.
*/


#include <io.h>
#include <fcntl.h>
#include <cstdint>
Expand Down Expand Up @@ -116,4 +126,5 @@ write_black_frame(PVideoFrame& dst, const VideoInfo& vi) noexcept
size = dst->GetPitch(PLANAR_U) * dst->GetHeight(PLANAR_U);
memset(dst->GetWritePtr(PLANAR_U), 0x80, size);
memset(dst->GetWritePtr(PLANAR_V), 0x80, size);
}
}

1 change: 1 addition & 0 deletions vs2015/RawSource.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<ProjectGuid>{971FBA54-37EB-45F9-A116-E97847B7163D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<ProjectName>RawSource26</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down

0 comments on commit 444ed16

Please sign in to comment.